FIX: Move thread storage out of chatApi.thread() call (#21773)

In some cases activeChannel can be null so this will error,
also it is limiting to have this code in chatApi. Instead
move to the threads manager, and also lean on channelsManager.find
to get the channel from the cache instead, which will not error.
This commit is contained in:
Martin Brennan
2023-05-27 09:43:29 +02:00
committed by GitHub
parent d1f785e7de
commit e4d628a931
2 changed files with 7 additions and 8 deletions
@@ -16,6 +16,7 @@ import { TrackedObject } from "@ember-compat/tracked-built-ins";
export default class ChatThreadsManager {
@service chatSubscriptionsManager;
@service chatTrackingStateManager;
@service chatChannelsManager;
@service chatApi;
@service chat;
@service currentUser;
@@ -83,7 +84,11 @@ export default class ChatThreadsManager {
}
async #find(channelId, threadId) {
return this.chatApi.thread(channelId, threadId);
return this.chatApi.thread(channelId, threadId).then((result) => {
return this.chatChannelsManager.find(channelId).then((channel) => {
return channel.threadsManager.store(channel, result.thread);
});
});
}
#cache(thread) {
@@ -62,13 +62,7 @@ export default class ChatApi extends Service {
* this.chatApi.thread(5, 1).then(thread => { ... })
*/
thread(channelId, threadId) {
return this.#getRequest(`/channels/${channelId}/threads/${threadId}`).then(
(result) =>
this.chat.activeChannel.threadsManager.store(
this.chat.activeChannel,
result.thread
)
);
return this.#getRequest(`/channels/${channelId}/threads/${threadId}`);
}
/**