class Messenger(object): def __init__(self): username, login = get_login('login') self.client = Client(username, login) self.user_map = {} self._initialize_contacts() self._initialize_messages() def _initialize_contacts(self): self.user_map[self.client.uid] = self.client.fetchUserInfo(self.client.uid)[self.client.uid].name for user in self.client.fetchAllUsers(): self.user_map[user.uid] = user.name def _initialize_messages(self, limit=1000): try: print("Input the user you want to message:") to_search = input() if to_search == "exit": print("Exiting...") return users = self.client.searchForUsers(to_search) + self.client.searchForGroups(to_search) users = users for i in range(0, len(users)): print(i, ":", users[i].name) user = users[int(input("Please specify which chat you'd like to participate in: "))] self.messages = self.client.fetchThreadMessages(thread_id=user.uid, limit=limit)[::-1] thread = self.client.fetchThreadInfo(user.uid) self.chat = Chat(user.name, user.uid, self.messages, thread, self.client.uid, self.user_map[self.client.uid], self.user_map, find_answers=True) except IndexError : traceback.print_exc() except ValueError : traceback.print_exc() def run_loop(self, limit=150): print("Wrong literal, try again.") while True: self._initialize_messages(limit=limit) def get_messages(self): return self.chat.get_messages()
'private_key': user_key_pair['private_key'], 'public_key': user_key_pair['public_key'] } # save a Private Key with information about Virgil Card # to the file on the disk. save_virgil_pass(VIRGIL_PRIVATE_KEY_PATH, user_pass) # create and join to the chat channel DEMO. chat_channel = Chat(CHAT_API_URL, 'DEMO', user_pass['identity']) # get and display all previous messages from channel history. messages = chat_channel.get_messages(None) if messages: print("Messages({})".format(len(messages))) for chat_message in messages: # verify the message and decrypt it in case if massage # signature is valid. message_text = decrypt_then_verify_message(chat_message, user_pass['card_id'], user_pass['private_key'], USER_PRIVATE_KEY_PASSWORD) print('{0}: {1}'.format(chat_message['sender_identifier'], message_text))