MessageThreadRepository
extends ApiRepository
in package
Front repository that reads through the Api bridge and uses the query cache when the service has it enabled (`cache.config.enabledServices`).
This is the deliberate opposite of ApiRepository: the front end only displays data, so a 5 minute old number is at most cosmetic, whereas the admin reads it into a form that is written back to the DB.
->useCache(false) on the query object overrides the policy for one query; it travels
to the payload as ApiBridge::PARAM_USE_CACHE.
IMPORTANT: null is passed on as null (no opinion), not as true. If this layer
substituted true, it would override QueryCacheContext, and
reads through a front manager inside an admin request (AssetManager, ThemeManager,
UserManager) would still be served from the cache. The true default therefore lives
in the bridge.
Table of Contents
Properties
- $apiEndpoint : string
- Api presenter path (e.g. `api/system/page`); set by each concrete repository.
- $bridge : ApiBridge
Methods
- __construct() : mixed
- countUnread() : array<int|string, mixed>
- Returns the number for the header badge; a dedicated action so the mailbox is not loaded on every page.
- find() : array<string|int, mixed>
- findAll() : array<int|string, mixed>
- "My messages" does not read `:Api:Base:MessageThread:getAll` but the dedicated internal action `:Api:Base:MessageThread:myThreads`, like watchdogs read `Watchdog:myList` ({@see \App\UI\Front\Bazaar\Models\Repositories\Api\WatchdogRepository}).
- findBy() : array<string|int, mixed>
- hideThread() : array<int|string, mixed>
- "Delete for me": the thread disappears from my mailbox and stays for the other party.
- markThreadRead() : array<int|string, mixed>
- replyToThread() : array<int|string, mixed>
- Replies to a thread. The write intentionally does not go through `save()` of a new message as with Response: every message must recompute `message_count`, `last_message_datetime` and the unread counters of other participants. One action is one transaction on the Api side; a `save()` from the front end would leave the derived state broken.
- failSoftRead() : array<string|int, mixed>
- Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
- getApiCallSource() : string
- Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
Properties
$apiEndpoint
Api presenter path (e.g. `api/system/page`); set by each concrete repository.
protected
string
$apiEndpoint
= 'api/base/message-thread'
$bridge read-only
protected
ApiBridge
$bridge
Methods
__construct()
public
__construct(ApiBridge $bridge) : mixed
Parameters
- $bridge : ApiBridge
countUnread()
Returns the number for the header badge; a dedicated action so the mailbox is not loaded on every page.
public
countUnread() : array<int|string, mixed>
Return values
array<int|string, mixed>find()
public
find(int $id[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>findAll()
"My messages" does not read `:Api:Base:MessageThread:getAll` but the dedicated internal action `:Api:Base:MessageThread:myThreads`, like watchdogs read `Watchdog:myList` ({@see \App\UI\Front\Bazaar\Models\Repositories\Api\WatchdogRepository}).
public
findAll([array<int|string, mixed>|null $filters = [] ][, array<string, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<int, string>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<int, string> $includes = [] ][, bool|null $useCache = null ]) : array<int|string, mixed>
The reason is sharper for messages: the thread has no owner column, participation lives in
cms_mod_base_message_participants. getAll would have nothing to filter and the role
registrated would receive foreign conversations. myThreads has no action*() (404
externally) and the server sets the scope from the JWT; the caller's filter can only narrow it.
Mailbox narrowing is sent in filters as flags box (received/sent), unreadOnly,
includeArchived, not as conditions over the participant table.
Parameters
- $filters : array<int|string, mixed>|null = []
- $orderBys : array<string, mixed>|null = null
- $offset : int|null = null
- $limit : int|null = null
- $columns : array<int, string>|null = null
- $computeTotalCount : bool = false
- $includes : string|array<int, string> = []
- $useCache : bool|null = null
Return values
array<int|string, mixed>findBy()
public
findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed>|null = []
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>hideThread()
"Delete for me": the thread disappears from my mailbox and stays for the other party.
public
hideThread(int $threadId) : array<int|string, mixed>
Parameters
- $threadId : int
Return values
array<int|string, mixed>markThreadRead()
public
markThreadRead(int $threadId) : array<int|string, mixed>
Parameters
- $threadId : int
Return values
array<int|string, mixed>replyToThread()
Replies to a thread. The write intentionally does not go through `save()` of a new message as with Response: every message must recompute `message_count`, `last_message_datetime` and the unread counters of other participants. One action is one transaction on the Api side; a `save()` from the front end would leave the derived state broken.
public
replyToThread(int $threadId, string $text) : array<int|string, mixed>
Parameters
- $threadId : int
- $text : string
Return values
array<int|string, mixed>failSoftRead()
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
protected
failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>
NOTE: it does not log on purpose. ApiBridge::call(), which sees both the
endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second
copy would turn one failure into three lines in auth.log.
Parameters
- $response : mixed
- $endpoint : string
-
only for call readability; the log takes the endpoint from the bridge
Return values
array<string|int, mixed>getApiCallSource()
Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
protected
getApiCallSource() : string