bug fixes with messages saving

This commit is contained in:
ingvar1995 2016-06-28 13:51:11 +03:00
parent b982df70ea
commit 7a77b56560
2 changed files with 10 additions and 11 deletions

View File

@ -70,10 +70,8 @@ class Friend(contact.Contact):
Get data to save in db Get data to save in db
:return: list of unsaved messages or [] :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)) 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): def get_corr(self):
return self._corr[:] return self._corr[:]
@ -104,15 +102,13 @@ class Friend(contact.Contact):
""" """
:return list of unsent messages for saving :return list of unsent messages for saving
""" """
if self._unsaved_messages: messages = filter(lambda x: x.get_type() <= 1 and x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr)
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))
return list(map(lambda x: x.get_data(), messages))
else:
return []
def delete_message(self, time): def delete_message(self, time):
elem = list(filter(lambda x: type(x) is TextMessage and x.get_data()[2] == time, self._corr))[0] 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._unsaved_messages -= 1
self._corr.remove(elem) self._corr.remove(elem)

View File

@ -422,12 +422,13 @@ class Profile(contact.Contact, Singleton):
if hasattr(self, '_history'): if hasattr(self, '_history'):
if s['save_history']: if s['save_history']:
for friend in self._friends: 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']: if not s['save_unsent_only']:
messages = friend.get_corr_for_saving() messages = friend.get_corr_for_saving()
else: else:
messages = friend.get_unsent_messages_for_saving() messages = friend.get_unsent_messages_for_saving()
if not self._history.friend_exists_in_db(friend.tox_id): self._history.delete_messages(friend.tox_id)
self._history.add_friend_to_db(friend.tox_id)
self._history.save_messages_to_db(friend.tox_id, messages) self._history.save_messages_to_db(friend.tox_id, messages)
unsent_messages = friend.get_unsent_messages() unsent_messages = friend.get_unsent_messages()
unsent_time = unsent_messages[0].get_data()[2] if len(unsent_messages) else time.time() + 1 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'): if hasattr(self, '_call'):
self._call.stop() self._call.stop()
del self._call del self._call
for i in range(len(self._friends)):
del self._friends[0]
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# File transfers support # File transfers support