iOS: accept images in NSE if enabled, reorder chats when coming from background (#800)

* ios: automatically accept images in NSE, if enabled in settings

* remove unnecessary TODOs

* reorder chat when coming from background
This commit is contained in:
Evgeny Poberezkin
2022-07-10 14:28:00 +01:00
committed by GitHub
parent 4408495cfb
commit f16d8842b2
8 changed files with 62 additions and 21 deletions
+16 -7
View File
@@ -58,9 +58,9 @@ final class ChatModel: ObservableObject {
chats.firstIndex(where: { $0.id == id })
}
func addChat(_ chat: Chat) {
func addChat(_ chat: Chat, at position: Int = 0) {
withAnimation {
chats.insert(chat, at: 0)
chats.insert(chat, at: position)
}
}
@@ -104,13 +104,22 @@ final class ChatModel: ObservableObject {
}
func updateChats(with newChats: [ChatData]) {
for c in newChats {
if let chat = getChat(c.id) {
for i in 0..<newChats.count {
let c = newChats[i]
if let j = getChatIndex(c.id) {
let chat = chats[j]
chat.chatInfo = c.chatInfo
chat.chatItems = c.chatItems
chat.chatStats = c.chatStats
if i != j {
if chatId != c.chatInfo.id {
popChat_(j, to: i)
} else if i == 0 {
chatToTop = c.chatInfo.id
}
}
} else {
addChat(Chat(c))
addChat(Chat(c), at: i)
}
}
}
@@ -247,9 +256,9 @@ final class ChatModel: ObservableObject {
}
}
private func popChat_(_ i: Int) {
private func popChat_(_ i: Int, to position: Int = 0) {
let chat = chats.remove(at: i)
chats.insert(chat, at: 0)
chats.insert(chat, at: position)
}
func removeChat(_ id: String) {