SimpleX-Chat/apps/ios/Shared/Views/Contacts/ContactListNavLink.swift

267 lines
9.2 KiB
Swift
Raw Normal View History

ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
//
// ContactListNavLink.swift
// SimpleX (iOS)
//
// Created by Diogo Cunha on 01/08/2024.
// Copyright © 2024 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct ContactListNavLink: View {
@EnvironmentObject var theme: AppTheme
@ObservedObject var chat: Chat
var showDeletedChatIcon: Bool
@State private var alert: SomeAlert? = nil
@State private var actionSheet: SomeActionSheet? = nil
@State private var sheet: SomeSheet<AnyView>? = nil
@State private var showConnectContactViaAddressDialog = false
@State private var showContactRequestDialog = false
var body: some View {
core, ios: chat tags (#5367) * types and db * migration module * chat tag * store method proposal * profiles build * update type * update return type * building * working api * update * refactor * attach tags to contact * simplify * attach chat tags to group info * get chat tags with supplied user id * get tags fix * ios: chat tags poc (#5370) * ios: chat tags poc * updates to sheet * temporary display for other option on swipe * sheet height * only show preset when it has matches * changes * worst emoji picker ever * simplify tag casts and collapse * open on create tag if no tags * simple emoji text field * nice emoji picker * dismiss sheets on tag/untag * semibold selection * all preset tag and change collapsed icon on selection * default selected tag (all) * only apply tag filters on empty search * + button when no custom lists * reset selection of tag filter on profile changes * edit tag (broken menu inside swiftui list) * create list to end of list * swipe changes * remove context menu * delete and edit on swipe actions * tap unread filter deselects other filters * remove delete tag if empty * show tag creation sheet when + button pressed * in memory tag edit * color, size * frame * layout * refactor * remove code * add unread to same unit * fraction on long press * nav fixes * in memory list * emoji picker improvements * remove diff * secondary plus * stop flickering on chat tags load * reuse string * fix reset glitches * delete destructive * simplify? * changes * api updates * fix styles on list via swipe * fixed untag * update schema * move user tags loading to get users chat data * move presets to model * update preset tags when chats are updated * style fixes and locate getPresetTags near tags model --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * deleted contacts and card should not match contact preset * fix update presets on chat remove * update migration indices * fix migration * not used chat model * disable button on repeated list name or emoji * no chats message for search fix * fix edits and trim * error in footer, not in alert * styling fixes due to wrong place to attach sheet * update library * remove log * idea for dynamic sheet height * max fraction 62% * minor fixes * disable save button when no changes and while saving * disable preset filter if it is no longer shown * remove comments from schema * fix emoji * remove apiChatTagsResponse * always read chat tags * fix --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
2024-12-19 10:48:26 +00:00
let contactType = chatContactType(chat)
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
Group {
switch (chat.chatInfo) {
case let .direct(contact):
switch contactType {
case .recent:
recentContactNavLink(contact)
case .chatDeleted:
deletedChatNavLink(contact)
case .card:
contactCardNavLink(contact)
default:
EmptyView()
}
case let .contactRequest(contactRequest):
contactRequestNavLink(contactRequest)
default:
EmptyView()
}
}
.alert(item: $alert) { $0.alert }
.actionSheet(item: $actionSheet) { $0.actionSheet }
.sheet(item: $sheet) {
if #available(iOS 16.0, *) {
$0.content
.presentationDetents([.fraction(0.4)])
} else {
$0.content
}
}
}
func recentContactNavLink(_ contact: Contact) -> some View {
Button {
dismissAllSheets(animated: true) {
ItemsModel.shared.loadOpenChat(contact.id)
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
}
} label: {
contactPreview(contact, titleColor: theme.colors.onBackground)
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
deleteContactDialog(
chat,
contact,
dismissToChatList: false,
showAlert: { alert = $0 },
showActionSheet: { actionSheet = $0 },
showSheetContent: { sheet = $0 }
)
} label: {
Label("Delete", systemImage: "trash")
}
.tint(.red)
}
}
func deletedChatNavLink(_ contact: Contact) -> some View {
Button {
Task {
await MainActor.run {
dismissAllSheets(animated: true) {
ItemsModel.shared.loadOpenChat(contact.id)
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
}
}
}
} label: {
contactPreview(contact, titleColor: theme.colors.onBackground)
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
deleteContactDialog(
chat,
contact,
dismissToChatList: false,
showAlert: { alert = $0 },
showActionSheet: { actionSheet = $0 },
showSheetContent: { sheet = $0 }
)
} label: {
Label("Delete", systemImage: "trash")
}
.tint(.red)
}
}
func contactPreview(_ contact: Contact, titleColor: Color) -> some View {
HStack{
ProfileImage(imageStr: contact.image, size: 30)
previewTitle(contact, titleColor: titleColor)
Spacer()
HStack {
if showDeletedChatIcon && contact.chatDeleted {
Image(systemName: "archivebox")
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
.foregroundColor(.secondary.opacity(0.65))
} else if chat.chatInfo.chatSettings?.favorite ?? false {
Image(systemName: "star.fill")
.resizable()
.scaledToFill()
.frame(width: 18, height: 18)
.foregroundColor(.secondary.opacity(0.65))
}
if contact.contactConnIncognito {
Image(systemName: "theatermasks")
.resizable()
.scaledToFit()
.frame(width: 22, height: 22)
.foregroundColor(.secondary)
}
}
}
}
private func previewTitle(_ contact: Contact, titleColor: Color) -> some View {
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
let t = Text(chat.chatInfo.chatViewName).foregroundColor(titleColor)
return (
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
contact.verified == true
? verifiedIcon + t
: t
)
.lineLimit(1)
}
private var verifiedIcon: Text {
(Text(Image(systemName: "checkmark.shield")) + textSpace)
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
.foregroundColor(.secondary)
.baselineOffset(1)
.kerning(-2)
}
func contactCardNavLink(_ contact: Contact) -> some View {
Button {
showConnectContactViaAddressDialog = true
} label: {
contactCardPreview(contact)
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
deleteContactDialog(
chat,
contact,
dismissToChatList: false,
showAlert: { alert = $0 },
showActionSheet: { actionSheet = $0 },
showSheetContent: { sheet = $0 }
)
} label: {
Label("Delete", systemImage: "trash")
}
.tint(.red)
}
.confirmationDialog("Connect with \(contact.chatViewName)", isPresented: $showConnectContactViaAddressDialog, titleVisibility: .visible) {
Button("Use current profile") { connectContactViaAddress_(contact, false) }
Button("Use new incognito profile") { connectContactViaAddress_(contact, true) }
}
}
private func connectContactViaAddress_(_ contact: Contact, _ incognito: Bool) {
Task {
let ok = await connectContactViaAddress(contact.contactId, incognito, showAlert: { alert = SomeAlert(alert: $0, id: "ContactListNavLink connectContactViaAddress") })
if ok {
ItemsModel.shared.loadOpenChat(contact.id) {
ios: improve new and existing chat interactions - new chat sheet, one hand ui, info views action buttons; new modes of contact deletion (keep conversation, only delete conversation) (#4427) * ios: added delete contacts, one hand ui, and contact action buttons * remove unused, rework info buttons wip * ios: moved existing buttons to new chat sheet * ios: add basic list of contacts to new chat sheet * ios: add deleted chats section to new chat sheet * group chat info navigation * fix spacing of group info buttons * remove comment * unify spacing logic across info views * info button alerts wip * calls alerts wip * call buttons alerts * fix call button to correctly update on preference change while in view * refactor * fix alert ids * contact list wip * more contact list actions * open chat wip * fix contact list elements clickability * ios: search functionality on new chat sheet * ios: white bg for search box on new chat sheet * ios: don't show empty list when pasted contact is not known * ios: add search and nav title to deleted chats * navigation links wip * fix refreshable * ios: empty states for lists * ios: hide contact cards from chat list * ios: make search bar icon sizes consistent * ios: fix deleted conversation dissapearing from chat list on back * fix pending invitation cleanup in chat sheet * rename search label from open to search * make cleanup alert work on sheet and on dismiss * dismiss all sheets after creation of groups * fix double toolbar on group invite members * fix double toolbar on group link invitation screen * dismiss all on group creation error * comment * show alert in dismissAllSheets completion * fix sheet dismissal on known group * rework contact list with buttons (fixes dark mode) * fix dark mode on new chat view * fix search dark mode * increase search padding * improve new chat title and info button placing * info view background * improve create group title placement * refactor * fix delete dialogue in light mode * change icon * archivebox on contact list --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-05 12:58:24 +01:00
dismissAllSheets(animated: true) {
AlertManager.shared.showAlert(connReqSentAlert(.contact))
}
}
}
}
}
func contactCardPreview(_ contact: Contact) -> some View {
HStack{
ProfileImage(imageStr: contact.image, size: 30)
Text(chat.chatInfo.chatViewName)
.foregroundColor(.accentColor)
.lineLimit(1)
Spacer()
Image(systemName: "envelope")
.resizable()
.scaledToFill()
.frame(width: 14, height: 14)
.foregroundColor(.accentColor)
}
}
func contactRequestNavLink(_ contactRequest: UserContactRequest) -> some View {
Button {
showContactRequestDialog = true
} label: {
contactRequestPreview(contactRequest)
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
Task { await acceptContactRequest(incognito: false, contactRequest: contactRequest) }
} label: { Label("Accept", systemImage: "checkmark") }
.tint(theme.colors.primary)
Button {
Task { await acceptContactRequest(incognito: true, contactRequest: contactRequest) }
} label: {
Label("Accept incognito", systemImage: "theatermasks")
}
.tint(.indigo)
Button {
alert = SomeAlert(alert: rejectContactRequestAlert(contactRequest), id: "rejectContactRequestAlert")
} label: {
Label("Reject", systemImage: "multiply")
}
.tint(.red)
}
.confirmationDialog("Accept connection request?", isPresented: $showContactRequestDialog, titleVisibility: .visible) {
Button("Accept") { Task { await acceptContactRequest(incognito: false, contactRequest: contactRequest) } }
Button("Accept incognito") { Task { await acceptContactRequest(incognito: true, contactRequest: contactRequest) } }
Button("Reject (sender NOT notified)", role: .destructive) { Task { await rejectContactRequest(contactRequest) } }
}
}
func contactRequestPreview(_ contactRequest: UserContactRequest) -> some View {
HStack{
ProfileImage(imageStr: contactRequest.image, size: 30)
Text(chat.chatInfo.chatViewName)
.foregroundColor(.accentColor)
.lineLimit(1)
Spacer()
Image(systemName: "checkmark")
.resizable()
.scaledToFill()
.frame(width: 14, height: 14)
.foregroundColor(.accentColor)
}
}
}