fix relationships

This commit is contained in:
cheykrym 2025-12-11 01:28:39 +03:00
parent 549b2126a9
commit 19939dcf61
3 changed files with 83 additions and 13 deletions

View File

@ -310,9 +310,25 @@ struct ChatProfilePermissions: Decodable {
} }
struct RelationshipStatus: Decodable { struct RelationshipStatus: Decodable {
let isTargetInContactsOfCurrentUser: Bool
let isCurrentUserInContactsOfTarget: Bool let isCurrentUserInContactsOfTarget: Bool
let isTargetUserBlockedByCurrentUser: Bool let isTargetUserBlockedByCurrentUser: Bool
let isCurrentUserInBlacklistOfTarget: Bool let isCurrentUserInBlacklistOfTarget: Bool
private enum CodingKeys: String, CodingKey {
case isTargetInContactsOfCurrentUser
case isCurrentUserInContactsOfTarget
case isTargetUserBlockedByCurrentUser
case isCurrentUserInBlacklistOfTarget
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.isTargetInContactsOfCurrentUser = try container.decodeIfPresent(Bool.self, forKey: .isTargetInContactsOfCurrentUser) ?? false
self.isCurrentUserInContactsOfTarget = try container.decodeIfPresent(Bool.self, forKey: .isCurrentUserInContactsOfTarget) ?? false
self.isTargetUserBlockedByCurrentUser = try container.decodeIfPresent(Bool.self, forKey: .isTargetUserBlockedByCurrentUser) ?? false
self.isCurrentUserInBlacklistOfTarget = try container.decodeIfPresent(Bool.self, forKey: .isCurrentUserInBlacklistOfTarget) ?? false
}
} }
enum JSONValue: Decodable { enum JSONValue: Decodable {

View File

@ -295,6 +295,9 @@
"был(а) %@" : { "был(а) %@" : {
"comment" : "Message profile last seen relative format" "comment" : "Message profile last seen relative format"
}, },
"В ваших контактах" : {
"comment" : "Message profile user in contacts tag"
},
"в сети" : { "в сети" : {
"comment" : "Message profile online status" "comment" : "Message profile online status"
}, },

View File

@ -254,6 +254,35 @@ struct MessageProfileView: View {
value: ratingDisplayValue value: ratingDisplayValue
) )
if shouldShowRelationshipQuickActions {
rowDivider
VStack(spacing: 8) {
buttonRow(
icon: "person.badge.plus",
title: NSLocalizedString("Добавить в контакты", comment: "Message profile add to contacts title"),
subtitle: NSLocalizedString("Появится отдельная запись в адресной книге Yobble.", comment: "Message profile add to contacts subtitle"),
iconTint: .accentColor
) {
handleAddContactTap()
}
buttonRow(
icon: "hand.raised.slash.fill",
title: isBlockedByCurrentUser
? NSLocalizedString("Разблокировать", comment: "Message profile unblock title")
: NSLocalizedString("Заблокировать", comment: "Message profile block title"),
subtitle: isBlockedByCurrentUser
? NSLocalizedString("Пользователь снова сможет писать вам.", comment: "Message profile unblock subtitle")
: NSLocalizedString("Перестанет появляться в чате и не сможет писать.", comment: "Message profile block subtitle"),
iconTint: .red,
destructive: true
) {
handleBlockToggleTap()
}
}
.padding(.top, 4)
}
} }
} }
} }
@ -407,10 +436,7 @@ struct MessageProfileView: View {
subtitle: NSLocalizedString("Появится отдельная запись в адресной книге Yobble.", comment: "Message profile add to contacts subtitle"), subtitle: NSLocalizedString("Появится отдельная запись в адресной книге Yobble.", comment: "Message profile add to contacts subtitle"),
iconTint: .accentColor iconTint: .accentColor
) { ) {
showPlaceholderAction( handleAddContactTap()
title: NSLocalizedString("Добавить контакт", comment: "Message profile add contact alert title"),
message: NSLocalizedString("Редактор контактов скоро появится. Мы сохраним имя, телефон и заметку.", comment: "Message profile add contact alert message")
)
} }
rowDivider rowDivider
@ -449,15 +475,7 @@ struct MessageProfileView: View {
iconTint: .red, iconTint: .red,
destructive: true destructive: true
) { ) {
let message = isBlockedByCurrentUser handleBlockToggleTap()
? NSLocalizedString("Скоро появится разблокировка с подтверждением и синхронизацией.", comment: "Message profile unblock alert message")
: NSLocalizedString("Блокировка чата пока в дизайне. Готовим отдельный экран со статусом и жалобой.", comment: "Message profile block alert message")
showPlaceholderAction(
title: isBlockedByCurrentUser
? NSLocalizedString("Разблокировать", comment: "Message profile unblock alert title")
: NSLocalizedString("Заблокировать", comment: "Message profile block alert title"),
message: message
)
} }
rowDivider rowDivider
@ -609,6 +627,23 @@ struct MessageProfileView: View {
placeholderAlert = PlaceholderAlert(title: title, message: message) placeholderAlert = PlaceholderAlert(title: title, message: message)
} }
private func handleAddContactTap() {
showPlaceholderAction(
title: NSLocalizedString("Добавить контакт", comment: "Message profile add contact alert title"),
message: NSLocalizedString("Редактор контактов скоро появится. Мы сохраним имя, телефон и заметку.", comment: "Message profile add contact alert message")
)
}
private func handleBlockToggleTap() {
let title = isBlockedByCurrentUser
? NSLocalizedString("Разблокировать", comment: "Message profile unblock alert title")
: NSLocalizedString("Заблокировать", comment: "Message profile block alert title")
let message = isBlockedByCurrentUser
? NSLocalizedString("Скоро появится разблокировка с подтверждением и синхронизацией.", comment: "Message profile unblock alert message")
: NSLocalizedString("Блокировка чата пока в дизайне. Готовим отдельный экран со статусом и жалобой.", comment: "Message profile block alert message")
showPlaceholderAction(title: title, message: message)
}
// MARK: - Derived Data // MARK: - Derived Data
private var profileBio: String? { private var profileBio: String? {
@ -625,6 +660,11 @@ struct MessageProfileView: View {
) )
} }
private var shouldShowRelationshipQuickActions: Bool {
guard let relationship = chat.chatData?.relationship else { return false }
return !relationship.isTargetInContactsOfCurrentUser
}
private var ratingDisplayValue: String { private var ratingDisplayValue: String {
guard let rating = chat.chatData?.rating else { guard let rating = chat.chatData?.rating else {
return NSLocalizedString("Недоступно", comment: "Message profile rating unavailable") return NSLocalizedString("Недоступно", comment: "Message profile rating unavailable")
@ -696,6 +736,17 @@ struct MessageProfileView: View {
} }
if let relationship = chat.chatData?.relationship { if let relationship = chat.chatData?.relationship {
if relationship.isTargetInContactsOfCurrentUser {
tags.append(
StatusTag(
icon: "person.crop.circle.badge.checkmark",
text: NSLocalizedString("В ваших контактах", comment: "Message profile user in contacts tag"),
background: Color.white.opacity(0.14),
tint: .white
)
)
}
if relationship.isCurrentUserInContactsOfTarget { if relationship.isCurrentUserInContactsOfTarget {
tags.append( tags.append(
StatusTag( StatusTag(