[ADD] mail: command /leave
Required some changes for the client_action to correctly remove the left channel from its sidebar, and switch to Inbox.
This commit is contained in:
@@ -628,3 +628,12 @@ class Channel(models.Model):
|
||||
You can insert canned responses in your message by typing <b>:shortcut</b>.<br>""")
|
||||
|
||||
self._send_transient_message(partner, msg)
|
||||
|
||||
def _define_command_leave(self):
|
||||
return {'help': _("Leave this channel")}
|
||||
|
||||
def _execute_command_leave(self, **kwargs):
|
||||
if self.channel_type == 'channel':
|
||||
self.action_unfollow()
|
||||
else:
|
||||
self.channel_pin(self.uuid, False)
|
||||
|
||||
@@ -484,8 +484,18 @@ function on_channel_notification (message) {
|
||||
|
||||
function on_partner_notification (data) {
|
||||
if (data.info === "unsubscribe") {
|
||||
remove_channel(chat_manager.get_channel(data.id));
|
||||
chat_manager.bus.trigger("unsubscribe_from_channel", data.id);
|
||||
var channel = chat_manager.get_channel(data.id);
|
||||
if (channel) {
|
||||
var msg;
|
||||
if (_.contains(['public', 'private'], channel.type)) {
|
||||
msg = _.str.sprintf(_t('You unsubscribed from <b>%s</b>.'), channel.name);
|
||||
} else {
|
||||
msg = _.str.sprintf(_t('You unpinned your conversation with <b>%s</b>.'), channel.name);
|
||||
}
|
||||
remove_channel(channel);
|
||||
chat_manager.bus.trigger("unsubscribe_from_channel", data.id);
|
||||
web_client.do_notify(_("Unsubscribed"), msg);
|
||||
}
|
||||
} else if (data.type === 'toggle_star') {
|
||||
on_toggle_star_notification(data);
|
||||
} else if (data.type === 'mark_as_read') {
|
||||
@@ -863,15 +873,11 @@ var chat_manager = {
|
||||
},
|
||||
|
||||
unsubscribe: function (channel) {
|
||||
var def;
|
||||
if (_.contains(['public', 'private'], channel.type)) {
|
||||
def = ChannelModel.call('action_unfollow', [[channel.id]]);
|
||||
return ChannelModel.call('action_unfollow', [[channel.id]]);
|
||||
} else {
|
||||
def = ChannelModel.call('channel_pin', [channel.uuid, false]);
|
||||
return ChannelModel.call('channel_pin', [channel.uuid, false]);
|
||||
}
|
||||
return def.then(function () {
|
||||
remove_channel(channel);
|
||||
});
|
||||
},
|
||||
close_chat_session: function (channel_id) {
|
||||
var channel = this.get_channel(channel_id);
|
||||
|
||||
@@ -105,7 +105,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
"click .o_mail_partner_unpin": function (event) {
|
||||
event.stopPropagation();
|
||||
var channel_id = $(event.target).data("channel-id");
|
||||
this.unsubscribe_from_channel(chat_manager.get_channel(channel_id));
|
||||
chat_manager.unsubscribe(chat_manager.get_channel(channel_id));
|
||||
},
|
||||
"click .o_snackbar_undo": function (event) {
|
||||
event.preventDefault();
|
||||
@@ -259,7 +259,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
chat_manager.bus.on('anyone_listening', self, function (channel, query) {
|
||||
query.is_displayed = query.is_displayed || (channel.id === self.channel.id && self.thread.is_at_bottom());
|
||||
});
|
||||
chat_manager.bus.on('unsubscribe_from_channel', self, self.render_sidebar);
|
||||
chat_manager.bus.on('unsubscribe_from_channel', self, self.on_channel_unsubscribed);
|
||||
chat_manager.bus.on('update_needaction', self, self.throttled_render_sidebar);
|
||||
chat_manager.bus.on('update_starred', self, self.throttled_render_sidebar);
|
||||
chat_manager.bus.on('update_channel_unread_counter', self, self.throttled_render_sidebar);
|
||||
@@ -469,20 +469,6 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
});
|
||||
});
|
||||
},
|
||||
unsubscribe_from_channel: function (channel) {
|
||||
var self = this;
|
||||
chat_manager
|
||||
.unsubscribe(channel)
|
||||
.then(this.render_sidebar.bind(this))
|
||||
.then(this.set_channel.bind(this, chat_manager.get_channel("channel_inbox")))
|
||||
.then(function () {
|
||||
if (_.contains(['public', 'private'], channel.type)) {
|
||||
var msg = _.str.sprintf(_t('You unsubscribed from <b>%s</b>.'), channel.name);
|
||||
self.do_notify(_t("Unsubscribed"), msg);
|
||||
}
|
||||
delete self.channels_scrolltop[channel.id];
|
||||
});
|
||||
},
|
||||
|
||||
get_thread_rendering_options: function (messages) {
|
||||
// Compute position of the 'New messages' separator, only once when joining
|
||||
@@ -642,6 +628,13 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
this.set_channel(channel);
|
||||
}
|
||||
},
|
||||
on_channel_unsubscribed: function (channel_id) {
|
||||
if (this.channel.id === channel_id) {
|
||||
this.set_channel(chat_manager.get_channel("channel_inbox"));
|
||||
}
|
||||
this.render_sidebar();
|
||||
delete this.channels_scrolltop[channel_id];
|
||||
},
|
||||
on_composer_input_focused: function () {
|
||||
var composer = this.channel.mass_mailing ? this.extended_composer : this.basic_composer;
|
||||
var commands = chat_manager.get_commands(this.channel);
|
||||
@@ -656,7 +649,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
|
||||
},
|
||||
|
||||
on_click_button_unsubscribe: function () {
|
||||
this.unsubscribe_from_channel(this.channel);
|
||||
chat_manager.unsubscribe(this.channel);
|
||||
},
|
||||
on_click_button_settings: function() {
|
||||
this.do_action({
|
||||
|
||||
Reference in New Issue
Block a user