mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: correctly sort channels with null last message (#23672)
As per 92839dc722 lastMessage won't be null when a message is deleted. This would cause sorting issues when messages from a direct message channels are deleted as we would try to sort on last message and thought it would exist when actually it would be a null message.
I might rethink this design to not return any last_message in this case soon as checking on ID feels dirty and prone to error, so only fixing the issue for now.
This commit is also using `@cached` to avoid replaying the sort logic on each access.
This commit is contained in:
@@ -2,7 +2,7 @@ import Service, { inject as service } from "@ember/service";
|
||||
import { debounce } from "discourse-common/utils/decorators";
|
||||
import Promise from "rsvp";
|
||||
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { cached, tracked } from "@glimmer/tracking";
|
||||
import { TrackedObject } from "@ember-compat/tracked-built-ins";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
@@ -106,6 +106,7 @@ export default class ChatChannelsManager extends Service {
|
||||
);
|
||||
}
|
||||
|
||||
@cached
|
||||
get publicMessageChannels() {
|
||||
return this.channels
|
||||
.filter(
|
||||
@@ -115,6 +116,7 @@ export default class ChatChannelsManager extends Service {
|
||||
.sort((a, b) => a?.slug?.localeCompare?.(b?.slug));
|
||||
}
|
||||
|
||||
@cached
|
||||
get directMessageChannels() {
|
||||
return this.#sortDirectMessageChannels(
|
||||
this.channels.filter((channel) => {
|
||||
@@ -151,11 +153,11 @@ export default class ChatChannelsManager extends Service {
|
||||
|
||||
#sortDirectMessageChannels(channels) {
|
||||
return channels.sort((a, b) => {
|
||||
if (!a.lastMessage) {
|
||||
if (!a.lastMessage.id) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!b.lastMessage) {
|
||||
if (!b.lastMessage.id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user