CoolCMS API

MessageReadState
in package

FinalYes

Per-message "read" state derived without a new table from the participant state (`last_read_datetime` + `unread_count`).

A message is unread for a participant when they are not its author and it is newer than their last_read_datetime (or that is empty). Time has second precision, so a message arriving in the same second as the thread was opened would count as read; therefore a second, exact guard applies: unread_count grows by one per foreign message since the last open, so exactly that many of the newest foreign messages are unread. Both rules are united.

Call before myThreadRead moves last_read_datetime and resets the counter.

Table of Contents

Methods

readMessageIds()  : array<int, true>
Marks the caller's own messages as read by the other party (optional operator feature "message read receipts").
unreadMessageIds()  : array<int, true>

Methods

readMessageIds()

Marks the caller's own messages as read by the other party (optional operator feature "message read receipts").

public static readMessageIds(array<int, Message> $messages, int|null $myParticipantId, array<int, MessageParticipantView> $participants) : array<int, true>

An own message is read when at least one other registered participant has lastReadDatetime

= the message time (the comparison is inclusive: time has second precision, a thread opened in the same second read the message). Nothing is evaluated for foreign and system messages, for a guest (does not read in the system), for a participant without lastReadDatetime (null means not read, or the switch is off and the Api omits the field) or when the own participant is unknown.

Parameters
$messages : array<int, Message>
$myParticipantId : int|null
$participants : array<int, MessageParticipantView>
Return values
array<int, true> —

ids of own messages the other party read

unreadMessageIds()

public static unreadMessageIds(array<int, Message> $messages, int|null $myParticipantId, DateTimeInterface|null $lastReadDatetime, int $unreadCount) : array<int, true>
Parameters
$messages : array<int, Message>

chronological (oldest first)

$myParticipantId : int|null

caller's participant row id; null means own messages are not recognized

$lastReadDatetime : DateTimeInterface|null
$unreadCount : int
Return values
array<int, true> —

ids of unread messages

On this page

Search results