MDL-67700 message: prevent async loading conversation message mix
authorFerran Recio <ferran@moodle.com>
Thu, 21 May 2020 13:26:52 +0000 (15:26 +0200)
committerFerran Recio <ferran@moodle.com>
Thu, 21 May 2020 16:02:42 +0000 (18:02 +0200)
message/amd/build/message_drawer_view_conversation.min.js
message/amd/build/message_drawer_view_conversation.min.js.map
message/amd/src/message_drawer_view_conversation.js

index 446a342..53c1f62 100644 (file)
Binary files a/message/amd/build/message_drawer_view_conversation.min.js and b/message/amd/build/message_drawer_view_conversation.min.js differ
index bf01ac7..dac3fc9 100644 (file)
Binary files a/message/amd/build/message_drawer_view_conversation.min.js.map and b/message/amd/build/message_drawer_view_conversation.min.js.map differ
index 31ccbae..03854ff 100644 (file)
@@ -506,6 +506,18 @@ function(
                 newestFirst,
                 timeFrom
             )
+            .then(function(result) {
+                // Prevent older requests from contaminating the current view.
+                if (result.id != viewState.id) {
+                    result.messages = [];
+                    // Purge old conversation cache to prevent messages lose.
+                    if (result.id in stateCache) {
+                        delete stateCache[result.id];
+                    }
+                }
+
+                return result;
+            })
             .then(function(result) {
                 if (result.messages.length && ignoreList.length) {
                     result.messages = result.messages.filter(function(message) {