|
|
|
#include "Notification.h"
|
|
|
|
|
|
|
|
#include "json/json.h"
|
|
|
|
#include "json/layout.h"
|
|
|
|
#include "util/format.h"
|
|
|
|
|
|
|
|
#include "model/notification.h"
|
|
|
|
#include "model/status.h"
|
|
|
|
|
|
|
|
#include "view/api/Status.h"
|
|
|
|
#include "view/api/Account.h"
|
|
|
|
|
|
|
|
bool int_to_string_callback( void* field_data, bool is_read, char** res );
|
|
|
|
|
|
|
|
static struct json_enum type_enum[] = {
|
|
|
|
{ "favourite", nt_favorite },
|
|
|
|
{ "follow", nt_follow },
|
|
|
|
{ "favourite", nt_like },
|
|
|
|
{ "mention", nt_unfollow },
|
|
|
|
{ "mention", nt_block },
|
|
|
|
{ "mention", nt_mention },
|
|
|
|
{ "pleroma:emoji_reaction", nt_react },
|
|
|
|
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OBJ_TYPE struct notification
|
|
|
|
static struct json_object_field Notification_Pleroma_layout[] = {
|
|
|
|
JSON_FIELD_FIXED_BOOL( is_muted, false ),
|
|
|
|
JSON_FIELD_FIXED_BOOL( is_seen, false ),
|
|
|
|
JSON_FIELD_END,
|
|
|
|
};
|
|
|
|
static struct json_object_field api_Notification_layout[] = {
|
|
|
|
{
|
|
|
|
.key = "account",
|
|
|
|
.offset = offsetof( OBJ_TYPE, account_id ),
|
|
|
|
.type = &api_Account_type,
|
|
|
|
},
|
|
|
|
JSON_FIELD_DATETIME( created_at, true ),
|
|
|
|
{
|
|
|
|
.key = "id",
|
|
|
|
.offset = offsetof( OBJ_TYPE, id ),
|
|
|
|
.type = &json_field_callback_string,
|
|
|
|
.string_callback = int_to_string_callback
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "pleroma",
|
|
|
|
.offset = 0,
|
|
|
|
.type = &json_field_object_composite,
|
|
|
|
.composite_layout = Notification_Pleroma_layout,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "status",
|
|
|
|
.offset = offsetof( OBJ_TYPE, status_id ),
|
|
|
|
.required = false,
|
|
|
|
.type = &api_Status_from_id_type,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "status",
|
|
|
|
.offset = offsetof( OBJ_TYPE, system_status ),
|
|
|
|
.required = false,
|
|
|
|
.type = &api_Status_type,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "emoji",
|
|
|
|
.offset = offsetof( OBJ_TYPE, react ),
|
|
|
|
.required = false,
|
|
|
|
.type = &json_field_string,
|
|
|
|
},
|
|
|
|
JSON_FIELD_ENUM( type, type_enum, true ),
|
|
|
|
JSON_FIELD_END,
|
|
|
|
};
|
|
|
|
#undef OBJ_TYPE
|
|
|
|
|
|
|
|
void api_Notification_write( struct notification* note, FILE* f, int indent )
|
|
|
|
{
|
|
|
|
struct json_writer jw = {
|
|
|
|
.f = f,
|
|
|
|
.indentation = "\t",
|
|
|
|
.indent = indent,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle notifications requiring a system-generated note as they are not part of Mastodon or Pleroma
|
|
|
|
switch( note->type ) {
|
|
|
|
case nt_unfollow:
|
|
|
|
note->system_status = status_new_system_unfollow( note->ref_account_id );
|
|
|
|
break;
|
|
|
|
case nt_block:
|
|
|
|
note->system_status = status_new_system_block( note->ref_account_id );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
json_write_pretty_object_layout( &jw, api_Notification_layout, note );
|
|
|
|
}
|
|
|
|
|