/
Backend implementation

Backend implementation

Database structure

https://excalidraw.com/#json=6583019510956032,3U8twxl8OgyBScD1yXFTXQ

New additions are colored green.

Table

Column

Definition

Table

Column

Definition

Channels

TotalMsgCountRoot

Total number of root messages

ChannelMembers

MsgCountRoot

Number of seen root messages

 

MentionCountRoot

Number of unread mentions in root messages

Threads

PostId

Id of the root post

 

ChannelId

 

 

ReplyCount

Number or reply posts in this thread

 

LastReplyAt

Timestamp of the last reply

 

Participants

json array of all thread member IDs

ThreadMemberships

PostId

Id of the root post

 

UserId

Id of the user

 

Following

Is the thread followed

 

UnreadMentions

Number of unread mentions for this user in the thread

 

LastViewed

Timestamp of when the thread was last viewed

 

LastUpdated

Timestamp of the last change to the thread (follow state, mentions, etc)

 

API

https://api.mattermost.com/#tag/threads

New APIs

Path

Method

Description

Path

Method

Description

api/v4/users/{user_id}/teams/{team_id}/threads



GET

Return threads that the user is following

api/v4/users/{user_id}/teams/{team_id}/threads/read

PUT

Mark all threads as read

api/v4/users/{user_id}/teams/{team_id}/{thread_id}

GET

Get one thread by Id

api/v4/users/{user_id}/teams/{team_id}/{thread_id}/following

PUT

Start following a thread

api/v4/users/{user_id}/teams/{team_id}/{thread_id}/following

DELETE

Stop following a thread

api/v4/users/{user_id}/teams/{team_id}/{thread_id}/read/{timestamp}

PUT

Change ‘read’ state of a thread based on the timestamp

Updated APIs

All ‘get posts’ methods, i.e.:
/api/v4/users/{user_id}/channels/{channel_id}/posts/unread
/api/v4/channels/{channel_id}/posts
/api/v4/posts/{post_id}/thread

 

Will receive additional optional query parameter: collapsedThreads=true
Optionally, extendedCollapsedThreads=true can be provided to enrich participants array

In this mode, the output of these API calls will change, instead of returning all posts, only top-level posts will be returned, and for those posts that have replies (i.e. threads), additional fields will be added to the output:

  • participants - array of user IDs (used to show avatars under the thread info in the channel): [{id:"zxxxx", id:"xcccvbs"}] or if extendedCollapsedThreads is set it will return the full user objects

  • reply_count - amount of replies

  • followed - if current user is following this thread

  • last_reply_at - timestamp of last reply

  • unreadReplies - unread replies in this thread

  • unreadMentions - unread mentions in this thread

Config

ServiceSettings.CollapsedThreads

Defaults to ‘disabled’.
Can also be ‘default_on’ or ‘default_off’ to set thread preference for users.
User can override via user preference: ‘collapsed_threads_settings.collapsed_threads_enabled’

ServiceSettings.ThreadAutoFollow

Defaults to ‘true’.
Controls if the threads are autofollowed when:

  1. Somebody replies to your post

  2. You are mentioned in a thread

  3. When someone replies to a root post you are mentioned in

Websocket events

New events

thread_updated

issued when there is a change in a thread (new post). includes thread details in ‘thread’ field.

thread_follow_changed

issued when a thread ‘followed’ state is changed
includes ‘thread_id’ and ‘state’ fields, ‘state’ is true/false indicating following/unfollowed

thread_read_changed

issued when a thread ‘read’ state is changed
includes ‘thread_id’ and ‘timestamp’ fields, ‘timestamp’ indicates the time to which the thread was reset to.
if ‘thread_id’ is not included - even applies to ALL user threads

Updated events

posted/post_edited/post_deleted

Additional ‘following’ boolean will be added

Related PRs

MM-28249 Auto follow threads by reflog · Pull Request #15878 · mattermost/mattermost
MM-34774 Root post with mention should be auto-followed but hidden from thread results by reflog · Pull Request #17390 · mattermost/mattermost
MM-34609 Mark-as-unread on a post in a thread should cause auto-follow by reflog · Pull Request #17343 · mattermost/mattermost
MM-33746 Add TotalMsgCountRoot and MsgCountRoot columns by reflog · Pull Request #17150 · mattermost/mattermost
MM-33708 - Add MentionCountRoot column to ChannelMembers by reflog · Pull Request #17099 · mattermost/mattermost
https://github.com/mattermost/mattermost-server/pull/17093
https://github.com/mattermost/mattermost-server/pull/17064
https://github.com/mattermost/mattermost-server/pull/16909
https://github.com/mattermost/mattermost-server/pull/16659
https://github.com/mattermost/mattermost-server/pull/16503
MM-30970 Add Basic unreadMentions support for collapsed threads by reflog · Pull Request #16407 · mattermost/mattermost
MM-30558 - Add unreadReplies and unreadMentions to thread membership by reflog · Pull Request #16304 · mattermost/mattermost
MM-29987 Implement new collapsed threads API by reflog · Pull Request #16091 · mattermost/mattermost

 

Related content