(data)
| 888 | } |
| 889 | |
| 890 | public async createOrUpdateChatStoreMethod(data): Promise<Chat> { |
| 891 | const { chat, initialMessages } = await createOrUpdateChatApiMethod({ |
| 892 | socketId: (this.store.socket && this.store.socket.id) || null, |
| 893 | ...data, |
| 894 | }); |
| 895 | |
| 896 | if (!chat) { |
| 897 | return null; |
| 898 | } |
| 899 | |
| 900 | if (data.id) { |
| 901 | const newObj = new Chat({ |
| 902 | ...chat, |
| 903 | initialMessages, |
| 904 | team: this.currentTeam, |
| 905 | store: this.store, |
| 906 | }); |
| 907 | |
| 908 | runInAction(() => { |
| 909 | if ( |
| 910 | newObj.chatParticipantIds.includes(this.store.currentUser._id) && |
| 911 | newObj.chatCreatorId === this.store.currentUser._id |
| 912 | ) { |
| 913 | const filteredChats = this.chatsForUser.filter((c) => c.chatId !== data.id); |
| 914 | this.chatsForUser.replace(filteredChats); |
| 915 | this.chatsForUser.push(newObj); |
| 916 | } |
| 917 | }); |
| 918 | |
| 919 | return newObj; |
| 920 | } else { |
| 921 | return new Promise<Chat>((resolve) => { |
| 922 | runInAction(() => { |
| 923 | const obj = this.addChatToLocalCacheStoreMethod(chat, initialMessages); |
| 924 | resolve(obj); |
| 925 | }); |
| 926 | }); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | public addChatToLocalCacheStoreMethod(data, initialMessages): Chat { |
| 931 | const obj = new Chat({ |
no test coverage detected