diff --git a/mail_private/models.py b/mail_private/models.py
index 1f69756d..2d16c99f 100644
--- a/mail_private/models.py
+++ b/mail_private/models.py
@@ -12,3 +12,57 @@ def send_mail(self, auto_commit=False):
for w in self:
w.is_log = True if w.is_private else w.is_log
super(MailComposeMessage, self).send_mail(auto_commit=False)
+
+
+class MailMessage(models.Model):
+ _inherit = 'mail.message'
+
+ @api.multi
+ def _notify(self, force_send=False, send_after_commit=True, user_signature=True):
+ self_sudo = self.sudo()
+ if 'is_private' not in self_sudo._context or not self_sudo._context['is_private']:
+ super(MailMessage, self)._notify(force_send, send_after_commit, user_signature)
+ else:
+ self._notify_mail_private(force_send, send_after_commit, user_signature)
+
+
+ @api.multi
+ def _notify_mail_private(self, force_send=False, send_after_commit=True, user_signature=True):
+ """ Add the related record followers to the destination partner_ids if is not a private message.
+ Call mail_notification.notify to manage the email sending
+ """
+ group_user = self.env.ref('base.group_user')
+ # have a sudoed copy to manipulate partners (public can go here with
+ # website modules like forum / blog / ...
+ self_sudo = self.sudo()
+
+ # TDE CHECK: add partners / channels as arguments to be able to notify a message with / without computation ??
+ self.ensure_one() # tde: not sure, just for testinh, will see
+ partners = self.env['res.partner'] | self.partner_ids
+ channels = self.env['mail.channel'].search([('id', '=', self._context['channel_ids'])])
+
+ # remove author from notified partners
+ if not self._context.get('mail_notify_author', False) and self_sudo.author_id:
+ partners = partners - self_sudo.author_id
+
+ # update message, with maybe custom values
+ message_values = {
+ 'channel_ids': [(6, 0, channels.ids)],
+ 'needaction_partner_ids': [(6, 0, partners.ids)]
+ }
+ if self.model and self.res_id and hasattr(self.env[self.model], 'message_get_message_notify_values'):
+ message_values.update(
+ self.env[self.model].browse(self.res_id).message_get_message_notify_values(self, message_values))
+ self.write(message_values)
+
+ # notify partners and channels
+ partners._notify(self, force_send=force_send, send_after_commit=send_after_commit,
+ user_signature=user_signature)
+ channels._notify(self)
+
+ # Discard cache, because child / parent allow reading and therefore
+ # change access rights.
+ if self.parent_id:
+ self.parent_id.invalidate_cache()
+
+ return True
diff --git a/mail_private/static/src/js/mail_private.js b/mail_private/static/src/js/mail_private.js
index d311b3cd..613a095d 100644
--- a/mail_private/static/src/js/mail_private.js
+++ b/mail_private/static/src/js/mail_private.js
@@ -33,14 +33,23 @@ Chatter.include({
}).fail(function () {
// todo: display notification
});
- },
+ },
on_open_composer_private_message: function (event) {
var self = this;
this.private = true;
+ var def = $.Deferred();
+
this.get_recipients_for_internal_message().then(function (data) {
self.recipients_for_internal_message = data;
- self.open_composer({is_private: true});
+ def.resolve();
+ });
+
+ this.get_channels_for_internal_message().then(function (data) {
+ self.channels_for_internal_message = data;
+ def.then(function() {
+ self.open_composer({is_private: true});
+ });
});
},
@@ -68,6 +77,15 @@ Chatter.include({
:'Follower'
});
});
+
+ _.each(self.channels_for_internal_message, function (partner) {
+ self.composer.suggested_channels.push({
+ checked: true,
+ partner_id: partner.id,
+ full_name: partner.name,
+ name: ('# ' + partner.name),
+ });
+ });
}
},
@@ -101,7 +119,39 @@ Chatter.include({
});
});
});
- }
+ },
+
+ get_channels_for_internal_message: function () {
+ var self = this;
+ self.result = {};
+ return new Model(this.context.default_model).query(
+ ['message_follower_ids', 'partner_id']).filter(
+ [['id', '=', self.context.default_res_id]]).all().
+ then(function (thread) {
+ var follower_ids = thread[0].message_follower_ids;
+ self.result[self.context.default_res_id] = [];
+ self.customer = thread[0].partner_id;
+
+ // Fetch partner ids
+ return new Model('mail.followers').call(
+ 'read', [follower_ids, ['channel_id']]).then(function (res_partners) {
+ // Filter result and push to array
+ var res_partners_filtered = _.map(res_partners, function (partner) {
+ if (partner.channel_id[0]) {
+ return partner.channel_id[0];
+ }
+ }).filter(function (partner) {
+ return typeof partner !== 'undefined';
+ });
+
+ return new Model('mail.channel').call(
+ 'read', [res_partners_filtered, ['name', 'id']]
+ ).then(function (recipients) {
+ return recipients;
+ });
+ });
+ });
+ },
});
MailComposer.include({
@@ -176,7 +226,6 @@ MailComposer.include({
});
return checked_partners;
},
-
});
});
diff --git a/mail_private/static/src/xml/mail_private.xml b/mail_private/static/src/xml/mail_private.xml
index 5607c9e9..df5d997d 100644
--- a/mail_private/static/src/xml/mail_private.xml
+++ b/mail_private/static/src/xml/mail_private.xml
@@ -3,7 +3,7 @@
-
+
@@ -20,6 +20,16 @@
+