# HG changeset patch # User Goffi # Date 1305562775 -7200 # Node ID d43d6e4b9dc82a06a033f48f2b7485992ced551b # Parent ed935f763cc81dd1d777966bb05c9e3cdf65113b room user joining/leaving diff -r ed935f763cc8 -r d43d6e4b9dc8 browser_side/panels.py --- a/browser_side/panels.py Mon May 16 03:10:11 2011 +0200 +++ b/browser_side/panels.py Mon May 16 18:19:35 2011 +0200 @@ -423,32 +423,42 @@ def __init__(self, nick): self.nick = nick - HTML.__init__(self, "
%s
" % html_sanitize(nick)) + HTML.__init__(self, "
%s
" % html_sanitize(nick)) + + def __str__(self): + return nick class OccupantsList(AbsolutePanel): """Panel user to show occupants of a room""" def __init__(self): AbsolutePanel.__init__(self) + self.occupants_list = {} self.setStyleName('occupantsList') - self.occupants = set() - #self.setHeight('100%') def addOccupant(self, nick): - _occupant = Occupant(nick) - print "addOccupant: nick", nick - print _occupant - self.occupants.add(_occupant) - self.add(_occupant) + _occupant = Occupant(nick) + self.occupants_list[nick] = _occupant + self.add(_occupant) -class ChatPanel(DropCell, ClickHandler, SimplePanel): + def removeOccupant(self, nick): + try: + self.remove(self.occupants_list[nick]) + except KeyError: + print "ERROR: trying to remove an unexisting nick" + + def clear(self): + self.occupants_list.clear() + AbsolutePanel.clear(self) + +class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): def __init__(self, host, target, type='one2one'): """Panel used for conversation (one 2 one or group chat) @param host: SatWebFrontend instance @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) @param type: one2one for simple conversation, group for MUC""" - SimplePanel.__init__(self) + ScrollPanelWrapper.__init__(self) DropCell.__init__(self) ClickHandler.__init__(self) self.vpanel = VerticalPanel() @@ -495,9 +505,20 @@ def setPresents(self, nicks): """Set the users presents in this room @param occupants: list of nicks (string)""" + self.occupants_list.clear() for nick in nicks: self.occupants_list.addOccupant(nick) + def userJoined(self, nick, data): + print "userJoined:", nick, data + self.occupants_list.addOccupant(nick) + self.printInfo("=> %s has joined the room" % nick) + + def userLeft(self, nick, data): + print "userLeft:", nick, data + self.occupants_list.removeOccupant(nick) + self.printInfo("<= %s has left the room" % nick) + def historyPrint(self, size=20): """Print the initial history""" def getHistoryCB(history): @@ -506,15 +527,32 @@ for stamp in stamps: self.printMessage(history[stamp][0], history[stamp][1], stamp) self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20) - + + def printInfo(self, msg, type='normal'): + """Print general info + @param msg: message to print + @type: one of: + normal: general info like "toto has joined the room" + me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" + """ + _wid = Label(msg) + if type == 'normal': + _wid.setStyleName('chatTextInfo') + elif type == 'me': + _wid.setStyleName('chatTextMe') + else: + _wid.setStyleName('chatTextInfo') + self.content.add(_wid) + + def printMessage(self, from_jid, msg, timestamp=None): """Print message in chat window. Must be implemented by child class""" _jid=JID(from_jid) nick = _jid.node if self.type=='one2one' else _jid.resource mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user - """if msg.startswith('/me '): + if msg.startswith('/me '): self.printInfo('* %s %s' % (nick, msg[4:]),type='me') - return""" + return self.content.add(ChatText(timestamp, nick, mymess, msg)) self.content_scroll.scrollToBottom() diff -r ed935f763cc8 -r d43d6e4b9dc8 libervia.py --- a/libervia.py Mon May 16 03:10:11 2011 +0200 +++ b/libervia.py Mon May 16 18:19:35 2011 +0200 @@ -222,12 +222,15 @@ chat_panel.setPresents(room_nicks) chat_panel.historyPrint() - def _roomUserJoinedCb(room_id, room_service, room_nicks, user_nick): - pass + def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): + for panel in self.mpanels + self.other_panels: + if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): + panel.userJoined(user_nick, user_data) - def _roomUserLeftCb(room_id, room_service, room_nicks, user_nick): - pass - + def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): + for panel in self.mpanels + self.other_panels: + if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): + panel.userLeft(user_nick, user_data) def _getPresenceStatusCB(self, presence_data): for entity in presence_data: diff -r ed935f763cc8 -r d43d6e4b9dc8 libervia.tac --- a/libervia.tac Mon May 16 03:10:11 2011 +0200 +++ b/libervia.tac Mon May 16 18:19:35 2011 +0200 @@ -344,7 +344,7 @@ sys.exit(1) self.bridge.register("connected", self.signal_handler.connected) self.bridge.register("connectionError", self.signal_handler.connectionError) - for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined']: + for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft']: self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) root.putChild('json_signal_api', self.signal_handler) root.putChild('json_api', MethodHandler(self)) diff -r ed935f763cc8 -r d43d6e4b9dc8 public/libervia.css --- a/public/libervia.css Mon May 16 03:10:11 2011 +0200 +++ b/public/libervia.css Mon May 16 18:19:35 2011 +0200 @@ -252,8 +252,17 @@ /* font-size: smaller; */ } +.chatTextInfo { + font-weight: bold; +} + +.chatTextInfo { + font-style: italic; +} + .chatArea { height:100%; + width:100%; } .chat_text_timestamp {