diff --git a/mail_private/__init__.py b/mail_private/__init__.py
index cde864ba..aa407583 100644
--- a/mail_private/__init__.py
+++ b/mail_private/__init__.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
+# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
from . import models
diff --git a/mail_private/__manifest__.py b/mail_private/__manifest__.py
index 6c0e4211..a211d612 100644
--- a/mail_private/__manifest__.py
+++ b/mail_private/__manifest__.py
@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*-
+# Copyright 2018 Ruslan Ronzhin
+# Copyright 2018 Kolushov Alexandr
+# Copyright 2019 Artem Rafailov
+# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
{
"name": """Internal Messaging""",
"summary": """Send private messages to specified recipients, regardless of who are in followers list.""",
"category": "Discuss",
"images": ['images/mail_private_image.png'],
- "version": "10.0.1.0.1",
+ "version": "10.0.1.1.0",
"application": False,
"author": "IT-Projects LLC, Pavel Romanchenko",
diff --git a/mail_private/doc/changelog.rst b/mail_private/doc/changelog.rst
index f3b7c081..fdf4adee 100644
--- a/mail_private/doc/changelog.rst
+++ b/mail_private/doc/changelog.rst
@@ -1,3 +1,8 @@
+`1.1.0`
+-------
+
+- **New**: added ability to select channels for private message sending.
+
`1.0.1`
-------
diff --git a/mail_private/full_composer_wizard.xml b/mail_private/full_composer_wizard.xml
index 9f57a207..46daeb59 100644
--- a/mail_private/full_composer_wizard.xml
+++ b/mail_private/full_composer_wizard.xml
@@ -1,4 +1,8 @@
+
+
diff --git a/mail_private/models.py b/mail_private/models.py
index 1f69756d..bfc95620 100644
--- a/mail_private/models.py
+++ b/mail_private/models.py
@@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
+# Copyright 2016 x620
+# Copyright 2016 manawi
+# Copyright 2017 Artyom Losev
+# Copyright 2019 Artem Rafailov
+# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
+
from odoo import models, fields, api
@@ -12,3 +18,50 @@ 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):
+ """ The method was partially copied from Odoo.
+ In the current method, the way of getting channels for a private message is changed.
+ """
+ # have a sudoed copy to manipulate partners (public can go here with
+ # website modules like forum / blog / ...
+
+ # 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'].browse(self._context['channel_ids'])
+
+ # 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..4efe6603 100644
--- a/mail_private/static/src/js/mail_private.js
+++ b/mail_private/static/src/js/mail_private.js
@@ -1,3 +1,9 @@
+/* Copyright 2016 x620
+ Copyright 2016 Ivan Yelizariev
+ Copyright 2016 manawi
+ Copyright 2017 Artyom Losev
+ Copyright 2019 Artem Rafailov
+ License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html). */
odoo.define('mail_private', function (require) {
'use strict';
@@ -33,13 +39,18 @@ Chatter.include({
}).fail(function () {
// todo: display notification
});
- },
+ },
on_open_composer_private_message: function (event) {
var self = this;
this.private = true;
+
+
this.get_recipients_for_internal_message().then(function (data) {
self.recipients_for_internal_message = data;
+ return self.get_channels_for_internal_message();
+ }).then(function (data) {
+ self.channels_for_internal_message = data;
self.open_composer({is_private: true});
});
},
@@ -68,6 +79,15 @@ Chatter.include({
:'Follower'
});
});
+
+ _.each(self.channels_for_internal_message, function (channel) {
+ self.composer.suggested_channels.push({
+ checked: true,
+ channel_id: channel.id,
+ full_name: channel.name,
+ name: ('# ' + channel.name),
+ });
+ });
}
},
@@ -101,13 +121,46 @@ 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({
init: function (parent, dataset, options) {
this._super(parent, dataset, options);
this.events['click .oe_composer_uncheck'] = 'on_uncheck_recipients';
+ this.suggested_channels = [];
},
@@ -115,6 +168,52 @@ MailComposer.include({
this.$('.o_composer_suggested_partners input:checked').each(function() {
$(this).prop('checked', false);
});
+ this.$('.o_composer_suggested_channels input:checked').each(function() {
+ $(this).prop('checked', false);
+ });
+ },
+
+ preprocess_message: function () {
+ var self = this;
+ var def = $.Deferred();
+ this._super().then(function (message) {
+ message = _.extend(message, {
+ subtype: 'mail.mt_comment',
+ message_type: 'comment',
+ content_subtype: 'html',
+ context: self.context,
+ });
+
+ // Subtype
+ if (self.options.is_log) {
+ message.subtype = 'mail.mt_note';
+ }
+
+ // for module mail_private
+ if (self.options.is_private) {
+ message.context.is_private = true;
+ message.context.channel_ids = self.get_checked_channels_ids();
+ message.channel_ids = self.get_checked_channels_ids();
+ }
+
+ // Partner_ids
+ if (!self.options.is_log) {
+ var checked_suggested_partners = self.get_checked_suggested_partners();
+ self.check_suggested_partners(checked_suggested_partners).done(function (partner_ids) {
+ message.partner_ids = (message.partner_ids || []).concat(partner_ids);
+ // update context
+ message.context = _.defaults({}, message.context, {
+ mail_post_autofollow: true,
+ });
+ def.resolve(message);
+ });
+ } else {
+ def.resolve(message);
+ }
+
+ });
+
+ return def;
},
on_open_full_composer: function() {
@@ -177,6 +276,20 @@ MailComposer.include({
return checked_partners;
},
+ get_checked_channels_ids: function () {
+ var self = this;
+ var checked_channels = [];
+ this.$('.o_composer_suggested_channels input:checked').each(function() {
+ var full_name = $(this).data('fullname');
+ checked_channels = checked_channels.concat(_.filter(self.suggested_channels, function(item) {
+ if (full_name === item.full_name) {
+ checked_channels.push(item.channel_id);
+ }
+ }));
+ });
+ return checked_channels;
+ },
+
});
});
diff --git a/mail_private/static/src/xml/mail_private.xml b/mail_private/static/src/xml/mail_private.xml
index 5607c9e9..cebfd85c 100644
--- a/mail_private/static/src/xml/mail_private.xml
+++ b/mail_private/static/src/xml/mail_private.xml
@@ -1,4 +1,10 @@
+
@@ -20,6 +26,16 @@
+
diff --git a/mail_private/template.xml b/mail_private/template.xml
index 4da60c79..4a21f485 100644
--- a/mail_private/template.xml
+++ b/mail_private/template.xml
@@ -1,4 +1,6 @@
+