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
|
2022-07-18 21:58:32 +04:00
|
|
|
@Environment(\.colorScheme) var colorScheme
|
|
|
|
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
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
let action = !chatItem.chatDir.sent && groupInvitation.status == .pending
|
2022-08-23 18:18:12 +04:00
|
|
|
let unsafeToJoinIncognito = interactiveIncognito && !chatIncognito
|
2022-07-18 21:58:32 +04:00
|
|
|
let v = ZStack(alignment: .bottomTrailing) {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
groupInfoView(action)
|
|
|
|
.padding(.horizontal, 2)
|
|
|
|
.padding(.top, 8)
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
.overlay(DetermineWidth())
|
|
|
|
|
|
|
|
Divider().frame(width: frameWidth)
|
|
|
|
|
|
|
|
if action {
|
2022-08-23 18:18:12 +04:00
|
|
|
groupInvitationText()
|
|
|
|
.overlay(DetermineWidth())
|
|
|
|
Text(interactiveIncognito ? "Tap to join incognito" : "Tap to join")
|
|
|
|
.foregroundColor(interactiveIncognito ? .indigo : .accentColor)
|
2022-07-18 21:58:32 +04:00
|
|
|
.font(.callout)
|
2022-08-23 18:18:12 +04:00
|
|
|
.padding(.trailing, 60)
|
|
|
|
.overlay(DetermineWidth())
|
2022-07-18 21:58:32 +04:00
|
|
|
} else {
|
|
|
|
groupInvitationText()
|
|
|
|
.padding(.trailing, 60)
|
|
|
|
.overlay(DetermineWidth())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.bottom, 2)
|
|
|
|
chatItem.timestampText
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 12)
|
|
|
|
.padding(.vertical, 6)
|
|
|
|
.background(chatItemFrameColor(chatItem, colorScheme))
|
|
|
|
.cornerRadius(18)
|
|
|
|
.textSelection(.disabled)
|
|
|
|
.onPreferenceChange(DetermineWidth.Key.self) { frameWidth = $0 }
|
|
|
|
|
|
|
|
if action {
|
2022-08-23 18:18:12 +04:00
|
|
|
v.onTapGesture {
|
|
|
|
if unsafeToJoinIncognito {
|
|
|
|
AlertManager.shared.showAlert(unsafeToJoinIncognitoAlert(groupInvitation.groupId))
|
|
|
|
} else {
|
|
|
|
joinGroup(groupInvitation.groupId)
|
|
|
|
}
|
|
|
|
}
|
2022-07-18 21:58:32 +04:00
|
|
|
} else {
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:18:12 +04:00
|
|
|
private var interactiveIncognito: Bool {
|
|
|
|
(groupInvitation.invitedIncognito ?? false) || chatModel.incognito
|
|
|
|
}
|
|
|
|
|
2022-07-18 21:58:32 +04:00
|
|
|
private func groupInfoView(_ action: Bool) -> some View {
|
2022-08-23 18:18:12 +04:00
|
|
|
var color: Color
|
|
|
|
if action {
|
|
|
|
color = interactiveIncognito ? .indigo : .accentColor
|
|
|
|
} 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",
|
2022-08-23 18:18:12 +04:00
|
|
|
color: color
|
2022-07-18 21:58:32 +04:00
|
|
|
)
|
|
|
|
.frame(width: 44, height: 44)
|
|
|
|
.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func groupInvitationText() -> some View {
|
|
|
|
Text(groupInvitationStr())
|
|
|
|
.font(.callout)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func groupInvitationStr() -> LocalizedStringKey {
|
|
|
|
if chatItem.chatDir.sent {
|
2022-08-23 18:18:12 +04:00
|
|
|
return (groupInvitation.invitedIncognito ?? false) ? "You sent group invitation incognito" : "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 {
|
|
|
|
CIGroupInvitationView(chatItem: ChatItem.getGroupInvitationSample(), groupInvitation: CIGroupInvitation.getSample(groupProfile: GroupProfile(displayName: "team", fullName: "team")), memberRole: .admin)
|
|
|
|
CIGroupInvitationView(chatItem: ChatItem.getGroupInvitationSample(), groupInvitation: CIGroupInvitation.getSample(status: .accepted), memberRole: .admin)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|