mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
DEV: Introduce Chat Notices with publishing method (#22369)
This commit is contained in:

committed by
GitHub

parent
c6cd3af5b5
commit
3171fd1a0a
@ -21,7 +21,7 @@
|
||||
@displayed={{this.includeHeader}}
|
||||
/>
|
||||
|
||||
<ChatRetentionReminder @channel={{@channel}} />
|
||||
<Chat::Notices @channel={{@channel}} />
|
||||
|
||||
<ChatMentionWarnings />
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
<div class="chat-notices">
|
||||
<ChatRetentionReminder @channel={{@channel}} />
|
||||
|
||||
{{#each this.noticesForChannel as |notice|}}
|
||||
<div class="chat-notices__notice">
|
||||
<p class="chat-notices__notice__content">
|
||||
{{notice.textContent}}
|
||||
</p>
|
||||
|
||||
<DButton
|
||||
@icon="times"
|
||||
@class="btn-flat chat-notices__notice__clear"
|
||||
@action={{fn this.clearNotice notice}}
|
||||
/>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
@ -0,0 +1,18 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { action } from "@ember/object";
|
||||
|
||||
export default class ChatNotices extends Component {
|
||||
@service("chat-channel-pane-subscriptions-manager") subscriptionsManager;
|
||||
|
||||
get noticesForChannel() {
|
||||
return this.subscriptionsManager.notices.filter(
|
||||
(notice) => notice.channelId === this.args.channel.id
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
clearNotice(notice) {
|
||||
this.subscriptionsManager.clearNotice(notice);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
|
||||
export default class ChatNotice {
|
||||
static create(args = {}) {
|
||||
return new ChatNotice(args);
|
||||
}
|
||||
|
||||
@tracked channelId;
|
||||
@tracked textContent;
|
||||
|
||||
constructor(args = {}) {
|
||||
this.channelId = args.channel_id;
|
||||
this.textContent = args.text_content;
|
||||
}
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
import { inject as service } from "@ember/service";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
||||
import ChatPaneBaseSubscriptionsManager from "./chat-pane-base-subscriptions-manager";
|
||||
import ChatThreadPreview from "../models/chat-thread-preview";
|
||||
import ChatNotice from "../models/chat-notice";
|
||||
|
||||
export default class ChatChannelPaneSubscriptionsManager extends ChatPaneBaseSubscriptionsManager {
|
||||
@service chat;
|
||||
@service currentUser;
|
||||
|
||||
@tracked notices = new TrackedArray();
|
||||
|
||||
get messageBusChannel() {
|
||||
return `/chat/${this.model.id}`;
|
||||
}
|
||||
@ -18,6 +23,17 @@ export default class ChatChannelPaneSubscriptionsManager extends ChatPaneBaseSub
|
||||
return;
|
||||
}
|
||||
|
||||
handleNotice(data) {
|
||||
this.notices.push(ChatNotice.create(data));
|
||||
}
|
||||
|
||||
clearNotice(notice) {
|
||||
const index = this.notices.indexOf(notice);
|
||||
if (index > -1) {
|
||||
this.notices.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
handleThreadOriginalMessageUpdate(data) {
|
||||
const message = this.messagesManager.findMessage(data.original_message_id);
|
||||
if (message) {
|
||||
|
@ -116,6 +116,9 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
|
||||
case "update_thread_original_message":
|
||||
this.handleThreadOriginalMessageUpdate(busData);
|
||||
break;
|
||||
case "notice":
|
||||
this.handleNotice(busData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,6 +251,10 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
handleNotice() {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
_afterDeleteMessage() {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ export default class ChatThreadPaneSubscriptionsManager extends ChatPaneBaseSubs
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: We don't yet handle notices inside of threads so do nothing.
|
||||
handleNotice() {
|
||||
return;
|
||||
}
|
||||
|
||||
_afterDeleteMessage(targetMsg, data) {
|
||||
if (this.model.currentUserMembership?.lastReadMessageId === targetMsg.id) {
|
||||
this.model.currentUserMembership.lastReadMessageId =
|
||||
|
Reference in New Issue
Block a user