Store
State management.
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
: Userschat_repo
: Chatsmessage_repo
: Messages
Actions
There are a few actions that exist on the root store.
Name | Arguments | Description |
---|---|---|
login | input: 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 |
logout | N/A | Logs the current user out of the chat server and resets the store. |
load | N/A | Gets the current user’s details |
Views
Name | Arguments | Description |
---|---|---|
user | The current logged in user | |
isLoggedIn | N/A | Returns true if you are logged into the chat server |
Models
Users
The Users model type is used to store all the chat users.
Name | Data type | Description |
---|---|---|
byId | { [userId: string]: User } | A map of all fetched users by id |
fetching | boolean | True if currently fetching users |
current | IUser | The current logged in chat user |
User
The User model type defines a single instance of a user.
Name | Data type | Description |
---|---|---|
id | string | The unique user id |
username | string | User’s username |
display_name | string|undefined | User’s display name |
description | string|undefined | User’s bio and/or details |
created_at | Date | The date the user was created |
updated_at | Date | The date the user was last updated |
image | string|undefined | URL or base64 encoded string of the user’s avatar |
last_seen | Date | The last time a user was active |
status | OnlineStatus | The current status of the user |
Chats
The Chats model type is used to store all the chats, dms and channels
Name | Data type | Description |
---|---|---|
byId | { [chatId: string]: Chat } | A map of all fetched chats by id |
fetching | boolean | True if currently fetching chats |
Chat
The Chat model type is used to define a specific chat, whether dm or channel
Name | Data type | Description |
---|---|---|
id | string | The unique chat id |
created_at | Date | The date the chat was created |
updated_at | Date | The date the chat was last updated |
members | Member[] | A list of members that belong to the chat |
kind | ChatType | The type of chat |
name | string|undefined | The name of chat |
description | string|undefined | The description of chat |
image | string|undefined | URL or base64 encoded string of the chat |
_private | boolean | True if a private chat. If false, any user can join the channel. |
last_message | Message|undefined | The last sent message of the chat |
joining | boolean|undefined | True if current user is in the process of joining the chat |
unread_count | number | The number of unread messages by the user of this chat |
users_typing | User[] | The users that are currently typing |
messages | MessageList | List of messages |
outgoing | Message[]|undefined | Messages that are currently being sent |
invites | User[]|undefined | Users that have been invited to the channel, but not yet joined |
Messages
The Messages model type is used to store all messages
Name | Data type | Description |
---|---|---|
byId | { [chatId: string]: Message } | A map of all fetched messages by id |
fetching | boolean | True if currently fetching messages |
Message
The Message model type is used to define a specific message
Name | Data type | Description |
---|---|---|
id | string | The unique message id |
created_at | Date | The date the message was created |
updated_at | Date | The date the message was last updated |
text | string|undefined | The textual portion of the message |
user | User | The sender |
parent_id | string|undefined | The id of the parent message in the event this message is within a thread |
chat_id | string | Id of the chat |
replies | Message[]|undefined | The array of replies to this message |
reply_count | number | Number of replies |
reactions | string[]|undefined | Message reactions and the users they belong to |
attachments | Attachment[]|undefined | The attachments sent with the message |
mentions | Mention[]|undefined | The message mentions |
status | string|undefined | sending or sent |
favorite | boolean | True if current user marked as favorite |
system | SystemMessageType|undefined | System message type |
Was this page helpful?