diff --git a/frontends/src/primitivus/chat.py b/frontends/src/primitivus/chat.py index c4b58193..7bd420dd 100644 --- a/frontends/src/primitivus/chat.py +++ b/frontends/src/primitivus/chat.py @@ -275,6 +275,16 @@ class Chat(urwid.WidgetWrap, QuickChat): self.present_wid.deleteValue(nick) self.host.redraw() + def clearHistory(self): + """Clear the content of this chat.""" + del self.content[:] + + def afterHistoryPrint(self): + """Refresh or scroll down the focus after the history is printed""" + if len(self.content): + self.text_list.focus_position = len(self.content) - 1 # scroll down + self.host.redraw() + def printMessage(self, from_jid, msg, profile, timestamp=""): assert isinstance(from_jid, JID) try: diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index b9265b0b..3a194236 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -38,7 +38,7 @@ from sat_frontends.primitivus.progress import Progress from sat_frontends.primitivus.notify import Notify from sat_frontends.tools.misc import InputHistory from sat_frontends.constants import Const as commonConst # FIXME -from sat.tools.jid import JID +from sat.tools.jid import JID from os.path import join @@ -133,6 +133,15 @@ class EditBar(sat_widgets.ModalEdit): self.app.status_bar.onChange(user_data=sat_widgets.AdvancedEdit(args[0])) else: self.app.status_bar.onStatusClick() + elif command == 'history': + try: + limit = int(args[0]) + except (IndexError, ValueError): + limit = 50 + win = self.app.chat_wins[JID(self.app.contact_list.selected).bare] + win.clearHistory() + if limit > 0: + win.historyPrint(size=limit, profile=self.app.profile) else: return self.set_edit_text('') diff --git a/frontends/src/quick_frontend/quick_chat.py b/frontends/src/quick_frontend/quick_chat.py index a2a6984e..ebf6d896 100644 --- a/frontends/src/quick_frontend/quick_chat.py +++ b/frontends/src/quick_frontend/quick_chat.py @@ -96,9 +96,17 @@ class QuickChat(object): log.error (_("[INTERNAL] trying to set subject for a non group chat window")) raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here + def afterHistoryPrint(self): + """Refresh or scroll down the focus after the history is printed""" + pass + def historyPrint(self, size=20, profile='@NONE@'): - """Print the initial history""" - log.debug (_("now we print history")) + """Print the current history + @param size (int): number of messages + @param profile (str): %(doc_profile)s + """ + log.debug(_("now we print the history (%d messages)") % size) + def onHistory(history): for line in history: timestamp, from_jid, to_jid, message, _type, extra = line @@ -106,16 +114,17 @@ class QuickChat(object): (self.type == 'one2one' and _type == 'groupchat')): continue self.printMessage(JID(from_jid), message, profile, timestamp) + self.afterHistoryPrint() def onHistoryError(err): - log.error (_("Can't get history")) + log.error(_("Can't get history")) if self.target.startswith(Const.PRIVATE_PREFIX): target = unescapePrivate(self.target) else: target = self.target.bare - self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError) + return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError) def _get_nick(self, jid): """Return nick of this jid when possible"""