wip
bzr revid: nicolas.vanhoren@openerp.com-20130902122311-gopkikbta9dg7cne
This commit is contained in:
parent
9a8fe95a5c
commit
9071d01a28
|
@ -203,14 +203,14 @@ class im_session(osv.osv):
|
|||
session_id = None
|
||||
if user_to:
|
||||
# FP Note: does the ORM allows something better than this? == on many2many
|
||||
sids = self.search(cr, uid, [('user_ids', 'in', [user_to]), ('user_ids', 'in', [my_id])], context=context, limit=1)
|
||||
sids = self.search(cr, openerp.SUPERUSER_ID, [('user_ids', 'in', [user_to]), ('user_ids', 'in', [my_id])], context=context, limit=1)
|
||||
for session in self.browse(cr, uid, sids, context=context):
|
||||
if len(session.user_ids) == 2:
|
||||
session_id = session.id
|
||||
break
|
||||
if not session_id:
|
||||
session_id = self.create(cr, uid, {
|
||||
'user_ids': [(6, 0, (user_to, uid))]
|
||||
session_id = self.create(cr, openerp.SUPERUSER_ID, {
|
||||
'user_ids': [(6, 0, [user_to, my_id])]
|
||||
}, context=context)
|
||||
return self.read(cr, uid, session_id, context=context)
|
||||
|
||||
|
|
|
@ -22,16 +22,5 @@
|
|||
<field name="perm_create" eval="1"/>
|
||||
<field name="perm_unlink" eval="1"/>
|
||||
</record>
|
||||
|
||||
<record id="sessions_rule_1" model="ir.rule">
|
||||
<field name="name">Can modify sessions if you are in it.</field>
|
||||
<field name="model_id" ref="model_im_session"/>
|
||||
<field name="groups" eval="[(6,0,[ref('base.group_user')])]"/>
|
||||
<field name="domain_force">[('user_ids', 'in', [user.id])]</field>
|
||||
<field name="perm_read" eval="0"/>
|
||||
<field name="perm_write" eval="1"/>
|
||||
<field name="perm_create" eval="0"/>
|
||||
<field name="perm_unlink" eval="0"/>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_im_message,im.message,model_im_message,base.group_user,1,0,1,0
|
||||
access_im_user,im.user,model_im_user,,1,1,1,0
|
||||
access_im_session,im.session,model_im_session,base.group_user,1,1,1,0
|
||||
access_im_session,im.session,model_im_session,,1,0,0,0
|
|
|
@ -75,7 +75,7 @@ class LiveChatController(http.Controller):
|
|||
def available(self, db, channel):
|
||||
reg, uid = self._auth(db)
|
||||
with reg.cursor() as cr:
|
||||
return reg.get('im_livechat.channel').get_available_user(cr, uid, channel) > 0
|
||||
return len(reg.get('im_livechat.channel').get_available_users(cr, uid, channel)) > 0
|
||||
|
||||
class im_livechat_channel(osv.osv):
|
||||
_name = 'im_livechat.channel'
|
||||
|
@ -159,7 +159,7 @@ class im_livechat_channel(osv.osv):
|
|||
'image': _get_default_image,
|
||||
}
|
||||
|
||||
def get_available_user(self, cr, uid, channel_id, context=None):
|
||||
def get_available_users(self, cr, uid, channel_id, context=None):
|
||||
channel = self.browse(cr, openerp.SUPERUSER_ID, channel_id, context=context)
|
||||
im_user_ids = self.pool.get("im.user").search(cr, uid, [["user_id", "in", [user.id for user in channel.user_ids]]], context=context)
|
||||
users = []
|
||||
|
@ -167,9 +167,17 @@ class im_livechat_channel(osv.osv):
|
|||
imuser = self.pool.get("im.user").browse(cr, uid, iuid, context=context)
|
||||
if imuser.im_status:
|
||||
users.append(imuser)
|
||||
return users
|
||||
|
||||
def get_session(self, cr, uid, channel_id, uuid, context=None):
|
||||
my_id = self.pool.get("im.user").get_my_id(cr, uid, uuid, context=context)
|
||||
users = self.get_available_users(cr, uid, channel_id, context=context)
|
||||
if len(users) == 0:
|
||||
return False
|
||||
return random.choice(users).id
|
||||
user_id = random.choice(users).id
|
||||
session = self.pool.get("im.session").session_get(cr, uid, user_id, uuid, context=context)
|
||||
self.pool.get("im.session").write(cr, openerp.SUPERUSER_ID, session.get("id"), {'channel_id': channel_id}, context=context)
|
||||
return session.get("id")
|
||||
|
||||
def test_channel(self, cr, uid, channel, context=None):
|
||||
if not channel:
|
||||
|
@ -198,50 +206,9 @@ class im_livechat_channel(osv.osv):
|
|||
self.write(cr, uid, ids, {'user_ids': [(3, uid)]})
|
||||
return True
|
||||
|
||||
"""
|
||||
class im_message(osv.osv):
|
||||
_inherit = 'im.message'
|
||||
|
||||
def _support_member(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
res[record.id] = False
|
||||
if record.to_id.user_id and record.from_id.user_id:
|
||||
continue
|
||||
elif record.to_id.user_id:
|
||||
res[record.id] = record.to_id.user_id.id
|
||||
elif record.from_id.user_id:
|
||||
res[record.id] = record.from_id.user_id.id
|
||||
return res
|
||||
|
||||
def _customer(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
res[record.id] = False
|
||||
if record.to_id.uuid and record.from_id.uuid:
|
||||
continue
|
||||
elif record.to_id.uuid:
|
||||
res[record.id] = record.to_id.id
|
||||
elif record.from_id.uuid:
|
||||
res[record.id] = record.from_id.id
|
||||
return res
|
||||
|
||||
def _direction(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
res[record.id] = False
|
||||
if not not record.to_id.user_id and not not record.from_id.user_id:
|
||||
continue
|
||||
elif not not record.to_id.user_id:
|
||||
res[record.id] = "c2s"
|
||||
elif not not record.from_id.user_id:
|
||||
res[record.id] = "s2c"
|
||||
return res
|
||||
class im_session(osv.osv):
|
||||
_inherit = 'im.session'
|
||||
|
||||
_columns = {
|
||||
'support_member_id': fields.function(_support_member, type='many2one', relation='res.users', string='Support Member', store=True, select=True),
|
||||
'customer_id': fields.function(_customer, type='many2one', relation='im.user', string='Customer', store=True, select=True),
|
||||
'direction': fields.function(_direction, type="selection", selection=[("s2c", "Support Member to Customer"), ("c2s", "Customer to Support Member")],
|
||||
string='Direction', store=False),
|
||||
'channel_id': fields.many2one("im.user", "Channel"),
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -92,7 +92,7 @@ define(["openerp", "im_common", "underscore", "require", "jquery",
|
|||
setTimeout(function() {
|
||||
def.reject();
|
||||
}, 5000);
|
||||
def.then(_.bind(this.chat, this), function() {
|
||||
return def.then(_.bind(this.chat, this), function() {
|
||||
im_common.notification(_t("It seems the connection to the server is encountering problems, please try again later."));
|
||||
});
|
||||
},
|
||||
|
@ -100,13 +100,12 @@ define(["openerp", "im_common", "underscore", "require", "jquery",
|
|||
var self = this;
|
||||
if (this.manager.conversations.length > 0)
|
||||
return;
|
||||
im_common.connection.model("im_livechat.channel").call("get_available_user", [this.channel]).then(function(user_id) {
|
||||
if (! user_id) {
|
||||
im_common.connection.model("im_livechat.channel").call("get_session", [this.channel, this.manager.me.get("uuid")]).then(function(session_id) {
|
||||
if (! session_id) {
|
||||
im_common.notification(_t("None of our collaborators seems to be available, please try again later."));
|
||||
return;
|
||||
}
|
||||
self.manager.ensure_users([user_id]).then(function() {
|
||||
var conv = self.manager.activate_user(self.manager.get_user(user_id), true);
|
||||
self.manager.activate_session(session_id, true).then(function(conv) {
|
||||
if (self.options.defaultMessage) {
|
||||
conv.received_message({message: self.options.defaultMessage,
|
||||
date: openerp.datetime_to_str(new Date())});
|
||||
|
|
Loading…
Reference in New Issue