-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: glimmerify chat-channel-row (#19287)
- Loading branch information
Showing
8 changed files
with
218 additions
and
196 deletions.
There are no files selected for viewing
31 changes: 25 additions & 6 deletions
31
plugins/chat/assets/javascripts/discourse/components/chat-channel-row.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 28 additions & 90 deletions
118
plugins/chat/assets/javascripts/discourse/components/chat-channel-row.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,32 @@ | ||
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) { | ||
import Component from "@glimmer/component"; | ||
import { action } from "@ember/object"; | ||
|
||
export default class ChatChannelRow extends Component { | ||
@service router; | ||
@service chat; | ||
@service currentUser; | ||
@service site; | ||
|
||
@action | ||
startTrackingStatus() { | ||
this.#firstDirectMessageUser?.trackStatus(); | ||
} | ||
|
||
@action | ||
stopTrackingStatus() { | ||
this.#firstDirectMessageUser?.stopTrackingStatus(); | ||
} | ||
|
||
get channelHasUnread() { | ||
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 | ||
this.currentUser.get( | ||
`chat_channel_tracking_state.${this.args.channel?.id}.unread_count` | ||
) > 0 | ||
); | ||
}, | ||
} | ||
|
||
@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"); | ||
} | ||
}, | ||
}); | ||
get #firstDirectMessageUser() { | ||
return this.args.channel?.chatable?.users?.firstObject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.