-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi_notification.c
More file actions
68 lines (53 loc) · 2.34 KB
/
api_notification.c
File metadata and controls
68 lines (53 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <string.h>
#include <json-c/json.h>
#include "ythtbbs/notification.h"
#include "api.h"
#include "apilib.h"
int api_notification_list(ONION_FUNC_PROTO_STR)
{
DEFINE_COMMON_SESSION_VARS;
int rc = api_check_session(req, cookie_buf, sizeof(cookie_buf), &cookie, &utmp_idx, &ptr_info);
if (rc != API_RT_SUCCESSFUL)
return api_error(p, req, res, rc);
struct json_object *obj = json_tokener_parse("{\"errcode\": 0, \"notifications\": []}");
struct json_object *noti_array = json_object_object_get(obj, "notifications");
NotifyItemList allNotifyItems = parse_notification(ptr_info->userid);
struct json_object * item = NULL;
struct NotifyItem * currItem;
struct boardmem *b;
for (currItem = (struct NotifyItem *)allNotifyItems; currItem != NULL; currItem = currItem->next) {
item = json_object_new_object();
json_object_object_add(item, "board", json_object_new_string(currItem->board));
json_object_object_add(item, "noti_time", json_object_new_int64(currItem->noti_time));
json_object_object_add(item, "from_userid", json_object_new_string(currItem->from_userid));
json_object_object_add(item, "title", json_object_new_string(currItem->title_utf));
json_object_object_add(item, "type", json_object_new_int(currItem->type));
b = ythtbbs_cache_Board_get_board_by_name(currItem->board);
json_object_object_add(item, "secstr", json_object_new_string(b->header.sec1));
json_object_array_add(noti_array, item);
}
free_notification(allNotifyItems);
api_set_json_header(res);
onion_response_write0(res, json_object_to_json_string(obj));
json_object_put(obj);
return OCS_PROCESSED;
}
int api_notification_del(ONION_FUNC_PROTO_STR)
{
DEFINE_COMMON_SESSION_VARS;
int rc = api_check_session(req, cookie_buf, sizeof(cookie_buf), &cookie, &utmp_idx, &ptr_info);
if (rc != API_RT_SUCCESSFUL)
return api_error(p, req, res, rc);
const char * type = onion_request_get_query(req, "type");
const char * board = onion_request_get_query(req, "board");
const char * aid_str = onion_request_get_query(req, "aid");
if (type == NULL && (board == NULL || aid_str == NULL)) {
return api_error(p, req, res, API_RT_WRONGPARAM);
}
if ((type != NULL) && (strcasecmp(type, "delall") == 0)) {
del_all_notification(ptr_info->userid);
} else {
del_post_notification(ptr_info->userid, board, atoi(aid_str));
}
return api_error(p, req, res, API_RT_SUCCESSFUL);
}