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

Load last contacts/messages ordered by timestamp

parent 5fad8a2d
...@@ -401,7 +401,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -401,7 +401,7 @@ class MessageHistory(object, metaclass=Singleton):
# print('-- Loading messages') # print('-- Loading messages')
notification_center = NotificationCenter() notification_center = NotificationCenter()
try: try:
result = Message.selectBy(remote_uri=uri)[-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
...@@ -412,7 +412,7 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -412,7 +412,7 @@ class MessageHistory(object, metaclass=Singleton):
def get_last_contacts(self, number=5): def get_last_contacts(self, number=5):
# print(f'-- Getting last {number} contacts wtih messages') # print(f'-- Getting last {number} contacts wtih messages')
query = f'select distinct(remote_uri) from messages order by id 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()
try: try:
result = self.db.queryAll(query) result = self.db.queryAll(query)
......
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