def execute(self, cmd: Command, msg: ReliableMessage) -> Optional[Content]: assert isinstance(cmd, SearchCommand), 'command error: %s' % cmd # message message = cmd.get('message') print('online users response: %s' % message) # users users = cmd.get('users') if users is not None: print(' users:', json_encode(users)) return None
def execute(self, cmd: Command, msg: ReliableMessage) -> Optional[Content]: assert isinstance(cmd, Command), 'command error: %s' % cmd # submit device token for APNs token = cmd.get('device_token') if token is not None: self.database.save_device_token(token=token, identifier=msg.sender) return ReceiptCommand(message='Token received')
def execute(self, cmd: Command, msg: ReliableMessage) -> Optional[Content]: assert isinstance(cmd, SearchCommand), 'command error: %s' % cmd # keywords keywords = cmd.get('keywords') if keywords is None: return TextContent(text='Search command error') keywords = keywords.split(' ') # search in database results = self.database.search(keywords=keywords) users = list(results.keys()) return SearchCommand(users=users, results=results)
def execute(self, cmd: Command, msg: ReliableMessage) -> Optional[Content]: assert isinstance(cmd, DocumentCommand), 'command error: %s' % cmd identifier = cmd.identifier doc = cmd.document if doc is None: doc_type = cmd.get('doc_type') if doc_type is None: doc_type = '*' return self.__get(identifier=identifier, doc_type=doc_type) else: # check meta meta = cmd.meta return self.__put(identifier=identifier, meta=meta, document=doc)
def __process_old_report(self, cmd: Command, sender: ID) -> Optional[Content]: # compatible with v1.0 state = cmd.get('state') if state is not None: session = self.messenger.current_session(identifier=sender) if 'background' == state: session.active = False elif 'foreground' == state: # welcome back! self.receptionist.add_guest(identifier=session.identifier) session.active = True else: session.active = True return ReceiptCommand.new(message='Client state received')