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-row.js
Keegan George 7a8e018965
UX: reworks channel index (drawer and mobile) (#18892)
- Multiple style improvements
- adds last sent message date to the view

Co-authored-by: chapoi <charlie@discourse.org>
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2022-11-28 18:38:05 +01:00

95 lines
2.3 KiB
JavaScript

import Component from "@ember/component";
import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
import { equal } from "@ember/object/computed";
import { inject as service } from "@ember/service";
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
export default Component.extend({
tagName: "",
router: service(),
chat: service(),
channel: null,
isDirectMessageRow: equal(
"channel.chatable_type",
CHATABLE_TYPES.directMessageChannel
),
options: null,
didInsertElement() {
this._super(...arguments);
if (this.isDirectMessageRow) {
this.channel.chatable.users[0].trackStatus();
}
},
willDestroyElement() {
this._super(...arguments);
if (this.isDirectMessageRow) {
this.channel.chatable.users[0].stopTrackingStatus();
}
},
@discourseComputed(
"channel.id",
"chat.activeChannel.id",
"router.currentRouteName"
)
active(channelId, activeChannelId, currentRouteName) {
return (
currentRouteName?.startsWith("chat.channel") &&
channelId === activeChannelId
);
},
@discourseComputed("active", "channel.{id,muted}", "channel.focused")
rowClassNames(active, channel, focused) {
const classes = ["chat-channel-row", `chat-channel-${channel.id}`];
if (active) {
classes.push("active");
}
if (focused) {
classes.push("focused");
}
if (channel.current_user_membership.muted) {
classes.push("muted");
}
if (this.options?.leaveButton) {
classes.push("can-leave");
}
const channelUnreadCount =
this.currentUser.chat_channel_tracking_state?.[channel.id]?.unread_count;
if (channelUnreadCount > 0) {
classes.push("has-unread");
}
return classes.join(" ");
},
@discourseComputed(
"isDirectMessageRow",
"channel.chatable.users.[]",
"channel.chatable.users.@each.status"
)
showUserStatus(isDirectMessageRow) {
return !!(
isDirectMessageRow &&
this.channel.chatable.users.length === 1 &&
this.channel.chatable.users[0].status
);
},
@discourseComputed("channel.chatable_type")
leaveChatTitle() {
if (this.channel.isDirectMessageChannel) {
return I18n.t("chat.direct_messages.leave");
} else {
return I18n.t("chat.channel_settings.leave_channel");
}
},
});