def updateMessageView(self, maxcount = 0): maxcount = maxcount or 200 mt = self.ui.messageTable items = [ (n, str(i.text(1)), mt.itemWidget(i, 0), i) for n, i in enumerate(map(lambda n:mt.topLevelItem(n), range(mt.topLevelItemCount()))) ] pids = [ str(item[2].id.text()) for item in items ] olditems = list(items) olds = list(pids) n = 0 self.app.icons.avatar_cache = {} messages = self.app.db.get_messages_from_cache(maxcount) print "* update message view", len(messages) for _blob in messages: blob = prepare_post(_blob.__dict__) if str(blob.pid) in olds: i = olds.index(str(blob.pid)) olditems.pop(i) olds.pop(i) if str(blob.pid) not in pids: pids.append(blob.pid) msg, time = self.build_message_item(blob) i = QTreeWidgetItem(mt) i.setText(1, time) mt.setItemWidget(i, 0, msg) # now remove the too old ones items.sort(key=lambda i:i[1]) for old in list(reversed(items))[maxcount-1:] + olditems: mt.removeItemWidget(old[3], 0) item = old[2] del item
def build_conversation(self, account, previous): if not previous: return # nothing to do previous = [drug(**previous)] #print "try to build conversation",previous[0].pid,"(%s)"%account.service Post, Conversation = self.db.Post, self.db.Conversation while True: posts = Post.find().filter_by(pid = previous[-1].reply).all() if posts: previous.append(prepare_post(posts[0].__dict__)) else: try: status = api_call(account.service, 'statuses/user_timeline', {'id': previous[-1].replied_user, 'max_id':previous[-1].reply, 'count': 1}) except: print "[ERROR] during conversion fetch" print_exc() break if not status: break # nothing fetched or empty list update = parse_post(account, "", status[0]) update['source_id'] = update['user_id'] #print account.service, "con", update['pid'] update['by_conversation'] = True Post(**update).add() previous.append(drug(**update)) if previous[-1].reply is None: break if len(previous) == 1: return # still no conversation ids = " ".join(list(map(lambda p: str(p.pid), previous[1:]))) Conversation(pid = previous[0].pid, ids = ids).save() #print "conversation", previous[0].pid, "build." self.app.reader.update()
def showConversation(self, item, _): mt = self.ui.messageTable msg = mt.itemWidget(item, 0) if item.isExpanded(): msg.replyLabel.setVisible(True) return # allready added if not msg.replyLabel.isVisible(): return # no conversation msg.replyLabel.setVisible(False) if item.childCount(): return # allready added messages = self.app.db.get_conversation_messages(int(msg.id.text())) for _blob in messages: blob = prepare_post(_blob.__dict__) msg, time = self.build_message_item(blob) msg.replyLabel.setVisible(False) # no conversation trees possible i = QTreeWidgetItem(item) i.setText(1, time) mt.setItemWidget(i, 0, msg)