From e300ea0e1a667c7fd08d1b714a887b209339e623 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 16 Jan 2015 17:01:52 +0200 Subject: [PATCH] hashed url support --- im_notif/im_notif_models.py | 24 ++++++++++++++++-------- im_notif/static/src/js/im_notif.js | 25 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/im_notif/im_notif_models.py b/im_notif/im_notif_models.py index b85a85f..8253d46 100644 --- a/im_notif/im_notif_models.py +++ b/im_notif/im_notif_models.py @@ -67,10 +67,14 @@ class mail_notification(models.Model): return email_pids, im_uids - def _message2im(self, message): - url = 'ODOO_REF#id=%s&model=%s&view_type=form' % ( - message.res_id, - message.model + def _message2im(self, cr, uid, message): + inbox_action = self.pool['ir.model.data'].xmlid_to_res_id(cr, SUPERUSER_ID, 'mail.action_mail_inbox_feeds') + inbox_url = '#action=%s' % inbox_action + url = None + if message.res_id: + url = '#id=%s&model=%s&view_type=form' % ( + message.res_id, + message.model ) author = message.author_id and message.author_id.name_get() author = author and author[0][1] or message.email_from @@ -80,11 +84,15 @@ class mail_notification(models.Model): 'notification': _('System notification'), }.get(message.type, '') + about = message.subject or message.record_name or 'UNDEFINED' + about = '[ABOUT] %s' % about + if url: + about = '%s' % (url, about) im_text = [ - '_____________________', - '_____________________', '%s [FROM] %s' % (message.type, author), - '[ABOUT] %s: %s' % (message.subject or message.record_name or '', url) + about, + '_____________________', + '_____[open_inbox]_____' % inbox_url, ] #im_text = im_text + body.split('\n') return im_text @@ -106,7 +114,7 @@ class mail_notification(models.Model): return True def _do_notify_im(self, cr, uid, im_uids, message, context=None): - im_text = self._message2im(message) + im_text = self._message2im(cr, uid, message) user_from = self.pool['ir.model.data'].xmlid_to_res_id(cr, SUPERUSER_ID, 'im_notif.notif_user') diff --git a/im_notif/static/src/js/im_notif.js b/im_notif/static/src/js/im_notif.js index 523656e..7994ca3 100644 --- a/im_notif/static/src/js/im_notif.js +++ b/im_notif/static/src/js/im_notif.js @@ -9,7 +9,7 @@ openerp.im_chat.Conversation.include({ escape_keep_url: function(str){ //var url_regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi; - var url_regex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?|ODOO_REF#[\w#!:.?+=&%@!\-\/]+)/gi; + var url_regex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?|(]*href="([^"]*)"[^>]*>([^<]*)<\/a>)/gi; var last = 0; var txt = ""; while (true) { @@ -18,11 +18,24 @@ break; txt += _.escape(str.slice(last, result.index)); last = url_regex.lastIndex; - var is_odoo_ref = result[0].match(/^ODOO_REF/) - var url = _.escape(result[0].replace(/^ODOO_REF/, '')); - if (is_odoo_ref) - url += '&rnd='+parseInt(Math.random()*1000); - txt += '' + url + ''; + var href = ''; + var content = ''; + var is_odoo_ref = false; + if (result[8]=='' + content + ''; } txt += _.escape(str.slice(last, str.length)); return txt;