From ec4bf4c1d972fb5503178eb1a4ec3c6364e64e12 Mon Sep 17 00:00:00 2001 From: Diogo Date: Fri, 1 Nov 2024 23:48:54 +0000 Subject: [PATCH] new apis and types --- apps/ios/Shared/Model/SimpleXAPI.swift | 4 ++-- apps/ios/SimpleXChat/API.swift | 6 ++++-- apps/ios/SimpleXChat/APITypes.swift | 8 ++++++-- apps/ios/SimpleXChat/ChatTypes.swift | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 9297aa7898..4d21b1e0eb 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -322,13 +322,13 @@ let loadItemsPerPage = 50 func apiGetChat(type: ChatType, id: Int64, search: String = "") async throws -> Chat { let r = await chatSendCmd(.apiGetChat(type: type, id: id, pagination: .last(count: loadItemsPerPage), search: search)) - if case let .apiChat(_, chat) = r { return Chat.init(chat) } + if case let .apiChat(_, chat, _) = r { return Chat.init(chat) } throw r } func apiGetChatItems(type: ChatType, id: Int64, pagination: ChatPagination, search: String = "") async throws -> [ChatItem] { let r = await chatSendCmd(.apiGetChat(type: type, id: id, pagination: pagination, search: search)) - if case let .apiChat(_, chat) = r { return chat.chatItems } + if case let .apiChat(_, chat, _) = r { return chat.chatItems } throw r } diff --git a/apps/ios/SimpleXChat/API.swift b/apps/ios/SimpleXChat/API.swift index 987f7f3d41..0cdcd7a30f 100644 --- a/apps/ios/SimpleXChat/API.swift +++ b/apps/ios/SimpleXChat/API.swift @@ -213,8 +213,10 @@ public func chatResponse(_ s: String) -> ChatResponse { if let jApiChat = jResp["apiChat"] as? NSDictionary, let user: UserRef = try? decodeObject(jApiChat["user"] as Any), let jChat = jApiChat["chat"] as? NSDictionary, - let chat = try? parseChatData(jChat) { - return .apiChat(user: user, chat: chat) + let jSection = jApiChat["section"] as? String, + let chat = try? parseChatData(jChat), + let section = ChatLandingSection(rawValue: jSection) { + return .apiChat(user: user, chat: chat, section: section) } } else if type == "chatCmdError" { if let jError = jResp["chatCmdError"] as? NSDictionary { diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index 3c9b91fa0b..eb3ce9b1e7 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -546,7 +546,7 @@ public enum ChatResponse: Decodable, Error { case chatStopped case chatSuspended case apiChats(user: UserRef, chats: [ChatData]) - case apiChat(user: UserRef, chat: ChatData) + case apiChat(user: UserRef, chat: ChatData, section: ChatLandingSection) case chatItemInfo(user: UserRef, chatItem: AChatItem, chatItemInfo: ChatItemInfo) case userProtoServers(user: UserRef, servers: UserProtoServers) case serverTestResult(user: UserRef, testServer: String, testFailure: ProtocolTestFailure?) @@ -888,7 +888,7 @@ public enum ChatResponse: Decodable, Error { case .chatStopped: return noDetails case .chatSuspended: return noDetails case let .apiChats(u, chats): return withUser(u, String(describing: chats)) - case let .apiChat(u, chat): return withUser(u, String(describing: chat)) + case let .apiChat(u, chat, section): return withUser(u, "section: \(String(describing: section))\n\(String(describing: chat))") case let .chatItemInfo(u, chatItem, chatItemInfo): return withUser(u, "chatItem: \(String(describing: chatItem))\nchatItemInfo: \(String(describing: chatItemInfo))") case let .userProtoServers(u, servers): return withUser(u, "servers: \(String(describing: servers))") case let .serverTestResult(u, server, testFailure): return withUser(u, "server: \(server)\nresult: \(String(describing: testFailure))") @@ -1133,12 +1133,16 @@ public enum ChatPagination { case last(count: Int) case after(chatItemId: Int64, count: Int) case before(chatItemId: Int64, count: Int) + case around(chatItemId: Int64, count: Int) + case initial(count: Int) var cmdString: String { switch self { case let .last(count): return "count=\(count)" case let .after(chatItemId, count): return "after=\(chatItemId) count=\(count)" case let .before(chatItemId, count): return "before=\(chatItemId) count=\(count)" + case let .around(chatItemId, count): return "around=\(chatItemId) count=\(count)" + case let .initial(count): return "initial=\(count)" } } } diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 1bd5673f01..29aa045a11 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -1619,6 +1619,11 @@ public struct Contact: Identifiable, Decodable, NamedChat, Hashable { ) } +public enum ChatLandingSection: String, Decodable, Hashable { + case latest = "latest" + case unread = "unread" +} + public enum ContactStatus: String, Decodable, Hashable { case active = "active" case deleted = "deleted"