Add iOS profile leave flow

This commit is contained in:
Mikhail Kilin
2026-05-21 15:52:25 +03:00
parent ec74961677
commit 782f08e00e

View File

@@ -173,7 +173,10 @@ public struct ChatListView: View {
} }
} detail: { } detail: {
if let selectedChat { if let selectedChat {
ChatDetailView(viewModel: ChatViewModel(chat: selectedChat, bridge: bridge), bridge: bridge) ChatDetailView(viewModel: ChatViewModel(chat: selectedChat, bridge: bridge), bridge: bridge) {
self.selectedChat = nil
Task { await viewModel.load() }
}
} else { } else {
Text("Select a chat") Text("Select a chat")
} }
@@ -327,15 +330,18 @@ public struct ChatDetailView: View {
@State private var deleteCandidate: Message? @State private var deleteCandidate: Message?
@State private var forwardCandidate: Message? @State private var forwardCandidate: Message?
@State private var forwardChatIdText = "" @State private var forwardChatIdText = ""
private let onChatLeft: () -> Void
public init( public init(
viewModel: ChatViewModel, viewModel: ChatViewModel,
bridge: SessionBridge, bridge: SessionBridge,
clipboard: ClipboardWriting = SystemClipboardWriter() clipboard: ClipboardWriting = SystemClipboardWriter(),
onChatLeft: @escaping () -> Void = {}
) { ) {
_viewModel = StateObject(wrappedValue: viewModel) _viewModel = StateObject(wrappedValue: viewModel)
self.bridge = bridge self.bridge = bridge
self.clipboard = clipboard self.clipboard = clipboard
self.onChatLeft = onChatLeft
_profileViewModel = StateObject(wrappedValue: ProfileViewModel(bridge: bridge)) _profileViewModel = StateObject(wrappedValue: ProfileViewModel(bridge: bridge))
} }
@@ -437,7 +443,10 @@ public struct ChatDetailView: View {
} }
} }
.sheet(isPresented: $showsProfile) { .sheet(isPresented: $showsProfile) {
ProfileView(viewModel: profileViewModel) ProfileView(viewModel: profileViewModel, chatId: viewModel.chat.id) {
showsProfile = false
onChatLeft()
}
} }
.alert("Edit Message", isPresented: editAlertBinding) { .alert("Edit Message", isPresented: editAlertBinding) {
TextField("Message", text: $editedText) TextField("Message", text: $editedText)
@@ -852,9 +861,14 @@ public struct ComposeBar: View {
public struct ProfileView: View { public struct ProfileView: View {
@ObservedObject public var viewModel: ProfileViewModel @ObservedObject public var viewModel: ProfileViewModel
public var chatId: Int64?
public var onLeave: () -> Void
@State private var confirmsLeave = false
public init(viewModel: ProfileViewModel) { public init(viewModel: ProfileViewModel, chatId: Int64? = nil, onLeave: @escaping () -> Void = {}) {
self.viewModel = viewModel self.viewModel = viewModel
self.chatId = chatId
self.onLeave = onLeave
} }
public var body: some View { public var body: some View {
@@ -877,11 +891,33 @@ public struct ProfileView: View {
Text("\(memberCount) members") Text("\(memberCount) members")
} }
} }
if profile.isGroup, chatId != nil {
Section {
Button(role: .destructive) {
confirmsLeave = true
} label: {
Label("Leave Chat", systemImage: "rectangle.portrait.and.arrow.right")
}
}
}
} else { } else {
ProgressView() ProgressView()
} }
} }
.navigationTitle("Profile") .navigationTitle("Profile")
.alert("Leave Chat", isPresented: $confirmsLeave) {
Button("Leave", role: .destructive) {
if let chatId {
Task {
await viewModel.leave(chatId: chatId)
if viewModel.errorMessage == nil {
onLeave()
}
}
}
}
Button("Cancel", role: .cancel) {}
}
} }
} }
} }