From d193658cac2f16d73f6c5ea9a2ca67b3e7bf4d56 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Tue, 6 May 2025 14:55:54 +0000 Subject: [PATCH] ios: auto-open support chat for invitee in pending status (#5871) --- apps/ios/Shared/Views/Chat/ChatView.swift | 54 ++++++++++++++++++- .../Views/Chat/Group/GroupChatInfoView.swift | 6 ++- .../Views/Chat/Group/MemberSupportView.swift | 3 +- .../Views/Chat/Group/SecondaryChatView.swift | 7 ++- .../Shared/Views/ChatList/ChatListView.swift | 3 +- 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index d585d88791..4e26055903 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -25,6 +25,7 @@ struct ChatView: View { @ObservedObject var im: ItemsModel @State var mergedItems: BoxedValue @State var floatingButtonModel: FloatingButtonModel + var onSheet: Bool @State private var showChatInfoSheet: Bool = false @State private var showAddMembersSheet: Bool = false @State private var composeState = ComposeState() @@ -56,11 +57,14 @@ struct ChatView: View { @State private var allowLoadMoreItems: Bool = false @State private var ignoreLoadingRequests: Int64? = nil @State private var animatedScrollingInProgress: Bool = false + @State private var showUserSupportChatSheet = false @State private var scrollView: EndlessScrollView = EndlessScrollView(frame: .zero) @AppStorage(DEFAULT_TOOLBAR_MATERIAL) private var toolbarMaterial = ToolbarMaterial.defaultMaterial + let userSupportScopeInfo: GroupChatScopeInfo = .memberSupport(groupMember_: nil) + var body: some View { if #available(iOS 16.0, *) { viewBody @@ -86,6 +90,9 @@ struct ChatView: View { ) } VStack(spacing: 0) { + if onSheet { + customUserSupportChatNavigationBar() + } ZStack(alignment: .bottomTrailing) { chatItemsList() if let groupInfo = chat.chatInfo.groupInfo, !composeState.message.isEmpty { @@ -223,6 +230,13 @@ struct ChatView: View { } } } + if case let .group(groupInfo, nil) = chat.chatInfo, + groupInfo.membership.memberPending { + let secIM = ItemsModel(secondaryIMFilter: .groupChatScopeContext(groupScopeInfo: userSupportScopeInfo)) + secIM.loadOpenChat(chat.id) { + showUserSupportChatSheet = true + } + } } .onChange(of: chatModel.chatId) { cId in showChatInfoSheet = false @@ -336,6 +350,16 @@ struct ChatView: View { localAlias: groupInfo.localAlias ) } + .appSheet( + isPresented: $showUserSupportChatSheet, + onDismiss: { + if groupInfo.membership.memberPending { + chatModel.chatId = nil + } + } + ) { + userSupportChat(groupInfo) + } } else if case .local = cInfo { ChatInfoToolbar(chat: chat) } @@ -457,6 +481,33 @@ struct ChatView: View { } } + @ViewBuilder private func userSupportChat(_ groupInfo: GroupInfo) -> some View { + if let secondaryIM = chatModel.secondaryIM { + SecondaryChatView( + chat: Chat(chatInfo: .group(groupInfo: groupInfo, groupChatScope: userSupportScopeInfo), chatItems: [], chatStats: ChatStats()), + im: secondaryIM, + onSheet: true + ) + } else { + EmptyView() + } + } + + private func customUserSupportChatNavigationBar() -> some View { + VStack(spacing: 0) { + HStack { + Text("Support") + .font(.headline) + .foregroundColor(theme.colors.onBackground) + } + .padding(.horizontal) + .padding(.vertical, 12) + .frame(maxWidth: .infinity) + .background(.thinMaterial) + Divider() + } + } + func textChatToolbar(_ text: LocalizedStringKey) -> some View { HStack { Text(text).font(.headline) @@ -2605,7 +2656,8 @@ struct ChatView_Previews: PreviewProvider { chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: []), im: im, mergedItems: BoxedValue(MergedItems.create(im, [])), - floatingButtonModel: FloatingButtonModel(im: im) + floatingButtonModel: FloatingButtonModel(im: im), + onSheet: false ) .environmentObject(chatModel) } diff --git a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift index bdc315a918..1d578fcb41 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift @@ -557,7 +557,8 @@ struct GroupChatInfoView: View { if let secondaryIM = chatModel.secondaryIM { SecondaryChatView( chat: chat, - im: secondaryIM + im: secondaryIM, + onSheet: false ) } } label: { @@ -600,7 +601,8 @@ struct GroupChatInfoView: View { if let secondaryIM = chatModel.secondaryIM { SecondaryChatView( chat: chat, - im: secondaryIM + im: secondaryIM, + onSheet: false ) } } label: { diff --git a/apps/ios/Shared/Views/Chat/Group/MemberSupportView.swift b/apps/ios/Shared/Views/Chat/Group/MemberSupportView.swift index ea07532c22..88d6ab13e8 100644 --- a/apps/ios/Shared/Views/Chat/Group/MemberSupportView.swift +++ b/apps/ios/Shared/Views/Chat/Group/MemberSupportView.swift @@ -86,7 +86,8 @@ struct MemberSupportView: View { if let secondaryIM = chatModel.secondaryIM { SecondaryChatView( chat: chat, - im: secondaryIM + im: secondaryIM, + onSheet: false ) } } label: { diff --git a/apps/ios/Shared/Views/Chat/Group/SecondaryChatView.swift b/apps/ios/Shared/Views/Chat/Group/SecondaryChatView.swift index ef36cc3a31..13b3252cf4 100644 --- a/apps/ios/Shared/Views/Chat/Group/SecondaryChatView.swift +++ b/apps/ios/Shared/Views/Chat/Group/SecondaryChatView.swift @@ -13,13 +13,15 @@ struct SecondaryChatView: View { @EnvironmentObject var chatModel: ChatModel @ObservedObject var chat: Chat @ObservedObject var im: ItemsModel + var onSheet: Bool var body: some View { ChatView( chat: chat, im: im, mergedItems: BoxedValue(MergedItems.create(im, [])), - floatingButtonModel: FloatingButtonModel(im: im) + floatingButtonModel: FloatingButtonModel(im: im), + onSheet: onSheet ) .onDisappear { chatModel.secondaryIM = nil @@ -34,6 +36,7 @@ struct SecondaryChatView: View { chatItems: [], chatStats: ChatStats() ), - im: ItemsModel.shared + im: ItemsModel.shared, + onSheet: false ) } diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index 59364c9498..46c8cc9ae0 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -457,7 +457,8 @@ struct ChatListView: View { chat: chat, im: im, mergedItems: BoxedValue(MergedItems.create(im, [])), - floatingButtonModel: FloatingButtonModel(im: im) + floatingButtonModel: FloatingButtonModel(im: im), + onSheet: false ) } }