ios: fix updating chats when exiting background (#772)

This commit is contained in:
Evgeny Poberezkin
2022-07-02 17:18:45 +01:00
committed by GitHub
parent 60642317d0
commit e4c6d210c6
8 changed files with 49 additions and 30 deletions
+16 -3
View File
@@ -179,9 +179,9 @@ func apiDeleteStorage() async throws {
try await sendCommandOkResp(.apiDeleteStorage)
}
func apiGetChats() throws -> [Chat] {
func apiGetChats() throws -> [ChatData] {
let r = chatSendCmdSync(.apiGetChats)
if case let .apiChats(chats) = r { return chats.map { Chat.init($0) } }
if case let .apiChats(chats) = r { return chats }
throw r
}
@@ -191,6 +191,18 @@ func apiGetChat(type: ChatType, id: Int64) throws -> Chat {
throw r
}
func loadChat(chat: Chat) {
do {
let cInfo = chat.chatInfo
let chat = try apiGetChat(type: cInfo.chatType, id: cInfo.apiId)
let m = ChatModel.shared
m.updateChatInfo(chat.chatInfo)
m.chatItems = chat.chatItems
} catch let error {
logger.error("loadChat error: \(responseError(error))")
}
}
func apiSendMessage(type: ChatType, id: Int64, file: String?, quotedItemId: Int64?, msg: MsgContent) async throws -> ChatItem {
let chatModel = ChatModel.shared
let cmd: ChatCommand = .apiSendMessage(type: type, id: id, file: file, quotedItemId: quotedItemId, msg: msg)
@@ -524,7 +536,8 @@ func startChat() throws {
if justStarted {
m.userAddress = try apiGetUserAddress()
m.userSMPServers = try getUserSMPServers()
m.chats = try apiGetChats()
let chats = try apiGetChats()
m.chats = chats.map { Chat.init($0) }
(m.savedToken, m.tokenStatus, m.notificationMode) = try apiGetNtfToken()
if let token = m.deviceToken {
registerToken(token: token)