[aum] aibility to post answers

This commit is contained in:
Romain Bignon 2010-04-11 12:03:59 +02:00
commit 637875c49a
4 changed files with 24 additions and 8 deletions

View file

@ -197,12 +197,14 @@ class AdopteUnMec(Browser):
@pageaccess @pageaccess
def get_thread_mails(self, id): def get_thread_mails(self, id):
self.page.open_thread_page(id) if not self.is_on_page(ContactThreadPage) or self.page.get_id() != int(id):
self.page.open_thread_page(id)
return self.page.get_mails() return self.page.get_mails()
@pageaccess @pageaccess
def post_mail(self, id, content): def post_mail(self, id, content):
self.page.open_thread_page(id) if not self.is_on_page(ContactThreadPage) or self.page.get_id() != int(id):
self.page.open_thread_page(id)
self.page.post(content) self.page.post(content)
@pageaccess @pageaccess

View file

@ -40,6 +40,10 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
if not self._browser: if not self._browser:
self._browser = AdopteUnMec(self.config['username'], self.config['password']) self._browser = AdopteUnMec(self.config['username'], self.config['password'])
return self._browser return self._browser
if name == 'queue_messages':
if not hasattr(self, '_queue_messages'):
self._queue_messages = []
return self._queue_messages
raise AttributeError, name raise AttributeError, name
def iter_messages(self, thread=None): def iter_messages(self, thread=None):
@ -47,6 +51,11 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
yield message yield message
def iter_new_messages(self, thread=None): def iter_new_messages(self, thread=None):
for message in self.queue_messages:
if not thread or message.get_thread_id() == thread:
yield message
self.queue_messages = []
for message in self._iter_messages(thread, True): for message in self._iter_messages(thread, True):
yield message yield message
@ -57,7 +66,7 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
contacts.reverse() contacts.reverse()
for contact in contacts: for contact in contacts:
if only_new and not contact.is_new(): if only_new and not contact.is_new() or thread and int(thread) != contact.get_id():
continue continue
mails = self.browser.get_thread_mails(contact.get_id()) mails = self.browser.get_thread_mails(contact.get_id())
@ -70,5 +79,9 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
if not profile: if not profile:
profile = self.browser.get_profile(contact.get_id()) profile = self.browser.get_profile(contact.get_id())
mail.signature += u'\n%s' % profile.get_profile_text() mail.signature += u'\n%s' % profile.get_profile_text()
print mail.signature
yield mail yield mail
def post_reply(self, thread_id, reply_id, title, message):
for message in self._iter_messages(thread_id, True):
self.queue_messages.append(message)
return self.browser.post(thread_id, message)

View file

@ -267,7 +267,6 @@ class ContactThreadPage(PageBase):
id_regexp = re.compile("/thread.php\?id=([0-9]+)") id_regexp = re.compile("/thread.php\?id=([0-9]+)")
def loaded(self): def loaded(self):
self.items = [] self.items = []
a_list = self.document.getElementsByTagName('a') a_list = self.document.getElementsByTagName('a')
@ -311,6 +310,8 @@ class ContactThreadPage(PageBase):
self.items[-1].reply_date = mail.get_date_int() self.items[-1].reply_date = mail.get_date_int()
self.items += [mail] self.items += [mail]
def get_mails(self): def get_id(self):
return self.id
def get_mails(self):
return self.items return self.items

View file

@ -107,5 +107,5 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
self.storage.set(self.name, 'seen', what, seen) self.storage.set(self.name, 'seen', what, seen)
self.storage.save(self.name) self.storage.save(self.name)
def post_reply(self, thread_id, reply_id, message): def post_reply(self, thread_id, reply_id, title, message):
return self.browser.post(thread_id, reply_id, message) return self.browser.post(thread_id, reply_id, title, message)