-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmessages.php
50 lines (40 loc) · 1.05 KB
/
messages.php
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
<?php
/**
* Ajax endpoint for getting new chat messages.
*/
$user = elgg_get_logged_in_user_entity();
$time_created = get_input('time_created');
$guid = get_input('guid');
$chat = get_entity($guid);
if (!elgg_instanceof($chat, 'object', 'chat') || !$chat->isMember()) {
echo false;
exit;
}
$options = array(
'type' => 'object',
'subtype' => 'chat_message',
'container_guid' => $guid,
'order_by' => 'e.time_created asc',
);
$pagination = get_input('pagination', false);
if ($pagination) {
// Get old messages
$options['wheres'] = array("time_created < $time_created");
$options['limit'] = 6;
} else {
// Get the newest messages
$options['wheres'] = array("time_created > $time_created");
$options['limit'] = false;
}
$messages = elgg_get_entities($options);
$html = '';
if ($messages) {
elgg_load_library('chat');
foreach ($messages as $message) {
$id = "elgg-object-{$message->getGUID()}";
$item = elgg_view_list_item($message);
$html .= "<li id=\"$id\" class=\"elgg-item\">$item</li>";
}
$chat->resetUnreadMessageCount();
}
echo $html;