FIX: When a user status update received other users statuses were getting cleared (#17520)

This commit is contained in:
Andrei Prigorshnev 2022-07-19 21:18:51 +04:00 committed by GitHub
parent 6e2199cd58
commit 7f112ffd4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -1238,7 +1238,9 @@ User.reopen(Evented, {
},
_updateStatus(statuses) {
this.set("status", statuses[this.id]);
if (statuses.hasOwnProperty(this.id)) {
this.set("status", statuses[this.id]);
}
},
});

View File

@ -111,4 +111,39 @@ module("Unit | Model | user", function (hooks) {
assert.ok(spyMomentGuess.notCalled);
});
test("clears statuses of several users correctly when receiving status updates via appEvents", function (assert) {
const status1 = {
description: "user1 status",
emoji: "mega",
};
const status2 = {
description: "user2 status",
emoji: "speech_balloon",
};
const user1 = User.create({
id: 1,
status: status1,
});
const user2 = User.create({ id: 2, status: status2 });
const appEvents = user1.appEvents;
try {
user1.trackStatus();
user2.trackStatus();
assert.equal(user1.status, status1);
assert.equal(user2.status, status2);
appEvents.trigger("user-status:changed", { [user1.id]: null });
assert.equal(user1.status, null);
assert.equal(user2.status, status2);
appEvents.trigger("user-status:changed", { [user2.id]: null });
assert.equal(user1.status, null);
assert.equal(user2.status, null);
} finally {
user1.stopTrackingStatus();
user2.stopTrackingStatus();
}
});
});