Commit a438cd25 authored by Tijmen de Mes's avatar Tijmen de Mes

Added log messages in storage

parent 214c447d
...@@ -20,8 +20,9 @@ from sipsimple.threading import run_in_thread ...@@ -20,8 +20,9 @@ from sipsimple.threading import run_in_thread
from sipsimple.util import ISOTimestamp from sipsimple.util import ISOTimestamp
from blink.configuration.settings import BlinkSettings from blink.configuration.settings import BlinkSettings
from blink.resources import ApplicationData, Resources from blink.logging import MessagingTrace as log
from blink.messages import BlinkMessage from blink.messages import BlinkMessage
from blink.resources import ApplicationData, Resources
from blink.util import run_in_gui_thread from blink.util import run_in_gui_thread
import traceback import traceback
...@@ -310,7 +311,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -310,7 +311,7 @@ class MessageHistory(object, metaclass=Singleton):
if message.content.startswith('?OTRv'): if message.content.startswith('?OTRv'):
return return
print(f"-- Adding {message.direction} history message to storage: {message.id} {state} {remote_uri}") log.info(f"== Adding {message.direction} history message to storage: {message.id} {state} {remote_uri}")
match = cls.phone_number_re.match(remote_uri) match = cls.phone_number_re.match(remote_uri)
if match: if match:
...@@ -363,7 +364,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -363,7 +364,7 @@ class MessageHistory(object, metaclass=Singleton):
if message.content.startswith('?OTRv'): if message.content.startswith('?OTRv'):
return return
# print(f"-- Adding message to storage: {message.id}") log.info(f"== Adding message to storage: {message.id}")
user = session.uri.user user = session.uri.user
domain = session.uri.host domain = session.uri.host
...@@ -438,7 +439,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -438,7 +439,7 @@ class MessageHistory(object, metaclass=Singleton):
return return
if message.state != 'displayed' and message.state != state: if message.state != 'displayed' and message.state != state:
# print(f'-- Updating {message.direction} {id} {message.state} -> {state}') log.info(f'== Updating {message.direction} {id} {message.state} -> {state}')
message.state = state message.state = state
@run_in_thread('db') @run_in_thread('db')
...@@ -455,24 +456,24 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -455,24 +456,24 @@ class MessageHistory(object, metaclass=Singleton):
else: else:
encryption_type = str([f'{message_info.encryption}']) encryption_type = str([f'{message_info.encryption}'])
if db_message.encryption_type != encryption_type: if db_message.encryption_type != encryption_type:
# print(f'-- Updating {message.id} encryption {db_message.encryption_type} -> {encryption_type}') log.debug(f'== Updating {message.id} encryption {db_message.encryption_type} -> {encryption_type}')
db_message.encryption_type = encryption_type db_message.encryption_type = encryption_type
@run_in_thread('db') @run_in_thread('db')
def load(self, uri, session): def load(self, uri, session):
# print('-- Loading messages') log.debug(f'== Loading messages for {uri}')
notification_center = NotificationCenter() notification_center = NotificationCenter()
try: try:
result = Message.selectBy(remote_uri=uri).orderBy('timestamp')[-100:] result = Message.selectBy(remote_uri=uri).orderBy('timestamp')[-100:]
except Exception as e: except Exception as e:
notification_center.post_notification('BlinkMessageHistoryLoadDidFail', sender=session, data=NotificationData(uri=uri)) notification_center.post_notification('BlinkMessageHistoryLoadDidFail', sender=session, data=NotificationData(uri=uri))
return return
# print(f"-- Messages loaded: {len(list(result))}") log.debug(f"== Messages loaded for {uri}: {len(list(result))}")
notification_center.post_notification('BlinkMessageHistoryLoadDidSucceed', sender=session, data=NotificationData(messages=list(result), uri=uri)) notification_center.post_notification('BlinkMessageHistoryLoadDidSucceed', sender=session, data=NotificationData(messages=list(result), uri=uri))
@run_in_thread('db') @run_in_thread('db')
def get_last_contacts(self, number=5): def get_last_contacts(self, number=5):
# print(f'-- Getting last {number} contacts wtih messages') log.debug(f'== Getting last {number} contacts wtih messages')
query = f'select remote_uri, max(timestamp) from messages group by remote_uri order by timestamp desc limit {Message.sqlrepr(number)}' query = f'select remote_uri, max(timestamp) from messages group by remote_uri order by timestamp desc limit {Message.sqlrepr(number)}'
notification_center = NotificationCenter() notification_center = NotificationCenter()
...@@ -481,7 +482,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -481,7 +482,7 @@ class MessageHistory(object, metaclass=Singleton):
except Exception as e: except Exception as e:
return return
# print(f"-- Contacts fetched: {len(list(result))}") log.debug(f"== Contacts fetched: {len(list(result))}")
result = [' '.join(item) for item in result] result = [' '.join(item) for item in result]
notification_center.post_notification('BlinkMessageHistoryLastContactsDidSucceed', data=NotificationData(contacts=list(result))) notification_center.post_notification('BlinkMessageHistoryLastContactsDidSucceed', data=NotificationData(contacts=list(result)))
...@@ -491,14 +492,17 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -491,14 +492,17 @@ class MessageHistory(object, metaclass=Singleton):
@run_in_thread('db') @run_in_thread('db')
def remove_contact_messages(self, account, contact): def remove_contact_messages(self, account, contact):
log.info(f'== Removing conversation between {account.id} <-> {contact}')
Message.deleteBy(remote_uri=contact, account_id=str(account.id)) Message.deleteBy(remote_uri=contact, account_id=str(account.id))
@run_in_thread('db') @run_in_thread('db')
def remove_message(self, id): def remove_message(self, id):
log.debug(f'== Trying to removing message: {id}')
try: try:
result = Message.selectBy(message_id=id)[0] result = Message.selectBy(message_id=id)[0]
except IndexError: except IndexError:
return return
log.info(f'== Removing message: {id}')
result.destroySelf() result.destroySelf()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment