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
Joffrey JAFFEUX 075af7ba84
REFACTOR: channel retention reminder text (#20310)
- Moves logic into one specialised component
- Adds more tests
- Removes duplicate key
- Uses pluralization
- Handles 0 case properly

Co-authored-by: Gerhard Schlager <mail@gerhard-schlager.at>
2023-02-15 14:50:01 +01:00

40 lines
1.2 KiB
JavaScript

import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
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.isCategoryChannel &&
this.currentUser.needs_channel_retention_reminder))
);
},
@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);
},
});