fixes, gc loading on start
This commit is contained in:
		
							parent
							
								
									3602b3433e
								
							
						
					
					
						commit
						bb4e80ca09
					
				
					 3 changed files with 55 additions and 23 deletions
				
			
		|  | @ -102,6 +102,14 @@ class Contact(basecontact.BaseContact): | |||
|             self._unsaved_messages -= 1 | ||||
|         self._corr.remove(elem) | ||||
| 
 | ||||
|     def delete_old_messages(self): | ||||
|         old = filter(lambda x: x.get_type() in (2, 3) and (x.get_status() >= 2 or x.get_status() is None), | ||||
|                      self._corr[:-SAVE_MESSAGES]) | ||||
|         old = list(old) | ||||
|         l = max(len(self._corr) - SAVE_MESSAGES, 0) - len(old) | ||||
|         self._unsaved_messages -= l | ||||
|         self._corr = old + self._corr[-SAVE_MESSAGES:] | ||||
| 
 | ||||
|     def mark_as_sent(self): | ||||
|         try: | ||||
|             message = list(filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr))[0] | ||||
|  |  | |||
|  | @ -558,14 +558,14 @@ class MainWindow(QtGui.QMainWindow): | |||
|         auto = QtGui.QApplication.translate("MainWindow", 'Disallow auto accept', None, QtGui.QApplication.UnicodeUTF8) if allowed else QtGui.QApplication.translate("MainWindow", 'Allow auto accept', None, QtGui.QApplication.UnicodeUTF8) | ||||
|         if item is not None: | ||||
|             self.listMenu = QtGui.QMenu() | ||||
|             if type(friend) is Friend:  # TODO: add `invite to gc` submenu | ||||
|             if type(friend) is Friend: | ||||
|                 arr = Profile.get_instance().get_all_gc() | ||||
|                 if arr: | ||||
|                     gc_menu = self.listMenu.addMenu(QtGui.QApplication.translate("MainWindow", 'Invite to group chat', None, QtGui.QApplication.UnicodeUTF8)) | ||||
|                     for gc in arr: | ||||
|                         item = gc.menu.addAction(gc_menu.name) | ||||
|                         item = gc_menu.addAction(gc.name) | ||||
|                         self.connect(item, QtCore.SIGNAL("triggered()"), | ||||
|                                      lambda: Profile.get_instance().invite_friend(gc.number), friend.number) | ||||
|                                      lambda: Profile.get_instance().invite_friend(gc.number, friend.number)) | ||||
| 
 | ||||
|                 set_alias_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Set alias', None, QtGui.QApplication.UnicodeUTF8)) | ||||
|                 clear_history_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Clear history', None, QtGui.QApplication.UnicodeUTF8)) | ||||
|  |  | |||
|  | @ -64,7 +64,24 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|             friend = Friend(i, message_getter, name, status_message, item, tox_id) | ||||
|             friend.set_alias(alias) | ||||
|             self._friends_and_gc.append(friend) | ||||
|         # TODO: list of gc | ||||
| 
 | ||||
|         l = self._tox.group_get_number_groups() | ||||
|         for i in range(l):  # creates list of group chats | ||||
|             tox_id = tox.group_get_chat_id(i) | ||||
|             try: | ||||
|                 alias = list(filter(lambda x: x[0] == tox_id, aliases))[0][1] | ||||
|             except: | ||||
|                 alias = '' | ||||
|             item = self.create_friend_item() | ||||
|             name = alias or tox.group_get_name(i) or tox_id | ||||
|             status_message = tox.group_get_topic(i) | ||||
|             if not self._history.friend_exists_in_db(tox_id): | ||||
|                 self._history.add_friend_to_db(tox_id) | ||||
|             message_getter = self._history.messages_getter(tox_id) | ||||
|             gc = GroupChat(self._tox, i, message_getter, name, status_message, item, tox_id) | ||||
|             gc.set_alias(alias) | ||||
|             self._friends_and_gc.append(gc) | ||||
| 
 | ||||
