35 : array
36 {
37 $conversations = [];
38
39 $res = $this->db->query(
40 'SELECT * FROM osc_conversation WHERE ' . $this->db->in(
41 'id',
42 $conversationIds,
43 false,
44 'text'
45 )
46 );
47
48 while ($row = $this->db->fetchAssoc(
$res)) {
49 $participants = json_decode($row['participants'], true);
50 $participantIds = array_filter(array_map(function ($value) {
51 if (is_array($value) && isset($value['id'])) {
52 return (int) $value['id'];
53 }
54
55 return 0;
56 }, $participants));
57
58 if (!in_array((
int) $this->
user->getId(), $participantIds)) {
59 continue;
60 }
61
62 $conversation = new ConversationDto($row['id']);
63 $conversation->setIsGroup((bool) $row['osc_']);
64 $conversation->setSubscriberUsrIds($participantIds);
65
66 $this->db->setLimit(1, 0);
68 SELECT osc_messages.*
69 FROM osc_messages
70 WHERE osc_messages.conversation_id = %s
71 AND {$this->db->in(
72 'osc_messages.user_id',
73 $participantIds,
74 false,
75 'text'
76 )}
77 ORDER BY osc_messages.timestamp DESC
78 ";
79 $msgRes = $this->db->queryF(
$query, [
'text'], [$conversation->getId()]);
80
81
82 $message =
new MessageDto(
'', $conversation);
85 $message->setCreatedTimestamp((
int) time() * 1000);
86 $conversation->setLastMessage(
$message);
87
88 while ($msgRow = $this->db->fetchAssoc($msgRes)) {
89 $message =
new MessageDto($msgRow[
'id'], $conversation);
90 $message->setMessage($msgRow[
'message']);
91 $message->setAuthorUsrId((
int) $msgRow[
'user_id']);
92 $message->setCreatedTimestamp((
int) $msgRow[
'timestamp']);
93 $conversation->setLastMessage(
$message);
94 break;
95 }
96
97 $conversations[] = $conversation;
98 }
99
100 return $conversations;
101 }
foreach($_POST as $key=> $value) $res