From 7a77b56560e6d250fabdfb6d75e45c583c65b744 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 28 Jun 2016 13:51:11 +0300 Subject: [PATCH] bug fixes with messages saving --- src/friend.py | 14 +++++--------- src/profile.py | 7 +++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/friend.py b/src/friend.py index 67d20dc..3dd5b0f 100644 --- a/src/friend.py +++ b/src/friend.py @@ -70,10 +70,8 @@ class Friend(contact.Contact): Get data to save in db :return: list of unsaved messages or [] """ - if hasattr(self, '_message_getter'): - del self._message_getter messages = list(filter(lambda x: x.get_type() <= 1, self._corr)) - return list(map(lambda x: x.get_data(), list(messages[-self._unsaved_messages:]))) if self._unsaved_messages else [] + return list(map(lambda x: x.get_data(), messages[-self._unsaved_messages:])) if self._unsaved_messages else [] def get_corr(self): return self._corr[:] @@ -104,15 +102,13 @@ class Friend(contact.Contact): """ :return list of unsent messages for saving """ - if self._unsaved_messages: - messages = filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr[-self._unsaved_messages:]) - return list(map(lambda x: x.get_data(), messages)) - else: - return [] + messages = filter(lambda x: x.get_type() <= 1 and x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr) + return list(map(lambda x: x.get_data(), messages)) def delete_message(self, time): elem = list(filter(lambda x: type(x) is TextMessage and x.get_data()[2] == time, self._corr))[0] - if elem in self.get_corr_for_saving(): + tmp = list(filter(lambda x: x.get_type() <= 1, self._corr)) + if elem in tmp[-self._unsaved_messages:]: self._unsaved_messages -= 1 self._corr.remove(elem) diff --git a/src/profile.py b/src/profile.py index 5db1cb5..0e5a0f9 100644 --- a/src/profile.py +++ b/src/profile.py @@ -422,12 +422,13 @@ class Profile(contact.Contact, Singleton): if hasattr(self, '_history'): if s['save_history']: for friend in self._friends: + if not self._history.friend_exists_in_db(friend.tox_id): + self._history.add_friend_to_db(friend.tox_id) if not s['save_unsent_only']: messages = friend.get_corr_for_saving() else: messages = friend.get_unsent_messages_for_saving() - if not self._history.friend_exists_in_db(friend.tox_id): - self._history.add_friend_to_db(friend.tox_id) + self._history.delete_messages(friend.tox_id) self._history.save_messages_to_db(friend.tox_id, messages) unsent_messages = friend.get_unsent_messages() unsent_time = unsent_messages[0].get_data()[2] if len(unsent_messages) else time.time() + 1 @@ -772,6 +773,8 @@ class Profile(contact.Contact, Singleton): if hasattr(self, '_call'): self._call.stop() del self._call + for i in range(len(self._friends)): + del self._friends[0] # ----------------------------------------------------------------------------------------------------------------- # File transfers support