-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetLastMessage.php
102 lines (51 loc) · 2.05 KB
/
getLastMessage.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
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Apache License 2.0
* @author Trapenok Victor, [email protected], 89244269357
* I will be glad to new orders for the development of anything.
*
* Skype:Levhav
* 89244269357
*
* https://github.com/Levhav/Star.Comet-Chat
*/
include './config.php';
include './common.php';
$user_id_from = getUserIdOrDie();
$user_id_to = (int)$_POST['user_id_to'];
if(isset($_POST['page']))
{
$page = (int)$_POST['page'];
}
else
{
$page = 0;
}
$messages = array();
/**
* Если не false то это первое сообщение в диалоге и переменная хранит информацию о пользователе
*/
$NewContactInfo = false;
$result = mysqli_query(StarCometChat::conf()->getDB(), "SELECT id, from_user_id, to_user_id, read_time, time*1000 as time, message FROM `messages` where (from_user_id = ".$user_id_from." and to_user_id = ".$user_id_to.") or (to_user_id = ".$user_id_from." and from_user_id = ".$user_id_to.") order by time desc limit ".($page*StarCometChat::conf()->page_size).", ".StarCometChat::conf()->page_size);
if(mysqli_errno(StarCometChat::conf()->getDB()) != 0)
{
echo "Error code:".mysqli_errno(StarCometChat::conf()->getDB())." ".mysqli_error(StarCometChat::conf()->getDB())."";
}
else if(mysqli_num_rows($result))
{
while($row = mysqli_fetch_assoc($result))
{
$messages[] = $row;
}
markAsReadMessageArray($user_id_to, $user_id_from);
}
else
{
// Человек ещё не в списке контактов так как в базе нет не одного сообщения
$NewContactInfo = @getUsersInfo($user_id_to)[0];
}
// Получение статусов пользователей с комет сервера
$result = mysqli_query(StarCometChat::conf()->getComet(), "SELECT time FROM users_time WHERE id = ".$user_id_to."");
$row = mysqli_fetch_assoc($result);
echo json_encode(array("success"=>true, "history" => $messages, "last_online_time" => $row['time'], "new_contact" => $NewContactInfo));