diff --git a/addon/content/reducer/reducerConversation.js b/addon/content/reducer/reducerConversation.js index 91724d243..eeb33daa5 100644 --- a/addon/content/reducer/reducerConversation.js +++ b/addon/content/reducer/reducerConversation.js @@ -33,9 +33,9 @@ let messageEnricher = () => { return (_messageEnricher = new MessageEnricher()); }; -function removeListeners() { +async function removeListeners() { if (currentQueryListener) { - browser.convGloda.queryConversationMessages.removeListener( + await browser.convGloda.queryConversationMessages.removeListener( currentQueryListener, currentQueryListenerArgs ); @@ -77,7 +77,7 @@ export const conversationActions = { return async (dispatch, getState) => { let loadingStartedTime = Date.now(); - removeListeners(); + await removeListeners(); let currentId = getState().conversation.currentId + 1; await dispatch(conversationActions.setConversationId({ currentId })); @@ -98,6 +98,12 @@ export const conversationActions = { ); currentQueryListener = (event) => { + if (event.conversationId != currentId) { + console.warn( + "Conversation Query Listener called after being removed" + ); + return; + } if (event.initial) { dispatch( conversationActions.displayConversationMsgs({ @@ -130,7 +136,8 @@ export const conversationActions = { browser.convGloda.queryConversationMessages.addListener( currentQueryListener, - currentQueryListenerArgs + currentQueryListenerArgs, + currentId ); }; }, diff --git a/addon/experiment-api/glodaApi.js b/addon/experiment-api/glodaApi.js index c8cabf887..0ed71371c 100644 --- a/addon/experiment-api/glodaApi.js +++ b/addon/experiment-api/glodaApi.js @@ -28,8 +28,8 @@ var convGloda = class extends ExtensionCommon.ExtensionAPI { queryConversationMessages: new ExtensionCommon.EventManager({ context, name: "convContacts.queryConversationMessages", - register(fire, msgIds) { - let status = { stopQuery: false }; + register(fire, msgIds, conversationId) { + let status = { stopQuery: false, conversationId }; let msgHdrs = msgIds.map((id) => context.extension.messageManager.get(id) @@ -109,10 +109,11 @@ function getGlodaMessages(msgHdrs) { * */ class GlodaListener { - constructor(msgHdrs, intermediateResults, fire, context) { + constructor({ msgHdrs, intermediateResults, status, fire, context }) { this.initialQueryComplete = false; this.msgHdrs = msgHdrs; this.intermediateResults = intermediateResults; + this.status = status; this.fire = fire; this.context = context; } @@ -132,7 +133,10 @@ class GlodaListener { } } if (messages.length) { - this.fire.async({ added: messages }); + this.fire.async({ + added: messages, + conversationId: this.status.conversationId, + }); } } onItemsModified(items) { @@ -148,7 +152,10 @@ class GlodaListener { } } if (messages.length) { - this.fire.async({ modified: messages }); + this.fire.async({ + modified: messages, + conversationId: this.status.conversationId, + }); } } onItemsRemoved(items) { @@ -168,7 +175,10 @@ class GlodaListener { msgIds.push(message.id); } } - this.fire.async({ removed: msgIds }); + this.fire.async({ + removed: msgIds, + conversationId: this.status.conversationId, + }); } onQueryCompleted(collection) { if (this.initialQueryComplete) { @@ -216,7 +226,10 @@ class GlodaListener { // since we would still need to load the headers to inject into the gloda // query and for the basic details. - this.fire.async({ initial: messages }); + this.fire.async({ + initial: messages, + conversationId: this.status.conversationId, + }); } /** @@ -301,12 +314,13 @@ function getAndObserveConversationThread( fire, context ) { - let glodaListener = new GlodaListener( + let glodaListener = new GlodaListener({ msgHdrs, intermediateResults, + status, fire, - context - ); + context, + }); let query = intermediateResults[0].conversation.getMessagesCollection( glodaListener, diff --git a/addon/experiment-api/glodaSchema.json b/addon/experiment-api/glodaSchema.json index 64cf8e746..f3f179b4b 100644 --- a/addon/experiment-api/glodaSchema.json +++ b/addon/experiment-api/glodaSchema.json @@ -21,6 +21,11 @@ "items": { "type": "number" } + }, + { + "name": "conversationId", + "type": "number", + "description": "The conversation id for the query." } ] }