|         self.filtration(self._show_online) | ||||
| 
 | ||||
|     # ----------------------------------------------------------------------------------------------------------------- | ||||
|  | @ -394,13 +411,15 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|         :param is_group: is group chat message or not | ||||
|         :param peer_id: if gc - peer id | ||||
|         """ | ||||
|         if num == self.get_active_number() and is_group != self.is_active_a_friend():  # add message to list | ||||
|         t = time.time() | ||||
| 
 | ||||
|         if num == self.get_active_number() and is_group != self.is_active_a_friend():  # add message to list | ||||
|             if not is_group: | ||||
|                 self.create_message_item(message, t, MESSAGE_OWNER['FRIEND'], message_type) | ||||
|             self._messages.scrollToBottom() | ||||
|             self._friends_and_gc[self._active_friend_or_gc].append_message( | ||||
|                 TextMessage(message, MESSAGE_OWNER['FRIEND'], t, message_type)) | ||||
|             else: | ||||
|                 self.create_message_item(message, t, MESSAGE_OWNER['FRIEND'], message_type, True, | ||||
|                                          self._tox.group_peer_get_name(num, peer_id)) | ||||
|             self._messages.scrollToBottom() | ||||
|         if is_group: | ||||
|             friend_or_gc = self.get_gc_by_number(num) | ||||
|             friend_or_gc.append_message(GroupChatTextMessage(self._tox.group_peer_get_name(num, peer_id), | ||||
|  | @ -410,6 +429,7 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|             friend_or_gc = self.get_friend_by_number(num) | ||||
|             friend_or_gc.inc_messages() | ||||
|             friend_or_gc.append_message(TextMessage(message, MESSAGE_OWNER['FRIEND'], time.time(), message_type)) | ||||
| 
 | ||||
|         if not friend_or_gc.visibility: | ||||
|             self.update_filtration() | ||||
| 
 | ||||
|  | @ -674,10 +694,11 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|     def friend_public_key(self, num): | ||||
|         return self._friends_and_gc[num].tox_id | ||||
| 
 | ||||
|     def delete_friend_or_gc(self, num): | ||||
|     def delete_friend_or_gc(self, num, is_gc=False): | ||||
|         """ | ||||
|         Removes friend or gc from contact list | ||||
|         :param num: number of friend or gc in list | ||||
|         :param is_gc: is a group chat | ||||
|         """ | ||||
|         friend = self._friends_and_gc[num] | ||||
|         settings = Settings.get_instance() | ||||
|  | @ -692,6 +713,7 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|         self.clear_history(num) | ||||
|         if self._history.friend_exists_in_db(friend.tox_id): | ||||
|             self._history.delete_friend_from_db(friend.tox_id) | ||||
|         if not is_gc: | ||||
|             self._tox.friend_delete(friend.number) | ||||
|         del self._friends_and_gc[num] | ||||
|         self._screen.friends_list.takeItem(num) | ||||
|  | @ -1155,6 +1177,8 @@ class Profile(basecontact.BaseContact, Singleton): | |||
| 
 | ||||
|     def call_click(self, audio=True, video=False): | ||||
|         """User clicked audio button in main window""" | ||||
|         if not self.is_active_a_friend(): | ||||
|             return | ||||
|         num = self.get_active_number() | ||||
|         if num not in self._call and self.is_active_online():  # start call | ||||
|             self._call(num, audio, video) | ||||
|  | @ -1287,7 +1311,7 @@ class Profile(basecontact.BaseContact, Singleton): | |||
|     def leave_group(self, num, message=None): | ||||
|         number = self._friends_and_gc[num].number | ||||
|         self._tox.group_leave(number, message) | ||||
|         self.delete_friend_or_gc(num) | ||||
|         self.delete_friend_or_gc(num, False) | ||||
| 
 | ||||
| 
 | ||||
| def tox_factory(data=None, settings=None): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 ingvar1995
						ingvar1995