filter chat by link
This commit is contained in:
parent
0cc5ee50f9
commit
5d9de98ad2
@ -135,7 +135,7 @@ private func formatText(_ ft: FormattedText, _ preview: Bool) -> Text {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func linkText(_ s: String, _ link: String, _ preview: Bool, prefix: String, color: Color = Color(uiColor: uiLinkColor), uiColor: UIColor = uiLinkColor) -> Text {
|
func linkText(_ s: String, _ link: String, _ preview: Bool, prefix: String, color: Color = Color(uiColor: uiLinkColor), uiColor: UIColor = uiLinkColor) -> Text {
|
||||||
preview
|
preview
|
||||||
? Text(s).foregroundColor(color).underline(color: color)
|
? Text(s).foregroundColor(color).underline(color: color)
|
||||||
: Text(AttributedString(s, attributes: AttributeContainer([
|
: Text(AttributedString(s, attributes: AttributeContainer([
|
||||||
|
@ -16,6 +16,7 @@ struct ChatListView: View {
|
|||||||
@FocusState private var searchFocussed
|
@FocusState private var searchFocussed
|
||||||
@State private var searchText = ""
|
@State private var searchText = ""
|
||||||
@State private var searchShowingSimplexLink = false
|
@State private var searchShowingSimplexLink = false
|
||||||
|
@State private var searchChatFilteredBySimplexLink: String? = nil
|
||||||
@State private var newChatMenuOption: NewChatMenuOption? = nil
|
@State private var newChatMenuOption: NewChatMenuOption? = nil
|
||||||
@State private var userPickerVisible = false
|
@State private var userPickerVisible = false
|
||||||
@State private var showConnectDesktop = false
|
@State private var showConnectDesktop = false
|
||||||
@ -150,7 +151,8 @@ struct ChatListView: View {
|
|||||||
searchMode: $searchMode,
|
searchMode: $searchMode,
|
||||||
searchFocussed: $searchFocussed,
|
searchFocussed: $searchFocussed,
|
||||||
searchText: $searchText,
|
searchText: $searchText,
|
||||||
searchShowingSimplexLink: $searchShowingSimplexLink
|
searchShowingSimplexLink: $searchShowingSimplexLink,
|
||||||
|
searchChatFilteredBySimplexLink: $searchChatFilteredBySimplexLink
|
||||||
)
|
)
|
||||||
.listRowSeparator(.hidden)
|
.listRowSeparator(.hidden)
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
@ -226,22 +228,25 @@ struct ChatListView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func filteredChats() -> [Chat] {
|
private func filteredChats() -> [Chat] {
|
||||||
let s = searchText.trimmingCharacters(in: .whitespaces).localizedLowercase
|
if let linkChatId = searchChatFilteredBySimplexLink {
|
||||||
return (s == "" && !showUnreadAndFavorites || searchShowingSimplexLink)
|
return chatModel.chats.filter { $0.id == linkChatId }
|
||||||
|
} else {
|
||||||
|
let s = searchString()
|
||||||
|
return s == "" && !showUnreadAndFavorites
|
||||||
? chatModel.chats
|
? chatModel.chats
|
||||||
: chatModel.chats.filter { chat in
|
: chatModel.chats.filter { chat in
|
||||||
let cInfo = chat.chatInfo
|
let cInfo = chat.chatInfo
|
||||||
switch cInfo {
|
switch cInfo {
|
||||||
case let .direct(contact):
|
case let .direct(contact):
|
||||||
return s == ""
|
return s == ""
|
||||||
? filtered(chat)
|
? filtered(chat)
|
||||||
: (viewNameContains(cInfo, s) ||
|
: (viewNameContains(cInfo, s) ||
|
||||||
contact.profile.displayName.localizedLowercase.contains(s) ||
|
contact.profile.displayName.localizedLowercase.contains(s) ||
|
||||||
contact.fullName.localizedLowercase.contains(s))
|
contact.fullName.localizedLowercase.contains(s))
|
||||||
case let .group(gInfo):
|
case let .group(gInfo):
|
||||||
return s == ""
|
return s == ""
|
||||||
? (filtered(chat) || gInfo.membership.memberStatus == .memInvited)
|
? (filtered(chat) || gInfo.membership.memberStatus == .memInvited)
|
||||||
: viewNameContains(cInfo, s)
|
: viewNameContains(cInfo, s)
|
||||||
case .contactRequest:
|
case .contactRequest:
|
||||||
return s == "" || viewNameContains(cInfo, s)
|
return s == "" || viewNameContains(cInfo, s)
|
||||||
case let .contactConnection(conn):
|
case let .contactConnection(conn):
|
||||||
@ -250,6 +255,11 @@ struct ChatListView: View {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchString() -> String {
|
||||||
|
searchShowingSimplexLink ? "" : searchText.trimmingCharacters(in: .whitespaces).localizedLowercase
|
||||||
|
}
|
||||||
|
|
||||||
func filtered(_ chat: Chat) -> Bool {
|
func filtered(_ chat: Chat) -> Bool {
|
||||||
(chat.chatInfo.chatSettings?.favorite ?? false) || chat.chatStats.unreadCount > 0 || chat.chatStats.unreadChat
|
(chat.chatInfo.chatSettings?.favorite ?? false) || chat.chatStats.unreadCount > 0 || chat.chatStats.unreadChat
|
||||||
@ -267,6 +277,8 @@ struct ChatListSearchBar: View {
|
|||||||
@FocusState.Binding var searchFocussed: Bool
|
@FocusState.Binding var searchFocussed: Bool
|
||||||
@Binding var searchText: String
|
@Binding var searchText: String
|
||||||
@Binding var searchShowingSimplexLink: Bool
|
@Binding var searchShowingSimplexLink: Bool
|
||||||
|
@Binding var searchChatFilteredBySimplexLink: String?
|
||||||
|
@State private var ignoreSearchTextChange = false
|
||||||
@State private var cancelVisible = false
|
@State private var cancelVisible = false
|
||||||
@State private var pasteboardHasString = false
|
@State private var pasteboardHasString = false
|
||||||
@State private var showScanCodeSheet = false
|
@State private var showScanCodeSheet = false
|
||||||
@ -345,16 +357,25 @@ struct ChatListSearchBar: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: searchText) { t in
|
.onChange(of: searchText) { t in
|
||||||
if let link = strHasSingleSimplexLink(t.trimmingCharacters(in: .whitespaces)) { // if SimpleX link is pasted, show connection dialogue
|
if ignoreSearchTextChange {
|
||||||
searchFocussed = false
|
ignoreSearchTextChange = false
|
||||||
searchText = link.text
|
|
||||||
searchShowingSimplexLink = true
|
|
||||||
connect(link.text)
|
|
||||||
} else {
|
} else {
|
||||||
if t != "" { // if some other text is pasted, enter search mode
|
if let link = strHasSingleSimplexLink(t.trimmingCharacters(in: .whitespaces)) { // if SimpleX link is pasted, show connection dialogue
|
||||||
searchFocussed = true
|
searchFocussed = false
|
||||||
|
if link.text != t {
|
||||||
|
ignoreSearchTextChange = true
|
||||||
|
searchText = link.text
|
||||||
|
}
|
||||||
|
searchShowingSimplexLink = true
|
||||||
|
searchChatFilteredBySimplexLink = nil
|
||||||
|
connect(link.text)
|
||||||
|
} else {
|
||||||
|
if t != "" { // if some other text is pasted, enter search mode
|
||||||
|
searchFocussed = true
|
||||||
|
}
|
||||||
|
searchShowingSimplexLink = false
|
||||||
|
searchChatFilteredBySimplexLink = nil
|
||||||
}
|
}
|
||||||
searchShowingSimplexLink = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(item: $alert) { a in
|
.alert(item: $alert) { a in
|
||||||
@ -371,7 +392,9 @@ struct ChatListSearchBar: View {
|
|||||||
showAlert: { alert = $0 },
|
showAlert: { alert = $0 },
|
||||||
showActionSheet: { sheet = $0 },
|
showActionSheet: { sheet = $0 },
|
||||||
dismiss: false,
|
dismiss: false,
|
||||||
incognito: nil
|
incognito: nil,
|
||||||
|
specialKnownContact: { searchChatFilteredBySimplexLink = $0.id },
|
||||||
|
specialKnownGroup: { searchChatFilteredBySimplexLink = $0.id }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,9 @@ func planAndConnect(
|
|||||||
showActionSheet: @escaping (PlanAndConnectActionSheet) -> Void,
|
showActionSheet: @escaping (PlanAndConnectActionSheet) -> Void,
|
||||||
dismiss: Bool,
|
dismiss: Bool,
|
||||||
incognito: Bool?,
|
incognito: Bool?,
|
||||||
cleanup: (() -> Void)? = nil
|
cleanup: (() -> Void)? = nil,
|
||||||
|
specialKnownContact: ((Contact) -> Void)? = nil,
|
||||||
|
specialKnownGroup: ((GroupInfo) -> Void)? = nil
|
||||||
) {
|
) {
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
@ -717,13 +719,21 @@ func planAndConnect(
|
|||||||
case let .connecting(contact_):
|
case let .connecting(contact_):
|
||||||
logger.debug("planAndConnect, .invitationLink, .connecting, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .invitationLink, .connecting, incognito=\(incognito?.description ?? "nil")")
|
||||||
if let contact = contact_ {
|
if let contact = contact_ {
|
||||||
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyConnectingAlert(contact)) }
|
if let f = specialKnownContact {
|
||||||
|
f(contact)
|
||||||
|
} else {
|
||||||
|
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyConnectingAlert(contact)) }
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
showAlert(.invitationLinkConnecting(connectionLink: connectionLink))
|
showAlert(.invitationLinkConnecting(connectionLink: connectionLink))
|
||||||
}
|
}
|
||||||
case let .known(contact):
|
case let .known(contact):
|
||||||
logger.debug("planAndConnect, .invitationLink, .known, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .invitationLink, .known, incognito=\(incognito?.description ?? "nil")")
|
||||||
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyExistsAlert(contact)) }
|
if let f = specialKnownContact {
|
||||||
|
f(contact)
|
||||||
|
} else {
|
||||||
|
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyExistsAlert(contact)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case let .contactAddress(cap):
|
case let .contactAddress(cap):
|
||||||
switch cap {
|
switch cap {
|
||||||
@ -750,10 +760,18 @@ func planAndConnect(
|
|||||||
}
|
}
|
||||||
case let .connectingProhibit(contact):
|
case let .connectingProhibit(contact):
|
||||||
logger.debug("planAndConnect, .contactAddress, .connectingProhibit, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .contactAddress, .connectingProhibit, incognito=\(incognito?.description ?? "nil")")
|
||||||
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyConnectingAlert(contact)) }
|
if let f = specialKnownContact {
|
||||||
|
f(contact)
|
||||||
|
} else {
|
||||||
|
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyConnectingAlert(contact)) }
|
||||||
|
}
|
||||||
case let .known(contact):
|
case let .known(contact):
|
||||||
logger.debug("planAndConnect, .contactAddress, .known, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .contactAddress, .known, incognito=\(incognito?.description ?? "nil")")
|
||||||
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyExistsAlert(contact)) }
|
if let f = specialKnownContact {
|
||||||
|
f(contact)
|
||||||
|
} else {
|
||||||
|
openKnownContact(contact, dismiss: dismiss) { AlertManager.shared.showAlert(contactAlreadyExistsAlert(contact)) }
|
||||||
|
}
|
||||||
case let .contactViaAddress(contact):
|
case let .contactViaAddress(contact):
|
||||||
logger.debug("planAndConnect, .contactAddress, .contactViaAddress, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .contactAddress, .contactViaAddress, incognito=\(incognito?.description ?? "nil")")
|
||||||
if let incognito = incognito {
|
if let incognito = incognito {
|
||||||
@ -785,7 +803,11 @@ func planAndConnect(
|
|||||||
showAlert(.groupLinkConnecting(connectionLink: connectionLink, groupInfo: groupInfo_))
|
showAlert(.groupLinkConnecting(connectionLink: connectionLink, groupInfo: groupInfo_))
|
||||||
case let .known(groupInfo):
|
case let .known(groupInfo):
|
||||||
logger.debug("planAndConnect, .groupLink, .known, incognito=\(incognito?.description ?? "nil")")
|
logger.debug("planAndConnect, .groupLink, .known, incognito=\(incognito?.description ?? "nil")")
|
||||||
openKnownGroup(groupInfo, dismiss: dismiss) { AlertManager.shared.showAlert(groupAlreadyExistsAlert(groupInfo)) }
|
if let f = specialKnownGroup {
|
||||||
|
f(groupInfo)
|
||||||
|
} else {
|
||||||
|
openKnownGroup(groupInfo, dismiss: dismiss) { AlertManager.shared.showAlert(groupAlreadyExistsAlert(groupInfo)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user