fix getting contacts list

This commit is contained in:
Romain Bignon 2011-10-16 20:59:57 +02:00
commit 0fb2951b57

View file

@ -120,7 +120,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
t.title = 'Discussion with %s' % thread['member']['pseudo'] t.title = 'Discussion with %s' % thread['member']['pseudo']
yield t yield t
def get_thread(self, id, contacts=None): def get_thread(self, id, contacts=None, get_profiles=False):
""" """
Get a thread and its messages. Get a thread and its messages.
@ -164,13 +164,14 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
if parse_dt(mail['date']) > slut['lastmsg']: if parse_dt(mail['date']) > slut['lastmsg']:
flags |= Message.IS_UNREAD flags |= Message.IS_UNREAD
if not mail['id_from'] in contacts: if get_profiles:
with self.browser: if not mail['id_from'] in contacts:
contacts[mail['id_from']] = self.get_contact(mail['id_from']) with self.browser:
if self.antispam and not self.antispam.check_contact(contacts[mail['id_from']]): contacts[mail['id_from']] = self.get_contact(mail['id_from'])
self.logger.info('Skipped a spam-mail-profile from %s' % mails['member']['pseudo']) if self.antispam and not self.antispam.check_contact(contacts[mail['id_from']]):
self.report_spam(thread.id) self.logger.info('Skipped a spam-mail-profile from %s' % mails['member']['pseudo'])
break self.report_spam(thread.id)
break
if int(mail['id_from']) == self.browser.my_id: if int(mail['id_from']) == self.browser.my_id:
if int(mails['remoteStatus']) == 0 and msg is None: if int(mails['remoteStatus']) == 0 and msg is None:
@ -223,7 +224,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
continue continue
slut = self._get_slut(thread['member']['id']) slut = self._get_slut(thread['member']['id'])
if parse_dt(thread['date']) > slut['lastmsg'] or int(thread['status']) != int(slut['status']): if parse_dt(thread['date']) > slut['lastmsg'] or int(thread['status']) != int(slut['status']):
t = self.get_thread(thread['member']['id'], contacts) t = self.get_thread(thread['member']['id'], contacts, get_profiles=True)
for m in t.iter_all_messages(): for m in t.iter_all_messages():
if m.flags & m.IS_UNREAD: if m.flags & m.IS_UNREAD:
yield m yield m
@ -351,23 +352,36 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None): def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
with self.browser: with self.browser:
for contact in self.browser.iter_contacts(): threads = self.browser.get_threads_list(count=100)
s = 0 for thread in threads:
if contact['isOnline']: contact = thread['member']
s = Contact.STATUS_ONLINE if contact.get('isBan', True):
else: with self.browser:
s = Contact.STATUS_OFFLINE self.browser.delete_thread(int(contact['id']))
continue
s = 0
if contact['isOnline']:
s = Contact.STATUS_ONLINE
else:
s = Contact.STATUS_OFFLINE
if not status & s or (ids and not contact['id'] in ids): if not status & s or (ids and not contact['id'] in ids):
continue continue
c = Contact(contact['id'], contact['pseudo'], s) c = Contact(contact['id'], contact['pseudo'], s)
c.url = self.browser.id2url(contact['id']) c.url = self.browser.id2url(contact['id'])
c.status_msg = u'%s old' % contact['birthday'] birthday = _parse_dt(contact['birthday'])
c.set_photo(contact['cover'].split('/')[-1].replace('thumb0_', 'image'), age = int((datetime.datetime.now() - birthday).days / 365.25)
url=contact['cover'].replace('thumb0_', 'image'), c.status_msg = u'%s old' % age
thumbnail_url=contact['cover']) if int(contact['cover']) > 0:
yield c url = 'http://s%s.adopteunmec.com/%s%%(type)s%s.jpg' % (contact['shard'], contact['path'], contact['cover'])
else:
url = 'http://s.adopteunmec.com/www/img/thumb0.gif'
c.set_photo('image%s' % contact['cover'],
url=url % {'type': 'image'},
thumbnail_url=url % {'type': 'thumb0_'})
yield c
def send_query(self, id): def send_query(self, id):
if isinstance(id, Contact): if isinstance(id, Contact):