def broadcast(self, msg, sender=None, exclude=None): if exclude is None: exclude = [] if sender is not None: _sender = sender.db_tuple.name else: _sender = None for user in self.broadcast_to.copy(): if user not in exclude: reactor.callFromThread(user.conn.send, ClientChatCommand.broadcast(_sender, self.id, msg))
def callIntoChat(self, sender, chat_id, sender_callback): """another user may use this to request a chat with this user sender: ConnectedUser instance that wants to chat chat_id: Chat instance created by the sender sender_callback: function to be called when a response is obtained from the user, accepts one parameter 'accepted' as True or False""" def response_callback(response): """expects response to be a dict with a key 'accepted' and boolean value""" if response['accepted']: self.enterChat(sender.getChatById(chat_id)) sender_callback(response['accepted']) command = ClientChatCommand.call_into(sender.db_tuple.name, chat_id) self.conn.addResponseCallback(response_callback, command['trans']) self.conn.send(command)