Chats Store
This store is responsible for holding all the data and logic surrounding chats and messages, but it also helps the chats store initializing when a user is logged in:
/*** src/stores/chats.js ***/
import { observable, computed, map, toJS, action } from 'mobx';
import { AsyncStorage } from 'react-native'
import { firebaseApp } from '../firebase'
import notifications from '../notifications'
class Chats {
@observable list;
@observable selectedChatMessages;
@observable downloadingChats = false;
@observable downloadingChat = false;
@action addMessages = function(chatId, contactId, messages) {
//add a list of messages to a chat
}
@action selectChat = function(id) {
//set a chat as selected and retrieve all the messages for it
}
@action add(user1, user2) {
//add a new chat to the list of chats for the users in it
}
bindToFirebase(userId) {
//listen for the list of chats in Firebase to update the
@observable list
}
}
const chats = new...