47 : array
48 {
49 $conversations = [];
50
51 $res = $this->db->query(
52 'SELECT * FROM osc_conversation WHERE ' . $this->db->in(
53 'id',
54 $conversationIds,
55 false,
56 'text'
57 )
58 );
59
60 while ($row = $this->db->fetchAssoc(
$res)) {
61 $participants = json_decode($row['participants'], true, 512, JSON_THROW_ON_ERROR);
62 $participantIds = array_filter(array_map(
static function (
$user):
int {
64 return (
int)
$user[
'id'];
65 }
66
67 return 0;
68 }, $participants));
69
70 if (!in_array($this->
user->getId(), $participantIds,
true)) {
71 continue;
72 }
73
74 $conversation = new ConversationDto($row['id']);
75 $conversation->setIsGroup((bool) $row['is_group']);
76 $conversation->setSubscriberUsrIds($participantIds);
77
78 $inParticipants = $this->db->in(
79 'osc_messages.user_id',
80 $participantIds,
81 false,
82 'text'
83 );
84
85 $this->db->setLimit(1, 0);
87 SELECT osc_messages.*
88 FROM osc_messages
89 WHERE osc_messages.conversation_id = %s
90 AND $inParticipants
91 ORDER BY osc_messages.timestamp DESC
92 ";
93 $msgRes = $this->db->queryF(
$query, [
'text'], [$conversation->getId()]);
94 while ($msgRow = $this->db->fetchAssoc($msgRes)) {
95 $message =
new MessageDto($msgRow[
'id'], $conversation);
96 $message->setMessage($msgRow[
'message']);
97 $message->setAuthorUsrId((
int) $msgRow[
'user_id']);
98 $message->setCreatedTimestamp((
int) $msgRow[
'timestamp']);
99 $conversation->setLastMessage(
$message);
100 break;
101 }
102
103 $conversations[] = $conversation;
104 }
105
106 return $conversations;
107 }