fixes
This commit is contained in:
@@ -124,14 +124,45 @@ impl TdClient {
|
||||
chat.last_message_date = last_message_date;
|
||||
}
|
||||
|
||||
// Пересортируем после обновления
|
||||
self.chats.sort_by(|a, b| b.last_message_date.cmp(&a.last_message_date));
|
||||
// Обновляем позиции если они пришли
|
||||
for pos in &update.positions {
|
||||
if matches!(pos.list, ChatList::Main) {
|
||||
if let Some(chat) = self.chats.iter_mut().find(|c| c.id == chat_id) {
|
||||
chat.order = pos.order;
|
||||
chat.is_pinned = pos.is_pinned;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Пересортируем по order
|
||||
self.chats.sort_by(|a, b| b.order.cmp(&a.order));
|
||||
}
|
||||
Update::ChatReadInbox(update) => {
|
||||
if let Some(chat) = self.chats.iter_mut().find(|c| c.id == update.chat_id) {
|
||||
chat.unread_count = update.unread_count;
|
||||
}
|
||||
}
|
||||
Update::ChatPosition(update) => {
|
||||
// Обновляем позицию чата или удаляем его из списка
|
||||
match &update.position.list {
|
||||
ChatList::Main => {
|
||||
if update.position.order == 0 {
|
||||
// Чат больше не в Main (перемещён в архив и т.д.)
|
||||
self.chats.retain(|c| c.id != update.chat_id);
|
||||
} else if let Some(chat) = self.chats.iter_mut().find(|c| c.id == update.chat_id) {
|
||||
// Обновляем позицию существующего чата
|
||||
chat.order = update.position.order;
|
||||
chat.is_pinned = update.position.is_pinned;
|
||||
}
|
||||
// Пересортируем по order
|
||||
self.chats.sort_by(|a, b| b.order.cmp(&a.order));
|
||||
}
|
||||
ChatList::Archive | ChatList::Folder(_) => {
|
||||
// Если чат добавляется в архив или папку, ничего не делаем
|
||||
// (он уже должен быть удалён из Main)
|
||||
}
|
||||
}
|
||||
}
|
||||
Update::NewMessage(_new_msg) => {
|
||||
// Новые сообщения обрабатываются при обновлении UI
|
||||
}
|
||||
@@ -152,6 +183,24 @@ impl TdClient {
|
||||
}
|
||||
|
||||
fn add_or_update_chat(&mut self, td_chat: &TdChat) {
|
||||
// Проверяем, есть ли у чата позиция в ChatList::Main
|
||||
// Если нет - не добавляем (это архивные чаты или связанные группы)
|
||||
let main_position = td_chat.positions.iter().find(|pos| {
|
||||
matches!(pos.list, ChatList::Main)
|
||||
});
|
||||
|
||||
// Если чат не в Main списке - удаляем его если был, и выходим
|
||||
let Some(position) = main_position else {
|
||||
self.chats.retain(|c| c.id != td_chat.id);
|
||||
return;
|
||||
};
|
||||
|
||||
// Если order == 0, чат не должен отображаться
|
||||
if position.order == 0 {
|
||||
self.chats.retain(|c| c.id != td_chat.id);
|
||||
return;
|
||||
}
|
||||
|
||||
let (last_message, last_message_date) = td_chat
|
||||
.last_message
|
||||
.as_ref()
|
||||
@@ -164,8 +213,8 @@ impl TdClient {
|
||||
last_message,
|
||||
last_message_date,
|
||||
unread_count: td_chat.unread_count,
|
||||
is_pinned: false,
|
||||
order: 0,
|
||||
is_pinned: position.is_pinned,
|
||||
order: position.order,
|
||||
};
|
||||
|
||||
if let Some(existing) = self.chats.iter_mut().find(|c| c.id == td_chat.id) {
|
||||
@@ -173,12 +222,14 @@ impl TdClient {
|
||||
existing.last_message = chat_info.last_message;
|
||||
existing.last_message_date = chat_info.last_message_date;
|
||||
existing.unread_count = chat_info.unread_count;
|
||||
existing.is_pinned = chat_info.is_pinned;
|
||||
existing.order = chat_info.order;
|
||||
} else {
|
||||
self.chats.push(chat_info);
|
||||
}
|
||||
|
||||
// Сортируем чаты по дате последнего сообщения (новые сверху)
|
||||
self.chats.sort_by(|a, b| b.last_message_date.cmp(&a.last_message_date));
|
||||
// Сортируем чаты по order (TDLib order учитывает pinned и время)
|
||||
self.chats.sort_by(|a, b| b.order.cmp(&a.order));
|
||||
}
|
||||
|
||||
fn convert_message(&self, message: &TdMessage) -> MessageInfo {
|
||||
|
||||
Reference in New Issue
Block a user