ios: contact aliases (#970)

* ios: contact aliases

* wip

* wip

* wip

* move onTapGesture

* revert test

* improve search

* corrections

* font size

* remove parameter

* clear button

* button style

* remove clear button

* ternary

* refactor search

* rename

* ios: contact aliases translations (#972)

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
JRoberts
2022-08-25 17:36:26 +04:00
committed by GitHub
parent a5e74ea2f0
commit 3a077d927d
12 changed files with 137 additions and 30 deletions

View File

@@ -46,8 +46,11 @@ struct ChatInfoView: View {
@EnvironmentObject var chatModel: ChatModel
@Environment(\.dismiss) var dismiss: DismissAction
@ObservedObject var chat: Chat
var contact: Contact
var connectionStats: ConnectionStats?
var customUserProfile: Profile?
@State var localAlias: String
@FocusState private var aliasTextFieldFocused: Bool
@State private var alert: ChatInfoViewAlert? = nil
@AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false
@@ -64,6 +67,14 @@ struct ChatInfoView: View {
List {
contactInfoHeader()
.listRowBackground(Color.clear)
.contentShape(Rectangle())
.onTapGesture {
aliasTextFieldFocused = false
}
localAliasTextEdit()
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
if let customUserProfile = customUserProfile {
Section("Incognito") {
@@ -113,11 +124,11 @@ struct ChatInfoView: View {
.frame(width: 192, height: 192)
.padding(.top, 12)
.padding()
Text(cInfo.displayName)
Text(contact.profile.displayName)
.font(.largeTitle)
.lineLimit(1)
.padding(.bottom, 2)
if cInfo.fullName != "" && cInfo.fullName != cInfo.displayName {
if cInfo.fullName != "" && cInfo.fullName != cInfo.displayName && cInfo.fullName != contact.profile.displayName {
Text(cInfo.fullName)
.font(.title2)
.lineLimit(2)
@@ -126,6 +137,37 @@ struct ChatInfoView: View {
.frame(maxWidth: .infinity, alignment: .center)
}
func localAliasTextEdit() -> some View {
TextField("Set contact name…", text: $localAlias)
.disableAutocorrection(true)
.focused($aliasTextFieldFocused)
.submitLabel(.done)
.onChange(of: aliasTextFieldFocused) { focused in
if !focused {
setContactAlias()
}
}
.onSubmit {
setContactAlias()
}
.multilineTextAlignment(.center)
.foregroundColor(.secondary)
}
private func setContactAlias() {
Task {
do {
if let contact = try await apiSetContactAlias(contactId: chat.chatInfo.apiId, localAlias: localAlias) {
await MainActor.run {
chatModel.updateContact(contact)
}
}
} catch {
logger.error("setContactAlias error: \(responseError(error))")
}
}
}
func networkStatusRow() -> some View {
HStack {
Text("Network status")
@@ -209,6 +251,6 @@ struct ChatInfoView: View {
struct ChatInfoView_Previews: PreviewProvider {
static var previews: some View {
ChatInfoView(chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: []))
ChatInfoView(chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: []), contact: Contact.sampleData, localAlias: "")
}
}

View File

@@ -101,8 +101,8 @@ struct ChatView: View {
}
.sheet(isPresented: $showChatInfoSheet) {
switch cInfo {
case .direct:
ChatInfoView(chat: chat, connectionStats: connectionStats, customUserProfile: customUserProfile)
case let .direct(contact):
ChatInfoView(chat: chat, contact: contact, connectionStats: connectionStats, customUserProfile: customUserProfile, localAlias: chat.chatInfo.localAlias)
case let .group(groupInfo):
GroupChatInfoView(chat: chat, groupInfo: groupInfo)
default:

View File

@@ -20,7 +20,7 @@ struct GroupChatInfoView: View {
@State private var selectedMember: GroupMember? = nil
@State private var showGroupProfile: Bool = false
@State private var connectionStats: ConnectionStats?
@State private var mainProfile: Profile?
@State private var memberMainProfile: LocalProfile?
@AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false
enum GroupChatInfoViewAlert: Identifiable {
@@ -53,7 +53,7 @@ struct GroupChatInfoView: View {
let (stats, profile) = try await apiGroupMemberInfo(groupInfo.apiId, member.groupMemberId)
await MainActor.run {
connectionStats = stats
mainProfile = profile
memberMainProfile = profile
}
} catch let error {
logger.error("apiGroupMemberInfo error: \(responseError(error))")
@@ -67,7 +67,7 @@ struct GroupChatInfoView: View {
AddGroupMembersView(chat: chat, groupInfo: groupInfo)
}
.sheet(item: $selectedMember, onDismiss: { connectionStats = nil }) { member in
GroupMemberInfoView(groupInfo: groupInfo, member: member, connectionStats: connectionStats, mainProfile: mainProfile)
GroupMemberInfoView(groupInfo: groupInfo, member: member, connectionStats: connectionStats, mainProfile: memberMainProfile)
}
.sheet(isPresented: $showGroupProfile) {
GroupProfileView(groupId: groupInfo.apiId, groupProfile: groupInfo.groupProfile)

View File

@@ -15,7 +15,7 @@ struct GroupMemberInfoView: View {
var groupInfo: GroupInfo
var member: GroupMember
var connectionStats: ConnectionStats?
var mainProfile: Profile?
var mainProfile: LocalProfile?
@State private var alert: GroupMemberInfoViewAlert?
@AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false
@@ -76,7 +76,7 @@ struct GroupMemberInfoView: View {
}
}
private func mainProfileRow(_ mainProfile: Profile) -> some View {
private func mainProfileRow(_ mainProfile: LocalProfile) -> some View {
HStack {
Text("Known main profile")
Spacer()