comparison frontends/src/quick_frontend/quick_chat.py @ 1125:d6c3fea5ecfe

quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
author souliane <souliane@mailoo.org>
date Sat, 23 Aug 2014 20:26:04 +0200
parents d1084f7e56a5
children 75025461141f
comparison
equal deleted inserted replaced
1124:7ee18dbfb661 1125:d6c3fea5ecfe
94 log.debug(_("Setting subject to %s") % subject) 94 log.debug(_("Setting subject to %s") % subject)
95 if self.type != "group": 95 if self.type != "group":
96 log.error (_("[INTERNAL] trying to set subject for a non group chat window")) 96 log.error (_("[INTERNAL] trying to set subject for a non group chat window"))
97 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 97 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
98 98
99 def afterHistoryPrint(self):
100 """Refresh or scroll down the focus after the history is printed"""
101 pass
102
99 def historyPrint(self, size=20, profile='@NONE@'): 103 def historyPrint(self, size=20, profile='@NONE@'):
100 """Print the initial history""" 104 """Print the current history
101 log.debug (_("now we print history")) 105 @param size (int): number of messages
106 @param profile (str): %(doc_profile)s
107 """
108 log.debug(_("now we print the history (%d messages)") % size)
109
102 def onHistory(history): 110 def onHistory(history):
103 for line in history: 111 for line in history:
104 timestamp, from_jid, to_jid, message, _type, extra = line 112 timestamp, from_jid, to_jid, message, _type, extra = line
105 if ((self.type == 'group' and _type != 'groupchat') or 113 if ((self.type == 'group' and _type != 'groupchat') or
106 (self.type == 'one2one' and _type == 'groupchat')): 114 (self.type == 'one2one' and _type == 'groupchat')):
107 continue 115 continue
108 self.printMessage(JID(from_jid), message, profile, timestamp) 116 self.printMessage(JID(from_jid), message, profile, timestamp)
117 self.afterHistoryPrint()
109 118
110 def onHistoryError(err): 119 def onHistoryError(err):
111 log.error (_("Can't get history")) 120 log.error(_("Can't get history"))
112 121
113 if self.target.startswith(Const.PRIVATE_PREFIX): 122 if self.target.startswith(Const.PRIVATE_PREFIX):
114 target = unescapePrivate(self.target) 123 target = unescapePrivate(self.target)
115 else: 124 else:
116 target = self.target.bare 125 target = self.target.bare
117 126
118 self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError) 127 return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError)
119 128
120 def _get_nick(self, jid): 129 def _get_nick(self, jid):
121 """Return nick of this jid when possible""" 130 """Return nick of this jid when possible"""
122 if self.target.startswith(Const.PRIVATE_PREFIX): 131 if self.target.startswith(Const.PRIVATE_PREFIX):
123 unescaped = unescapePrivate(self.target) 132 unescaped = unescapePrivate(self.target)