Mercurial > libervia-backend
diff sat_frontends/jp/output_std.py @ 2707:b156b78b8f9a
jp (output): new OUTPUT_MESS output to handle data containing chat messages
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Dec 2018 10:48:01 +0100 |
parents | 56f94936df1e |
children | 003b8b4b56a7 |
line wrap: on
line diff
--- a/sat_frontends/jp/output_std.py Sat Dec 01 10:47:59 2018 +0100 +++ b/sat_frontends/jp/output_std.py Sat Dec 01 10:48:01 2018 +0100 @@ -20,7 +20,9 @@ from sat_frontends.jp.constants import Const as C +from sat_frontends.tools import jid from sat.tools.common.ansi import ANSI as A +from sat.tools.common import date_utils import json __outputs__ = ["Simple", "Json"] @@ -39,6 +41,7 @@ host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict) host.register_output(C.OUTPUT_LIST_DICT, SIMPLE, self.list_dict) host.register_output(C.OUTPUT_DICT_DICT, SIMPLE, self.dict_dict) + host.register_output(C.OUTPUT_MESS, SIMPLE, self.messages) host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print) def simple_print(self, data): @@ -76,6 +79,30 @@ self.host.disp(A.color(C.A_HEADER, key)) self.dict(sub_dict, indent=4, header_color=C.A_SUBHEADER) + def messages(self, data): + # TODO: handle lang, and non chat message (normal, headline) + for mess_data in data: + (uid, timestamp, from_jid, to_jid, message, subject, mess_type, + extra) = mess_data + time_str = date_utils.date_fmt(timestamp, u"auto_day", + tz_info=date_utils.TZ_LOCAL) + from_jid = jid.JID(from_jid) + if mess_type == C.MESS_TYPE_GROUPCHAT: + nick = from_jid.resource + else: + nick = from_jid.node + + if self.host.own_jid is not None and self.host.own_jid.bare == from_jid.bare: + nick_color = A.BOLD + A.FG_BLUE + else: + nick_color = A.BOLD + A.FG_YELLOW + message = message.values()[0] if message else u"" + + self.host.disp(A.color( + A.FG_CYAN, u'['+time_str+u'] ', + nick_color, nick, A.RESET, A.BOLD, u'> ', + A.RESET, message)) + class Json(object): """outputs in json format""" @@ -91,6 +118,8 @@ host.register_output(C.OUTPUT_LIST_DICT, JSON_RAW, self.dump) host.register_output(C.OUTPUT_DICT_DICT, JSON, self.dump_pretty) host.register_output(C.OUTPUT_DICT_DICT, JSON_RAW, self.dump) + host.register_output(C.OUTPUT_MESS, JSON, self.dump_pretty) + host.register_output(C.OUTPUT_MESS, JSON_RAW, self.dump) host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty) host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)