mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 11:53:08 +00:00
Sort chats when new message comes
This commit is contained in:
parent
3ee7a60948
commit
da05614b08
2 changed files with 5 additions and 4 deletions
|
@ -130,7 +130,8 @@ class Controller:
|
|||
|
||||
def refresh_chats(self):
|
||||
with self.lock:
|
||||
# using lock here, because model.get_chats is vulnerable to race conditions
|
||||
# using lock here, because refresh_chats is used from another
|
||||
# thread by tdlib python wrapper
|
||||
self.view.draw_chats(
|
||||
self.model.current_chat,
|
||||
self.model.get_chats(limit=self.view.chats.h)
|
||||
|
|
|
@ -102,7 +102,7 @@ class ChatModel:
|
|||
def fetch_chats(self, offset=0, limit=10):
|
||||
if offset + limit < len(self.chats):
|
||||
# return data from cache
|
||||
return self.chats[offset:limit]
|
||||
return sorted(self.chats, key=lambda it: it['last_message']['date'], reverse=True)[offset:limit]
|
||||
|
||||
previous_chats_num = len(self.chat_ids)
|
||||
|
||||
|
@ -111,13 +111,13 @@ class ChatModel:
|
|||
limit=len(self.chats) + limit
|
||||
)
|
||||
if len(self.chat_ids) == previous_chats_num:
|
||||
return self.chats[offset:limit]
|
||||
return sorted(self.chats, key=lambda it: it['last_message']['date'], reverse=True)[offset:limit]
|
||||
|
||||
for chat_id in self.chat_ids:
|
||||
chat = self.fetch_chat(chat_id)
|
||||
self.chats.append(chat)
|
||||
|
||||
return self.chats[offset:limit]
|
||||
return sorted(self.chats, key=lambda it: it['last_message']['date'], reverse=True)[offset:limit]
|
||||
|
||||
def fetch_chat_ids(self, offset=0, limit=10):
|
||||
if len(self.chats):
|
||||
|
|
Loading…
Reference in a new issue