Expose leave chat to iOS bridge
This commit is contained in:
@@ -12,6 +12,7 @@ public protocol SessionBridge: Sendable {
|
||||
func loadHistory(chatId: Int64) async throws -> [Message]
|
||||
func searchMessages(chatId: Int64, query: String) async throws -> [Message]
|
||||
func openProfile(chatId: Int64) async throws -> Profile
|
||||
func leaveChat(chatId: Int64) async throws
|
||||
func sendMessage(chatId: Int64, text: String, replyToMessageId: Int64?) async throws -> Message
|
||||
func editMessage(chatId: Int64, messageId: Int64, text: String) async throws -> Message
|
||||
func deleteMessages(chatId: Int64, messageIds: [Int64]) async throws
|
||||
@@ -132,6 +133,12 @@ public actor FakeSessionBridge: SessionBridge {
|
||||
return profile
|
||||
}
|
||||
|
||||
public func leaveChat(chatId: Int64) async throws {
|
||||
chats.removeAll { $0.id == chatId }
|
||||
messages.removeValue(forKey: chatId)
|
||||
events.append(.chatListChanged(chats))
|
||||
}
|
||||
|
||||
public func sendMessage(chatId: Int64, text: String, replyToMessageId: Int64?) async throws -> Message {
|
||||
let message = Message(
|
||||
id: nextMessageId,
|
||||
|
||||
@@ -73,6 +73,10 @@ public actor UniFfiSessionBridge: SessionBridge {
|
||||
try Self.mapProfile(handle.openProfile(chatId: chatId))
|
||||
}
|
||||
|
||||
public func leaveChat(chatId: Int64) async throws {
|
||||
try handle.leaveChat(chatId: chatId)
|
||||
}
|
||||
|
||||
public func sendMessage(chatId: Int64, text: String, replyToMessageId: Int64?) async throws -> Message {
|
||||
try Self.mapMessage(
|
||||
handle.sendMessage(chatId: chatId, text: text, replyToMessageId: replyToMessageId),
|
||||
|
||||
@@ -284,6 +284,15 @@ public final class ProfileViewModel: ObservableObject {
|
||||
errorMessage = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
public func leave(chatId: Int64) async {
|
||||
do {
|
||||
try await bridge.leaveChat(chatId: chatId)
|
||||
errorMessage = nil
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
@@ -208,6 +208,10 @@ struct TeleTuiIOSSmokeTests {
|
||||
await viewModel.load(chatId: 1)
|
||||
precondition(viewModel.profile?.title == "Saved Messages")
|
||||
precondition(viewModel.profile?.username == "saved")
|
||||
|
||||
await viewModel.leave(chatId: 1)
|
||||
let chats = try await bridge.loadChats(folderId: nil)
|
||||
precondition(!chats.contains { $0.id == 1 })
|
||||
}
|
||||
|
||||
private static func appStorageUsesApplicationSupportStyleAccountPaths() {
|
||||
|
||||
Reference in New Issue
Block a user