Notifications.php
2.15 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: Notifications.php 25828 2011-11-23 10:50:40Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class Cloud_Service_Server_Notifications extends Cloud_Service_Server_Restful {
protected static $_instance;
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
public function onNotificationsSend($uId, $recipientIds, $appId, $notification) {
$this->getUserSpace($uId);
$result = array();
foreach($recipientIds as $recipientId) {
$val = intval($recipientId);
if($val) {
if ($uId) {
$result[$val] = notification_add($val, $appId, $notification) === null;
} else {
$result[$val] = notification_add($val, $appId, $notification, array(), 1) === null;
}
} else {
$result[$recipientId] = null;
}
}
return $result;
}
public function onNotificationsGet($uId) {
$notify = $result = array();
$result = array(
'message' => array(
'unread' => 0,
'mostRecent' => 0
),
'notification' => array(
'unread' => 0 ,
'mostRecent' => 0
),
'friendRequest' => array(
'uIds' => array()
)
);
$i = 0;
foreach(C::t('home_notification')->fetch_all_by_uid($uId, 1) as $value) {
$i++;
if(!$result['notification']['mostRecent']) $result['notification']['mostRecent'] = $value['dateline'];
}
$result['notification']['unread'] = $i;
loaducenter();
$pmarr = uc_pm_list($uId, 1, 1, 'newbox', 'newpm');
if($pmarr['count']) {
$result['message']['unread'] = $pmarr['count'];
$result['message']['mostRecent'] = $pmarr['data'][0]['dateline'];
}
$fIds = array();
foreach(C::t('home_friend_request')->fetch_all_by_uid($uId) as $value) {
if(!$result['friendRequest']['mostRecent']) {
$result['friendRequest']['mostRecent'] = $value['dateline'];
}
$fIds[] = $value['uid'];
}
$result['friendRequest']['uIds'] = $fIds;
return $result;
}
}