FIX: Don't publish PM archive events to acting user. (#14291)

When a user archives a personal message, they are redirected back to the
inbox and will refresh the list of the topics for the given filter.
Publishing an event to the user results in an incorrect incoming message
because the list of topics has already been refreshed.

This does mean that if a user has two tabs opened, the non-active tab
will not receive the incoming message but at this point we do not think
the technical trade-offs are worth it to support this feature. We
basically have to somehow exclude a client from an incoming message
which is not easy to do.

Follow-up to fc1fd1b416
This commit is contained in:
Alan Guo Xiang Tan
2021-09-10 09:20:50 +08:00
committed by GitHub
parent 2215cc2547
commit bc23dcd30b
12 changed files with 117 additions and 114 deletions
@@ -168,18 +168,12 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({
this._notifyIncoming(message.topic_id);
}
break;
case "archive":
if (
[INBOX_FILTER, ARCHIVE_FILTER].includes(this.filter) &&
["user", "all"].includes(this.inbox)
) {
this._notifyIncoming(message.topic_id);
}
break;
case "group_archive":
if (
[INBOX_FILTER, ARCHIVE_FILTER].includes(this.filter) &&
(!message.payload.acting_user_id ||
message.payload.acting_user_id !== this.currentUser.id) &&
(this.inbox === "all" || this._displayMessageForGroupInbox(message))
) {
this._notifyIncoming(message.topic_id);
@@ -235,16 +235,6 @@ acceptance(
);
};
const publishArchiveToMessageBus = function (opts) {
publishToMessageBus(
`/private-message-topic-tracking-state/user/${opts.userId || 5}`,
{
topic_id: opts.topicId,
message_type: "archive",
}
);
};
const publishGroupArchiveToMessageBus = function (opts) {
publishToMessageBus(
`/private-message-topic-tracking-state/group/${opts.groupIds[0]}`,
@@ -253,6 +243,7 @@ acceptance(
message_type: "group_archive",
payload: {
group_ids: opts.groupIds,
acting_user_id: opts.actingUserId,
},
}
);
@@ -289,42 +280,6 @@ acceptance(
);
};
test("incoming archive message on all and archive filter", async function (assert) {
for (const url of [
"/u/charlie/messages",
"/u/charlie/messages/archive",
"/u/charlie/messages/personal",
"/u/charlie/messages/personal/archive",
]) {
await visit(url);
publishArchiveToMessageBus({ topicId: 1 });
await visit(url); // wait for re-render
assert.ok(
exists(".show-mores"),
`${url} displays the topic incoming info`
);
}
for (const url of [
"/u/charlie/messages/group/awesome_group/archive",
"/u/charlie/messages/group/awesome_group",
]) {
await visit(url);
publishArchiveToMessageBus({ topicId: 1 });
await visit(url); // wait for re-render
assert.ok(
!exists(".show-mores"),
`${url} does not display the topic incoming info`
);
}
});
test("incoming read message on unread filter", async function (assert) {
await visit("/u/charlie/messages/unread");
@@ -335,6 +290,23 @@ acceptance(
assert.ok(exists(".show-mores"), `displays the topic incoming info`);
});
test("incoming group archive message acted by current user", async function (assert) {
await visit("/u/charlie/messages");
publishGroupArchiveToMessageBus({
groupIds: [14],
topicId: 1,
actingUserId: 5,
});
await visit("/u/charlie/messages"); // wait for re-render
assert.ok(
!exists(".show-mores"),
`does not display the topic incoming info`
);
});
test("incoming group archive message on all and archive filter", async function (assert) {
for (const url of [
"/u/charlie/messages",