Mercurial > libervia-web
comparison browser_side/panels.py @ 132:30d8e328559b
server & browser side: microblogging refactoring first draft
- use of new getLastGroupBlogs and getMassiveLastGroupBlogs methods
- microblgos browser's cache is temporarily deactivated
- last 10 microblogs for everybody are requested on new meta microblog widget
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2012 00:25:38 +0200 |
parents | ddfcc4cb6cee |
children | ceef355156de |
comparison
equal
deleted
inserted
replaced
131:ddfcc4cb6cee | 132:30d8e328559b |
---|---|
95 print "no message found" | 95 print "no message found" |
96 item=' ' | 96 item=' ' |
97 item_type = None | 97 item_type = None |
98 DOM.eventPreventDefault(event) | 98 DOM.eventPreventDefault(event) |
99 if item_type=="GROUP": | 99 if item_type=="GROUP": |
100 _new_panel = MicroblogPanel(self.host, item) | 100 _new_panel = MicroblogPanel(self.host, [item]) |
101 _new_panel.setAcceptedGroup(item) | 101 _new_panel.setAcceptedGroup(item) |
102 self.host.FillMicroblogPanel(_new_panel) | 102 self.host.FillMicroblogPanel(_new_panel) #XXX: cache is temporarly deactivated, need to be reworked |
103 elif item_type=="CONTACT": | 103 elif item_type=="CONTACT": |
104 _contact = JID(item) | 104 _contact = JID(item) |
105 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) | 105 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
106 _new_panel = ChatPanel(self.host, _contact) | 106 _new_panel = ChatPanel(self.host, _contact) |
107 _new_panel.historyPrint() | 107 _new_panel.historyPrint() |
108 elif item_type=="CONTACT_TITLE": | 108 elif item_type=="CONTACT_TITLE": |
109 _new_panel = MicroblogPanel(self.host, accept_all=True) | 109 _new_panel = MicroblogPanel(self.host, []) |
110 self.host.FillMicroblogPanel(_new_panel) | 110 #self.host.FillMicroblogPanel(_new_panel) #XXX: cache is temporarly deactivated, need to be reworked |
111 self.host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) | |
111 else: | 112 else: |
112 return False | 113 return False |
113 if isinstance(self, LiberviaWidget): | 114 if isinstance(self, LiberviaWidget): |
114 self.host.unregisterWidget(self) | 115 self.host.unregisterWidget(self) |
115 if not isinstance(_new_panel, LiberviaWidget): | 116 if not isinstance(_new_panel, LiberviaWidget): |
471 | 472 |
472 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done | 473 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
473 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | 474 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this |
474 return AutoCompleteTextBox.complete(self)""" | 475 return AutoCompleteTextBox.complete(self)""" |
475 | 476 |
477 class MicroblogItem(): | |
478 #XXX: should be moved in a separated module | |
479 | |
480 def __init__(self, data): | |
481 self.id = data['id'] | |
482 self.content = data['content'] | |
483 self.author = data['author'] | |
484 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here | |
485 | |
476 class MicroblogEntry(SimplePanel): | 486 class MicroblogEntry(SimplePanel): |
477 | 487 |
478 def __init__(self, host, mblog_entry): | 488 def __init__(self, host, mblog_entry): |
479 SimplePanel.__init__(self) | 489 SimplePanel.__init__(self) |
480 | 490 |
502 self.avatar.setUrl(new_avatar) | 512 self.avatar.setUrl(new_avatar) |
503 | 513 |
504 | 514 |
505 class MicroblogPanel(LiberviaWidget): | 515 class MicroblogPanel(LiberviaWidget): |
506 | 516 |
507 def __init__(self, host, title='', accept_all=False): | 517 def __init__(self, host, accepted_groups): |
508 """Panel used to show microblog | 518 """Panel used to show microblog |
509 @param title: title of the panel | 519 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts |
510 @param accept_all: if true, show every message, without filtering jids""" | 520 """ |
511 LiberviaWidget.__init__(self, host, title) | 521 LiberviaWidget.__init__(self, host, ", ".join(accepted_groups)) |
512 #ScrollPanelWrapper.__init__(self) | 522 #ScrollPanelWrapper.__init__(self) |
513 #DropCell.__init__(self) | 523 #DropCell.__init__(self) |
514 self.accept_all = accept_all | 524 self.accepted_groups = accepted_groups |
515 self.accepted_groups = [] | |
516 self.entries = {} | 525 self.entries = {} |
517 self.vpanel = VerticalPanel() | 526 self.vpanel = VerticalPanel() |
518 self.vpanel.setStyleName('microblogPanel') | 527 self.vpanel.setStyleName('microblogPanel') |
519 self.setWidget(self.vpanel) | 528 self.setWidget(self.vpanel) |
520 | 529 |
530 def accept_all(self): | |
531 return not self.accepted_groups #we accept every microblog only if we are not filtering by groups | |
532 | |
533 def getEntries(self): | |
534 """Ask all the entries for the currenly accepted groups, | |
535 and fill the panel""" | |
536 | |
537 def massiveInsert(self, mblogs): | |
538 """Insert several microblogs at once | |
539 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs | |
540 """ | |
541 print "Massive insertion of microblogs" | |
542 for publisher in mblogs: | |
543 print "adding blogs for [%s]" % publisher | |
544 for mblog in mblogs[publisher]: | |
545 if not mblog.has_key('content'): | |
546 print ("WARNING: No content found in microblog [%s]", mblog) | |
547 continue | |
548 mblog_entry = MicroblogItem(mblog) | |
549 self.addEntry(mblog_entry) | |
550 | |
521 def addEntry(self, mblog_entry): | 551 def addEntry(self, mblog_entry): |
522 """Add an entry to the panel | 552 """Add an entry to the panel |
523 @param text: main text of the entry | 553 @param mblog_entry: MicroblogItem instance |
524 @param id: unique id of the entry | 554 """ |
525 @param author: who wrote the entry | |
526 @param date: when the entry was written""" | |
527 if mblog_entry.id in self.entries: | 555 if mblog_entry.id in self.entries: |
528 return | 556 return |
529 _entry = MicroblogEntry(self.host, mblog_entry) | 557 _entry = MicroblogEntry(self.host, mblog_entry) |
530 self.entries[mblog_entry.id] = _entry | 558 self.entries[mblog_entry.id] = _entry |
531 self.vpanel.insert(_entry,0) | 559 self.vpanel.insert(_entry,0) |
551 | 579 |
552 def isJidAccepted(self, jid): | 580 def isJidAccepted(self, jid): |
553 """Tell if a jid is actepted and show in this panel | 581 """Tell if a jid is actepted and show in this panel |
554 @param jid: jid | 582 @param jid: jid |
555 @return: True if the jid is accepted""" | 583 @return: True if the jid is accepted""" |
556 if self.accept_all: | 584 if self.accept_all(): |
557 return True | 585 return True |
558 for group in self.accepted_groups: | 586 for group in self.accepted_groups: |
559 if self.host.contact_panel.isContactInGroup(group, jid): | 587 if self.host.contact_panel.isContactInGroup(group, jid): |
560 return True | 588 return True |
561 return False | 589 return False |