-
-
Notifications
You must be signed in to change notification settings - Fork 699
/
fetchmessage.php
47 lines (33 loc) · 1.39 KB
/
fetchmessage.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
<?php
erLhcoreClassRestAPIHandler::setHeaders();
if (!empty($_GET) && $_SERVER['REQUEST_METHOD'] === 'GET') {
$requestPayload = $_GET;
} else {
$requestPayload = json_decode(file_get_contents('php://input'),true);
}
try {
if (!isset($requestPayload['id']) || !isset($requestPayload['msg_id'])) {
throw new Exception('Chat ID or message ID not provided!');
}
$chat = erLhcoreClassModelChat::fetch($requestPayload['id']);
if ($chat instanceof erLhcoreClassModelChat && $chat->hash === $requestPayload['hash'])
{
$msg = erLhcoreClassModelmsg::fetch($requestPayload['msg_id']);
if ($msg instanceof erLhcoreClassModelmsg && $msg->chat_id == $chat->id) {
$tpl = erLhcoreClassTemplate::getInstance( 'lhchat/syncuser.tpl.php');
$tpl->set('messages',array((array)$msg));
$tpl->set('chat',$chat);
$tpl->set('react',true);
$tpl->set('sync_mode','');
$tpl->set('async_call',true);
if (isset($requestPayload['theme']) && ($themeId = erLhcoreClassChat::extractTheme($requestPayload['theme'])) !== false) {
$tpl->set('theme',erLhAbstractModelWidgetTheme::fetch($requestPayload['theme']));
}
echo json_encode(array('id' => $msg->id, 'msg' => trim($tpl->fetch())));
exit;
}
}
} catch ( Exception $e ) {
}
exit;
?>