This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-channel-unread-indicator.js
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

47 lines
1.1 KiB
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component";
import { equal, gt } from "@ember/object/computed";
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
export default Component.extend({
tagName: "",
channel: null,
isDirectMessage: equal(
"channel.chatable_type",
CHATABLE_TYPES.directMessageChannel
),
hasUnread: gt("unreadCount", 0),
@discourseComputed(
"currentUser.chat_channel_tracking_state.@each.{unread_count,unread_mentions}",
"channel.id"
)
channelTrackingState(state, channelId) {
return state?.[channelId];
},
@discourseComputed(
"channelTrackingState.unread_mentions",
"channel",
"isDirectMessage"
)
isUrgent(unreadMentions, channel, isDirectMessage) {
if (!channel) {
return;
}
return isDirectMessage || unreadMentions > 0;
},
@discourseComputed("channelTrackingState.unread_count", "channel")
unreadCount(unreadCount, channel) {
if (!channel) {
return;
}
return unreadCount || 0;
},
});