NotificationType
enum NotificationType
A type of event that can change the value of the global notification handler’s UserNotificationData result.
When certain database-mutating events occur, the notification bookkeeping methods need to be called to keep our cached notification counts up to date. The notification counts themselves are database-denormalizing, but they’re a cache intended to improve the performance of the global notification method.
How notifications are stored in Redis:
- Announcements:
ActiveAnnouncementIDsholds announcement IDs for all active announcements, Its updated frequently to catch expiring announcements. - Mentions: Field
forumMentionin hash-valued keyNotificationHash-\(userID)holds the total number of @mentions for each user. Counts are updated on each post, post edit, and post deletion. - Alertwords: All alertwords by all users are kept in a sorted set keyed by
alertwords. The value for each entry in the set is the number of users watching on that alertword. When someone posts, we get all fields inalertwordswith values > 0. We then intersect the words in the post with the words from alertwords. For any words in the intersection, we get the set-valued keyalertwordusers-\(word)to get the set of users watching on that particular word. We then increment the count of the fieldalertwordPost-\(word)in keyNotificationHash-\(userID). - LFG Posts/Seamails: When a post is created, we increment a field named with the chats’ ID in the
UnreadLFGs-\(userID)orUnreadSeamails-\(userID)key. When a post is deleted, we decrement the same field, only for users that haven’t seen the post (their unseen count is less than how far back the deleted post is). - Next Event Time: Every time an event is followed/unfollowed, we calculate the time of the next event in the followed list, storing that in the
nextFollowedEventTimefield inNotificationHash-\(userID).
How notifications are marked ‘viewed’ in Redis:
- Announcements: Each user stores the # of their highest-read announcement in the
announcementfield of the hash-valued keyNotificationHash-\(userID). The number of announcements with IDs > the highest-read announceemnt are ‘new’ to that user. This means an announceement could appear and then expire unseen by a user, and their unseen count would continue to be correct. - Mentions: The # of mentions the user has viewed are stored in
forumMention_viewedin theNotificationHash-\(userID)key, and set equal to the relevant @mention count when a user’s own mentions are viewed. - Alertwords: Similar to Mentions; the # of alertword hits that have been viewed is stored in
alertwordPost-\(word)_viewed. The difference between this field andalertwordPost-\(word)equals the number of new, unseen alertword hits. The_viewedfield is set equal to the count field upon viewing hits. - Fez Posts: When the fez is viewed (more corectly, the getSingleFez api call is made), we set the # of unseen posts for the fez to 0.
- Next Event Time: Never gets deleted, but can get expired when the current time is > the event time.
-
An app-wide announcement. Associated value is the ID of the announcement.
Declaration
Swift
case announcement(Int) -
Only for ‘open’ seamails. The owner of the chata has added this user.
Declaration
Swift
case addedToChat(UUID, FezType) -
A new message posted to a fez. Associated value is the ID of the fez. (NOT the id of the new message).
Declaration
Swift
case chatUnreadMsg(UUID, FezType) -
An upcoming event that the user has followed.
Declaration
Swift
case nextFollowedEventTime(Date?, UUID?) -
An event the user is following is about to start.
Declaration
Swift
case followedEventStarting(UUID) -
An upcoming LFG that the user has joined.
Declaration
Swift
case nextJoinedLFGTime(Date?, UUID?) -
An LFG the user is joined is about to start.
Declaration
Swift
case joinedLFGStarting(UUID) -
A Personal Event the user has created or was added to is about to start.
Declaration
Swift
case personalEventStarting(UUID) -
An LFG or Private Event the user has joined has been cancelled.
Declaration
Swift
case chatCanceled(UUID, FezType) -
A new forum post that contains a word that a user was alerting on. Associated value is a tuple. First is the alert word that matched. Second is the post ID. Could also happen if an existing post was edited, and the edit adds the alert word to the text. The optional String is the ID of the forum containing the post; it’s sent to socket clients as
secondaryContentID.Declaration
Swift
case alertwordPost(String, Int, _: String? = nil) -
A new or edited forum post that now @mentions a user. Associated value is the post ID. The optional String is the ID of the forum containing the post; it’s sent to socket clients as
secondaryContentID.Declaration
Swift
case forumMention(Int, _: String? = nil) -
A new or edited forum post that now @mentions @moderator. Associated value is the post ID.
Declaration
Swift
case moderatorForumMention(Int, _: String? = nil) -
A new or edited forum post that now @mentions @twitarrteam. Associated value is the post ID.
Declaration
Swift
case twitarrTeamForumMention(Int, _: String? = nil) -
A new or edited forum post that now @mentions @CommunitySupport. Associated value is the post ID. Only sent to Community Support role holders and TwitarrTeam and above–the people who can see the private Community Support forum category.
Declaration
Swift
case communitySupportForumMention(Int, _: String? = nil) -
A Micro Karaoke song the user contributed to is ready for viewing. Associated value is song ID
Declaration
Swift
case microKaraokeSongReady(Int) -
Returns the hash field name used to store info about this notification type in Redis.
Declaration
Swift
func redisFieldName() -> String -
Some notification types store both ‘current counts’ and ‘viewed counts’. Thie builds the Redis field name for the viewed counts.
Declaration
Swift
func redisViewedFieldName() -> String -
Returns the Redis Key used to store info about this notification type in Redis.
Declaration
Swift
func redisKeyName(userID: UUID) -> RedisKey -
The global notificaiton method pulls all the notification data out of this key and builds its data transfer struct from it.
Declaration
Swift
static func redisHashKeyForUser(_ userID: UUID) -> RedisKey -
A shortcut method to get the RedisKey to use to store notification data about a chat.
Declaration
Swift
func objectID() -> String -
Returns the ID of a related object (the forum containing the post, for forum mention types), if known. Sent to socket clients as
secondaryContentID.Declaration
Swift
func secondaryObjectID() -> String? -
Declaration
Swift
static func chatStarting(_ id: UUID, type: FezType) -> NotificationType
View on GitHub