PrivilegedMailbox
struct PrivilegedMailbox : Sendable
Describes one privileged shared mailbox: a non-loginable phantom User (see PrivilegedUser) that
stands in for “every real user who satisfies requirement”. A chat addressed to, or containing, the
phantom account is really addressed to every member of that roster, each of whom gets their own
Redis unread count under inbox (see MailInbox).
PrivilegedMailbox.all is the single source of truth for every “@moderator”/“@TwitarrTeam”-shaped
mailbox’s notification bookkeeping: the chat-unread fan-out, the ?foruser= access checks, and
the nightly consistency job all key off this table, so adding a new mailbox (see issue #517) means
appending a row here, adding a MailInbox case, and seeding its phantom account.
It does NOT cover authoring or UI: FezController.createChat‘s createdByModerator/
createdByTwitarrTeam fields, PostContentData.effectiveAuthor, SiteSeamailController’s
postAsModerator/postAsTwitarrTeam fields, and ForumController.processForumMentions still
hardcode the moderator/TwitarrTeam pair and need their own updates for a new mailbox to be usable
end-to-end.
-
Declaration
Swift
let user: PrivilegedUser -
Declaration
Swift
let inbox: MailInbox -
Declaration
Swift
let requirement: PrivilegedMailboxRequirement -
The
Abort(.forbidden)reason when a user withoutrequirementasks for this mailbox by name (e.g.?foruser=).Declaration
Swift
let accessDeniedReason: String -
Order matters: a chat that somehow contains more than one phantom account resolves to the first matching mailbox here (see
forChat). This preserves existing behavior, where TwitarrTeam has always taken precedence over moderator.Declaration
Swift
static let all: [PrivilegedMailbox] -
The cached phantom account for this mailbox, or nil if the seed migration that creates it hasn’t run on this instance.
Declaration
Swift
func phantomUser(on req: Request) -> UserCacheData? -
All real users who may read this mailbox.
Declaration
Swift
func members(on req: Request) -> [UserCacheData] -
Whether
usermay read this mailbox.Declaration
Swift
func isSatisfied(by user: UserCacheData) -> Bool -
Whether a user with the given accessLevel/roles may read this mailbox. Callers that don’t have a
UserCacheData(e.g.ConsistencyJobs, which works fromUsermodels) should use this instead of reaching intorequirementdirectly.Declaration
Swift
func isSatisfied(accessLevel: UserAccessLevel, roles: Set<UserRoleType>) -> Bool -
Case-insensitive match against a
?foruser=-style query param, e.g. “moderator”/“twitarrteam”. Returns nil both for an unrecognized name and for aPrivilegedUserthat isn’t a mailbox (e.g. “admin”/“tho”, which are service accounts, not shared mailboxes).Declaration
Swift
static func matching(queryParam: String) -> PrivilegedMailbox? -
The first mailbox (in
all‘s order) whose phantom account is a member of the given chat participant list, or nil if none of the phantom accounts are present. PasssatisfiedByto additionally require that user to hold that mailbox’s access requirement–used when resolving which persona a caller may view a fez’s members-only data as; omit it to resolve the fez’s own privileged inbox regardless of who’s asking.Declaration
Swift
static func forChat(participantArray: [UUID], satisfiedBy user: UserCacheData? = nil, on req: Request) -> PrivilegedMailbox?
View on GitHub