Overview

Behind the scenes, we use mobx-state-tree (MST) for our data store. You can access data via either direct model access or views and fetch or save data with actions.

Root Store

The root store consists of the following structure:

  • user_repo: Users
  • chat_repo: Chats
  • message_repo: Messages

Actions

There are a few actions that exist on the root store.

NameArgumentsDescription
logininput: LoginInput

Logs the provided user into the chat server. If the user doesn’t yet exist, a new one is created. If the user does exist, the initially provided uid is used for authentication. The uid should be the unique and persisted identifier of the user within your user management solution.

logoutN/A

Logs the current user out of the chat server and resets the store.

loadN/AGets the current user’s details

Views

NameArgumentsDescription
userThe current logged in user
isLoggedInN/AReturns true if you are logged into the chat server

Models

Users

The Users model type is used to store all the chat users.

NameData typeDescription
byId{ [userId: string]: User }A map of all fetched users by id
fetchingbooleanTrue if currently fetching users
currentIUserThe current logged in chat user

User

The User model type defines a single instance of a user.

NameData typeDescription
idstringThe unique user id
usernamestringUser’s username
display_namestring|undefinedUser’s display name
descriptionstring|undefinedUser’s bio and/or details
created_atDateThe date the user was created
updated_atDateThe date the user was last updated
imagestring|undefinedURL or base64 encoded string of the user’s avatar
last_seenDateThe last time a user was active
statusOnlineStatusThe current status of the user

Chats

The Chats model type is used to store all the chats, dms and channels

NameData typeDescription
byId{ [chatId: string]: Chat }A map of all fetched chats by id
fetchingbooleanTrue if currently fetching chats

Chat

The Chat model type is used to define a specific chat, whether dm or channel

NameData typeDescription
idstringThe unique chat id
created_atDateThe date the chat was created
updated_atDateThe date the chat was last updated
membersMember[]A list of members that belong to the chat
kindChatTypeThe type of chat
namestring|undefinedThe name of chat
descriptionstring|undefinedThe description of chat
imagestring|undefinedURL or base64 encoded string of the chat
_privateboolean

True if a private chat. If false, any user can join the channel.

last_messageMessage|undefinedThe last sent message of the chat
joiningboolean|undefinedTrue if current user is in the process of joining the chat
unread_countnumberThe number of unread messages by the user of this chat
users_typingUser[]The users that are currently typing
messagesMessageListList of messages
outgoingMessage[]|undefinedMessages that are currently being sent
invitesUser[]|undefined

Users that have been invited to the channel, but not yet joined

Messages

The Messages model type is used to store all messages

NameData typeDescription
byId{ [chatId: string]: Message }A map of all fetched messages by id
fetchingbooleanTrue if currently fetching messages

Message

The Message model type is used to define a specific message

NameData typeDescription
idstringThe unique message id
created_atDateThe date the message was created
updated_atDateThe date the message was last updated
textstring|undefinedThe textual portion of the message
userUserThe sender
parent_idstring|undefined

The id of the parent message in the event this message is within a thread

chat_idstringId of the chat
repliesMessage[]|undefinedThe array of replies to this message
reply_countnumberNumber of replies
reactionsstring[]|undefinedMessage reactions and the users they belong to
attachmentsAttachment[]|undefinedThe attachments sent with the message
mentionsMention[]|undefinedThe message mentions
statusstring|undefinedsending or sent
favoritebooleanTrue if current user marked as favorite
systemSystemMessageType|undefinedSystem message type