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-retention-reminder.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

60 lines
1.8 KiB
JavaScript

import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
import { action } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Component.extend({
tagName: "",
loading: false,
@discourseComputed(
"chatChannel.chatable_type",
"currentUser.{needs_dm_retention_reminder,needs_channel_retention_reminder}"
)
show() {
return (
!this.chatChannel.isDraft &&
((this.chatChannel.isDirectMessageChannel &&
this.currentUser.needs_dm_retention_reminder) ||
(!this.chatChannel.isDirectMessageChannel &&
this.currentUser.needs_channel_retention_reminder))
);
},
@discourseComputed("chatChannel.chatable_type")
text() {
let days = this.siteSettings.chat_channel_retention_days;
let translationKey = "chat.retention_reminders.public";
if (this.chatChannel.isDirectMessageChannel) {
days = this.siteSettings.chat_dm_retention_days;
translationKey = "chat.retention_reminders.dm";
}
return I18n.t(translationKey, { days });
},
@discourseComputed("chatChannel.chatable_type")
daysCount() {
return this.chatChannel.isDirectMessageChannel
? this.siteSettings.chat_dm_retention_days
: this.siteSettings.chat_channel_retention_days;
},
@action
dismiss() {
return ajax("/chat/dismiss-retention-reminder", {
method: "POST",
data: { chatable_type: this.chatChannel.chatable_type },
})
.then(() => {
const field = this.chatChannel.isDirectMessageChannel
? "needs_dm_retention_reminder"
: "needs_channel_retention_reminder";
this.currentUser.set(field, false);
})
.catch(popupAjaxError);
},
});