CoolCMS API

ResponseThreadReadSyncTrait

Synchronizes two read trackers: the `read` flag on a response and the unread messages in the private-message thread the response created (`Response::$messageThreadId`).

It lives on the Api side in one place: every way of marking a response (response detail, the modal on advert edit, the e-mail link) ends in updateColumn('read', 1):

  • response to thread (self::updateColumns()): after a successful read = 1 write the thread is marked read for the receiver of the response (the advert owner), and only when its single unread message is the root one from the response; a thread with newer messages from the other side stays unread,
  • thread to response (self::onMessageThreadRead()): when the advert owner reads the thread, the linked response is marked.

IMPORTANT: only the advert owner (the receiving participant) is ever marked, never whoever triggered the action. A holder of the e-mail key gains nothing extra: the key passes the same receiver check and the thread is not marked for anyone else. A guest or an owner without an account (anonymous advert) is skipped: no receiver with an account means no thread to mark.

IMPORTANT: both sides call MessageThreadManager in the no-notification mode (MessageThreadManager::markReadIfOnlyFirstUnread()), and the thread to response direction writes through the service directly so the hooks do not fire a second time; otherwise the two sides would trigger each other in a loop.

Usage: the module ResponseManager implements MessageThreadReadListener and uses this trait.

Tags
requires

$this->advertManager (find() of an advert with getInsertUserId())

$this->messageThreadManager (Api MessageThreadManager)

Table of Contents

Methods

onMessageThreadRead()  : void
Thread to response: the advert owner read the conversation, so their response is read too.
updateColumns()  : Result
markThreadReadForResponse()  : void
responseReceiverUserId()  : int|null
Returns the user the response was addressed to (the advert owner), or `null` for an anonymous advert.

Methods

onMessageThreadRead()

Thread to response: the advert owner read the conversation, so their response is read too.

public onMessageThreadRead(int $threadId, int $userId) : void
Parameters
$threadId : int
$userId : int

updateColumns()

public updateColumns(int|array<int, int> $entityId, array<string, mixed> $values) : Result
Parameters
$entityId : int|array<int, int>
$values : array<string, mixed>
Return values
Result
On this page

Search results