comparison src/browser/sat_browser/panels.py @ 518:3d8e8f693576

browser_side: avoid some confusions between jid object 1. as an instance of JID or 2. as a str
author souliane <souliane@mailoo.org>
date Tue, 02 Sep 2014 21:13:59 +0200
parents db3436c85fb1
children d2bf317b2d28
comparison
equal deleted inserted replaced
517:85699d18921f 518:3d8e8f693576
1251 def getHistoryCB(history): 1251 def getHistoryCB(history):
1252 # display day change 1252 # display day change
1253 day_format = "%A, %d %b %Y" 1253 day_format = "%A, %d %b %Y"
1254 previous_day = datetime.now().strftime(day_format) 1254 previous_day = datetime.now().strftime(day_format)
1255 for line in history: 1255 for line in history:
1256 timestamp, from_jid, to_jid, message, mess_type, extra = line 1256 timestamp, from_jid_s, to_jid_s, message, mess_type, extra = line
1257 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format) 1257 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
1258 if previous_day != message_day: 1258 if previous_day != message_day:
1259 self.printInfo("* " + message_day) 1259 self.printInfo("* " + message_day)
1260 previous_day = message_day 1260 previous_day = message_day
1261 self.printMessage(from_jid, message, extra, timestamp) 1261 self.printMessage(jid.JID(from_jid_s), message, extra, timestamp)
1262 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) 1262 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
1263 1263
1264 def printInfo(self, msg, type_='normal', link_cb=None): 1264 def printInfo(self, msg, type_='normal', link_cb=None):
1265 """Print general info 1265 """Print general info
1266 @param msg: message to print 1266 @param msg: message to print
1283 _wid.setStyleName('chatTextInfo') 1283 _wid.setStyleName('chatTextInfo')
1284 self.content.add(_wid) 1284 self.content.add(_wid)
1285 1285
1286 def printMessage(self, from_jid, msg, extra, timestamp=None): 1286 def printMessage(self, from_jid, msg, extra, timestamp=None):
1287 """Print message in chat window. Must be implemented by child class""" 1287 """Print message in chat window. Must be implemented by child class"""
1288 _jid = jid.JID(from_jid) 1288 nick = from_jid.node if self.type == 'one2one' else from_jid.resource
1289 nick = _jid.node if self.type == 'one2one' else _jid.resource 1289 mymess = from_jid.resource == self.nick if self.type == "group" else from_jid.bare == self.host.whoami.bare # mymess = True if message comes from local user
1290 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare # mymess = True if message comes from local user
1291 if msg.startswith('/me '): 1290 if msg.startswith('/me '):
1292 self.printInfo('* %s %s' % (nick, msg[4:]), type_='me') 1291 self.printInfo('* %s %s' % (nick, msg[4:]), type_='me')
1293 return 1292 return
1294 self.content.add(base_panels.ChatText(timestamp, nick, mymess, msg, extra.get('xhtml'))) 1293 self.content.add(base_panels.ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
1295 self.content_scroll.scrollToBottom() 1294 self.content_scroll.scrollToBottom()