fix the fetch of a single thread (when no listed on the main contacts page)

This commit is contained in:
Romain Bignon 2010-07-04 17:17:16 +02:00
commit a041e1b210

View file

@ -76,41 +76,47 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
for message in self._iter_messages(thread, True): for message in self._iter_messages(thread, True):
yield message yield message
def _get_slut(self, id):
if not id in self.storage.get('sluts'):
slut = {'lastmsg': datetime(1970,1,1),
'msgstatus': ''}
else:
slut = self.storage.get('sluts', id)
slut['lastmsg'] = slut['lastmsg'].replace(tzinfo=tz.tzutc())
return slut
def _iter_messages(self, thread, only_new): def _iter_messages(self, thread, only_new):
with self.browser: with self.browser:
try: try:
profiles = {} profiles = {}
if thread:
slut = self._get_slut(int(thread))
for mail in self._iter_thread_messages(thread, only_new, slut['lastmsg'], {}):
if slut['lastmsg'] < mail.get_date():
slut['lastmsg'] = mail.get_date()
yield mail
self.storage.set('sluts', int(thread), slut)
self.storage.save()
else:
contacts = self.browser.get_threads_list() contacts = self.browser.get_threads_list()
for contact in contacts: for contact in contacts:
if not contact.get_id() in self.storage.get('sluts'): slut = self._get_slut(contact.get_id())
slut = {'lastmsg': datetime(1970,1,1), last_msg = slut['lastmsg']
'msgstatus': ''}
else:
slut = self.storage.get('sluts', contact.get_id())
last_msg = slut['lastmsg'].replace(tzinfo=tz.tzutc())
new_lastmsg = last_msg
if only_new and contact.get_lastmsg_date() < last_msg and contact.get_status() == slut['msgstatus'] or \ if only_new and contact.get_lastmsg_date() < last_msg and contact.get_status() == slut['msgstatus'] or \
not thread is None and int(thread) != contact.get_id(): not thread is None and int(thread) != contact.get_id():
continue continue
mails = self.browser.get_thread_mails(contact.get_id()) for mail in self._iter_thread_messages(contact.get_id(), only_new, last_msg, profiles):
for mail in mails: if last_msg < mail.get_date():
if only_new and mail.get_date() <= last_msg: last_msg = mail.get_date()
continue
if not mail.profile_link in profiles:
profiles[mail.profile_link] = self.browser.get_profile(mail.profile_link)
mail.signature += u'\n%s' % profiles[mail.profile_link].get_profile_text()
if new_lastmsg < mail.get_date():
new_lastmsg = mail.get_date()
yield mail yield mail
slut['lastmsg'] = new_lastmsg slut['lastmsg'] = last_msg
slut['msgstatus'] = contact.get_status() slut['msgstatus'] = contact.get_status()
self.storage.set('sluts', contact.get_id(), slut) self.storage.set('sluts', contact.get_id(), slut)
self.storage.save() self.storage.save()
@ -133,6 +139,18 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
except BrowserUnavailable: except BrowserUnavailable:
pass pass
def _iter_thread_messages(self, id, only_new, last_msg, profiles):
mails = self.browser.get_thread_mails(id)
for mail in mails:
if only_new and mail.get_date() <= last_msg:
continue
if not mail.profile_link in profiles:
profiles[mail.profile_link] = self.browser.get_profile(mail.profile_link)
mail.signature += u'\n%s' % profiles[mail.profile_link].get_profile_text()
yield mail
def post_reply(self, thread_id, reply_id, title, message): def post_reply(self, thread_id, reply_id, title, message):
while 1: while 1:
try: try: