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/app/assets/javascripts/discourse/controllers/preferences/users.js.es6
Tarek Khalil dc60128355
FIX: Hide ignoring users in preference for users with TL less than a member (#7415)
* FIX: Hide ignoring users in preference for users with TL less than a member
2019-04-23 14:47:37 +01:00

53 lines
1.8 KiB
JavaScript

import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
import { popupAjaxError } from "discourse/lib/ajax-error";
import showModal from "discourse/lib/show-modal";
import User from "discourse/models/user";
export default Ember.Controller.extend(PreferencesTabController, {
saveAttrNames: ["muted_usernames", "ignored_usernames"],
ignoredUsernames: Ember.computed.alias("model.ignored_usernames"),
userIsMemberOrAbove: Ember.computed.gte("model.trust_level", 2),
ignoredEnabled: Ember.computed.or("userIsMemberOrAbove", "model.staff"),
actions: {
ignoredUsernamesChanged(previous, current) {
if (current.length > previous.length) {
const username = current.pop();
if (username) {
User.findByUsername(username).then(user => {
if (user.get("ignored")) {
return;
}
const controller = showModal("ignore-duration", {
model: user
});
controller.setProperties({
onClose: () => {
if (!user.get("ignored")) {
const usernames = this.get("ignoredUsernames")
.split(",")
.removeAt(
this.get("ignoredUsernames").split(",").length - 1
)
.join(",");
this.set("ignoredUsernames", usernames);
}
}
});
});
}
} else {
return this.get("model")
.save(["ignored_usernames"])
.catch(popupAjaxError);
}
},
save() {
this.set("saved", false);
return this.get("model")
.save(this.get("saveAttrNames"))
.then(() => this.set("saved", true))
.catch(popupAjaxError);
}
}
});