[IMP] mail: notifies users when someone join/leave a channel

This commit is contained in:
Géry Debongnie
2015-10-22 14:43:13 +02:00
parent 81b7a32a4d
commit 586928356b
2 changed files with 9 additions and 6 deletions
+9 -3
View File
@@ -145,7 +145,11 @@ class Channel(models.Model):
@api.multi
def action_unfollow(self):
return self.write({'channel_partner_ids': [(3, self.env.user.partner_id.id)]})
result = self.write({'channel_partner_ids': [(3, self.env.user.partner_id.id)]})
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), self.channel_info()[0])
notification = _('<div class="o_mail_notification">left <a href="#" data-channel-id="%s">#%s</a></div>') % (self.uuid, self.name,)
self.message_post(body=notification, message_type="comment", subtype="mail.mt_comment")
return result
@api.multi
@@ -481,8 +485,8 @@ class Channel(models.Model):
@api.multi
def channel_join_and_get_info(self):
self.ensure_one()
notification = {"type": "user_join", "payload": {"channel_id": self.id, "name": self.env.user.partner_id.name}}
self.env['bus.bus'].sendmany([[(self._cr.dbname, 'mail.channel', self.id), notification]])
notification = _('<div class="o_mail_notification">joined <a href="#" data-channel-id="%s">#%s</a></div>') % (self.uuid, self.name,)
self.message_post(body=notification, message_type="notification", subtype="mail.mt_comment")
self.action_follow()
channel_info = self.channel_info()[0]
@@ -505,5 +509,7 @@ class Channel(models.Model):
'channel_partner_ids': [(4, self.env.user.partner_id.id)]
})
channel_info = new_channel.channel_info()[0]
notification = _('<div class="o_mail_notification">created <a href="#" data-channel-id="%s">#%s</a></div>') % (new_channel.uuid, new_channel.name,)
new_channel.message_post(body=notification, message_type="notification", subtype="mail.mt_comment")
self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), channel_info)
return channel_info
@@ -457,9 +457,6 @@ function init () {
if (model === 'mail.channel') {
// new message in a channel
var message = notification[1];
if (message.type === 'user_join') {
return; // to be implemented later
}
var channel_id = message.channel_ids[0];
// fetch the channel info if not done already
var channel = _.findWhere(channels, {id: channel_id});