2022-07-18 21:58:32 +04:00
|
|
|
//
|
|
|
|
// CIGroupInvitationView.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by JRoberts on 15.07.2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import SimpleXChat
|
|
|
|
|
|
|
|
struct CIGroupInvitationView: View {
|
2022-08-23 18:18:12 +04:00
|
|
|
@EnvironmentObject var chatModel: ChatModel
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2024-08-25 21:21:24 +03:00
|
|
|
@Environment(\.showTimestamp) var showTimestamp: Bool
|
2024-04-25 12:41:20 +04:00
|
|
|
@ObservedObject var chat: Chat
|
2022-07-18 21:58:32 +04:00
|
|
|
var chatItem: ChatItem
|
|
|
|
var groupInvitation: CIGroupInvitation
|
|
|
|
var memberRole: GroupMemberRole
|
2022-08-23 18:18:12 +04:00
|
|
|
var chatIncognito: Bool = false
|
2022-07-18 21:58:32 +04:00
|
|
|
@State private var frameWidth: CGFloat = 0
|
2023-10-26 10:32:11 +04:00
|
|
|
@State private var inProgress = false
|
|
|
|
@State private var progressByTimeout = false
|
2022-07-18 21:58:32 +04:00
|
|
|
|
2024-05-15 16:09:42 +04:00
|
|
|
@AppStorage(DEFAULT_SHOW_SENT_VIA_RPOXY) private var showSentViaProxy = false
|
|
|
|
|
2022-07-18 21:58:32 +04:00
|
|
|
var body: some View {
|
|
|
|
let action = !chatItem.chatDir.sent && groupInvitation.status == .pending
|
|
|
|
let v = ZStack(alignment: .bottomTrailing) {
|
2023-10-26 10:32:11 +04:00
|
|
|
ZStack {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
groupInfoView(action)
|
|
|
|
.padding(.horizontal, 2)
|
|
|
|
.padding(.top, 8)
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
.overlay(DetermineWidth())
|
2022-07-18 21:58:32 +04:00
|
|
|
|
2023-10-26 10:32:11 +04:00
|
|
|
Divider().frame(width: frameWidth)
|
2022-07-18 21:58:32 +04:00
|
|
|
|
2023-10-26 10:32:11 +04:00
|
|
|
if action {
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
|
groupInvitationText()
|
|
|
|
.overlay(DetermineWidth())
|
2024-04-25 12:41:20 +04:00
|
|
|
(
|
|
|
|
Text(chatIncognito ? "Tap to join incognito" : "Tap to join")
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(inProgress ? theme.colors.secondary : chatIncognito ? .indigo : theme.colors.primary)
|
2024-04-25 12:41:20 +04:00
|
|
|
.font(.callout)
|
2024-11-27 19:01:16 +00:00
|
|
|
+ Text(verbatim: " ")
|
2024-09-06 14:36:54 +03:00
|
|
|
+ ciMetaText(chatItem.meta, chatTTL: nil, encrypted: nil, colorMode: .transparent, showStatus: false, showEdited: false, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
|
2024-04-25 12:41:20 +04:00
|
|
|
)
|
|
|
|
.overlay(DetermineWidth())
|
2023-10-26 10:32:11 +04:00
|
|
|
}
|
|
|
|
} else {
|
2024-04-25 12:41:20 +04:00
|
|
|
(
|
|
|
|
groupInvitationText()
|
2024-11-27 19:01:16 +00:00
|
|
|
+ Text(verbatim: " ")
|
2024-09-06 14:36:54 +03:00
|
|
|
+ ciMetaText(chatItem.meta, chatTTL: nil, encrypted: nil, colorMode: .transparent, showStatus: false, showEdited: false, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
|
2024-04-25 12:41:20 +04:00
|
|
|
)
|
|
|
|
.overlay(DetermineWidth())
|
2023-10-26 10:32:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.bottom, 2)
|
|
|
|
|
|
|
|
if progressByTimeout {
|
|
|
|
ProgressView().scaleEffect(2)
|
2022-07-18 21:58:32 +04:00
|
|
|
}
|
|
|
|
}
|
2023-10-26 10:32:11 +04:00
|
|
|
|
2024-07-03 22:42:13 +01:00
|
|
|
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary, showStatus: false, showEdited: false)
|
2022-07-18 21:58:32 +04:00
|
|
|
}
|
|
|
|
.padding(.horizontal, 12)
|
|
|
|
.padding(.vertical, 6)
|
2024-08-27 16:30:07 +03:00
|
|
|
.background { chatItemFrameColor(chatItem, theme).modifier(ChatTailPadding()) }
|
2022-07-18 21:58:32 +04:00
|
|
|
.textSelection(.disabled)
|
|
|
|
.onPreferenceChange(DetermineWidth.Key.self) { frameWidth = $0 }
|
2023-10-26 10:32:11 +04:00
|
|
|
.onChange(of: inProgress) { inProgress in
|
|
|
|
if inProgress {
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
|
|
progressByTimeout = inProgress
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
progressByTimeout = false
|
|
|
|
}
|
|
|
|
}
|
2022-07-18 21:58:32 +04:00
|
|
|
|
|
|
|
if action {
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
v.simultaneousGesture(TapGesture().onEnded {
|
2023-10-26 10:32:11 +04:00
|
|
|
inProgress = true
|
|
|
|
joinGroup(groupInvitation.groupId) {
|
|
|
|
await MainActor.run { inProgress = false }
|
|
|
|
}
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
})
|
2023-10-26 10:32:11 +04:00
|
|
|
.disabled(inProgress)
|
2022-07-18 21:58:32 +04:00
|
|
|
} else {
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func groupInfoView(_ action: Bool) -> some View {
|
2022-08-23 18:18:12 +04:00
|
|
|
var color: Color
|
2023-10-26 10:32:11 +04:00
|
|
|
if action && !inProgress {
|
2024-07-03 22:42:13 +01:00
|
|
|
color = chatIncognito ? .indigo : theme.colors.primary
|
2022-08-23 18:18:12 +04:00
|
|
|
} else {
|
|
|
|
color = Color(uiColor: .tertiaryLabel)
|
|
|
|
}
|
|
|
|
return HStack(alignment: .top) {
|
2022-07-18 21:58:32 +04:00
|
|
|
ProfileImage(
|
2022-08-23 18:18:12 +04:00
|
|
|
imageStr: groupInvitation.groupProfile.image,
|
2022-07-18 21:58:32 +04:00
|
|
|
iconName: "person.2.circle.fill",
|
2024-04-24 21:20:26 +01:00
|
|
|
size: 44,
|
2022-08-23 18:18:12 +04:00
|
|
|
color: color
|
2022-07-18 21:58:32 +04:00
|
|
|
)
|
|
|
|
.padding(.trailing, 4)
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
let p = groupInvitation.groupProfile
|
|
|
|
Text(p.displayName).font(.headline).lineLimit(2)
|
|
|
|
if p.fullName != "" && p.displayName != p.fullName {
|
|
|
|
Text(p.fullName).font(.subheadline).lineLimit(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(minHeight: 44)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 12:41:20 +04:00
|
|
|
private func groupInvitationText() -> Text {
|
2022-07-18 21:58:32 +04:00
|
|
|
Text(groupInvitationStr())
|
|
|
|
.font(.callout)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func groupInvitationStr() -> LocalizedStringKey {
|
|
|
|
if chatItem.chatDir.sent {
|
2022-08-29 14:47:29 +04:00
|
|
|
return "You sent group invitation"
|
2022-07-18 21:58:32 +04:00
|
|
|
} else {
|
|
|
|
switch groupInvitation.status {
|
|
|
|
case .pending: return "You are invited to group"
|
|
|
|
case .accepted: return "You joined this group"
|
|
|
|
case .rejected: return "You rejected group invitation"
|
|
|
|
case .expired: return "Group invitation expired"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CIGroupInvitationView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
Group {
|
2024-04-25 12:41:20 +04:00
|
|
|
CIGroupInvitationView(chat: Chat.sampleData, chatItem: ChatItem.getGroupInvitationSample(), groupInvitation: CIGroupInvitation.getSample(groupProfile: GroupProfile(displayName: "team", fullName: "team")), memberRole: .admin)
|
|
|
|
CIGroupInvitationView(chat: Chat.sampleData, chatItem: ChatItem.getGroupInvitationSample(), groupInvitation: CIGroupInvitation.getSample(status: .accepted), memberRole: .admin)
|
2022-07-18 21:58:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|