@@ -109,7 +109,7 @@ def poll(self, last=None, users_watch=None, db=None, uid=None, password=None, uu
109
109
registry = openerp .modules .registry .RegistryManager .get (db )
110
110
with registry .cursor () as cr :
111
111
registry .get ('im.user' ).im_connect (cr , uid , uuid = uuid , context = request .context )
112
- my_id = registry .get ('im.user' ).get_by_user_id (cr , uid , uuid or uid , request .context )[ "id" ]
112
+ my_id = registry .get ('im.user' ).get_my_id (cr , uid , uuid , request .context )
113
113
num = 0
114
114
while True :
115
115
with registry .cursor () as cr :
@@ -156,7 +156,7 @@ def get_messages(self, cr, uid, last=None, users_watch=None, uuid=None, context=
156
156
157
157
# complex stuff to determine the last message to show
158
158
users = self .pool .get ("im.user" )
159
- my_id = users .get_by_user_id (cr , uid , uuid or uid , context = context )[ "id" ]
159
+ my_id = users .get_my_id (cr , uid , uuid , context = context )
160
160
c_user = users .browse (cr , openerp .SUPERUSER_ID , my_id , context = context )
161
161
if last :
162
162
if c_user .im_last_received < last :
@@ -181,7 +181,7 @@ def get_messages(self, cr, uid, last=None, users_watch=None, uuid=None, context=
181
181
182
182
def post (self , cr , uid , message , to_user_id , uuid = None , context = None ):
183
183
assert_uuid (uuid )
184
- my_id = self .pool .get ('im.user' ).get_by_user_id (cr , uid , uuid or uid )[ "id" ]
184
+ my_id = self .pool .get ('im.user' ).get_my_id (cr , uid , uuid )
185
185
self .create (cr , openerp .SUPERUSER_ID , {"message" : message , 'from_id' : my_id , 'to_id' : to_user_id }, context = context )
186
186
notify_channel (cr , "im_channel" , {'type' : 'message' , 'receiver' : to_user_id })
187
187
return False
@@ -199,10 +199,9 @@ def _im_status(self, cr, uid, ids, something, something_else, context=None):
199
199
res [obj ["id" ]] = obj ["im_last_status" ] and (last_update + delta ) > current
200
200
return res
201
201
202
- def search_users (self , cr , uid , domain , fields , limit , context = None ):
203
- # do not user openerp.SUPERUSER_ID, reserved to normal users
204
- found = self .pool .get ('res.users' ).search (cr , uid , domain , limit = limit , context = context )
205
- found = self .get_by_user_ids (cr , uid , found , context = context )
202
+ def search_users (self , cr , uid , text_search , fields , limit , context = None ):
203
+ my_id = self .get_my_id (cr , uid , None , context )
204
+ found = self .search (cr , uid , [["name" , "ilike" , text_search ], ["id" , "<>" , my_id ]], limit = limit , context = context )
206
205
return self .read (cr , uid , found , fields , context = context )
207
206
208
207
def im_connect (self , cr , uid , uuid = None , context = None ):
@@ -215,45 +214,28 @@ def im_disconnect(self, cr, uid, uuid=None, context=None):
215
214
216
215
def _im_change_status (self , cr , uid , new_one , uuid = None , context = None ):
217
216
assert_uuid (uuid )
218
- id = self .get_by_user_id (cr , uid , uuid or uid , context = context )[ "id" ]
217
+ id = self .get_my_id (cr , uid , uuid , context = context )
219
218
current_status = self .read (cr , openerp .SUPERUSER_ID , id , ["im_status" ], context = None )["im_status" ]
220
219
self .write (cr , openerp .SUPERUSER_ID , id , {"im_last_status" : new_one ,
221
220
"im_last_status_update" : datetime .datetime .now ().strftime (DEFAULT_SERVER_DATETIME_FORMAT )}, context = context )
222
221
if current_status != new_one :
223
222
notify_channel (cr , "im_channel" , {'type' : 'status' , 'user' : id })
224
223
return True
225
224
226
- def get_by_user_id (self , cr , uid , id , context = None ):
227
- ids = self .get_by_user_ids (cr , uid , [id ], context = context )
228
- return ids [0 ]
229
-
230
- def get_by_user_ids (self , cr , uid , ids , context = None ):
231
- user_ids = [x for x in ids if isinstance (x , int )]
232
- uuids = [x for x in ids if isinstance (x , (str , unicode ))]
233
- users = self .search (cr , openerp .SUPERUSER_ID , ["|" , ["user_id" , "in" , user_ids ], ["uuid" , "in" , uuids ]], context = None )
234
- records = self .read (cr , openerp .SUPERUSER_ID , users , ["user_id" , "uuid" ], context = None )
235
- inside = {}
236
- for i in records :
237
- if i ["user_id" ]:
238
- inside [i ["user_id" ][0 ]] = True
239
- elif ["uuid" ]:
240
- inside [i ["uuid" ]] = True
241
- not_inside = {}
242
- for i in ids :
243
- if not (i in inside ):
244
- not_inside [i ] = True
245
- for to_create in not_inside .keys ():
246
- if isinstance (to_create , int ):
247
- created = self .create (cr , openerp .SUPERUSER_ID , {"user_id" : to_create }, context = context )
248
- records .append ({"id" : created , "user_id" : [to_create , "" ]})
249
- else :
250
- created = self .create (cr , openerp .SUPERUSER_ID , {"uuid" : to_create }, context = context )
251
- records .append ({"id" : created , "uuid" : to_create })
252
- return records
225
+ def get_my_id (self , cr , uid , uuid = None , context = None ):
226
+ assert_uuid (uuid )
227
+ if uuid :
228
+ users = self .search (cr , openerp .SUPERUSER_ID , [["uuid" , "=" , uuid ]], context = None )
229
+ else :
230
+ users = self .search (cr , openerp .SUPERUSER_ID , [["user_id" , "=" , uid ]], context = None )
231
+ my_id = users [0 ] if len (users ) >= 1 else False
232
+ if not my_id :
233
+ my_id = self .create (cr , openerp .SUPERUSER_ID , {"user_id" : uid if not uuid else False , "uuid" : uuid if uuid else False }, context = context )
234
+ return my_id
253
235
254
236
def assign_name (self , cr , uid , uuid , name , context = None ):
255
237
assert_uuid (uuid )
256
- id = self .get_by_user_id (cr , uid , uuid or uid , context = context )[ "id" ]
238
+ id = self .get_my_id (cr , uid , uuid , context = context )
257
239
self .write (cr , openerp .SUPERUSER_ID , id , {"assigned_name" : name }, context = context )
258
240
return True
259
241
0 commit comments