Compare commits

..

No commits in common. "9f6beecb49ced0f137982d55212dc8a5516ff2f9" and "052ff5fe4f0337a52d9f95f73d3983f59a802e9f" have entirely different histories.

4 changed files with 65 additions and 105 deletions

View File

@ -29,16 +29,3 @@ struct ErrorResponse: Decodable {
struct MessagePayload: Decodable {
let message: String
}
struct BlockedUserInfo: Decodable {
let userId: UUID
let login: String
let fullName: String?
let customName: String?
let createdAt: Date
}
struct BlockedUsersPayload: Decodable {
let hasMore: Bool
let items: [BlockedUserInfo]
}

View File

@ -19,6 +19,14 @@ enum BlockedUsersServiceError: LocalizedError {
}
}
struct BlockedUserPayload: Decodable {
let userId: UUID
let login: String
let fullName: String?
let customName: String?
let createdAt: Date
}
final class BlockedUsersService {
private let client: NetworkClient
private let decoder: JSONDecoder
@ -30,22 +38,16 @@ final class BlockedUsersService {
self.decoder.dateDecodingStrategy = .custom(Self.decodeDate)
}
func fetchBlockedUsers(limit: Int, offset: Int, completion: @escaping (Result<BlockedUsersPayload, Error>) -> Void) {
let query = [
"limit": String(limit),
"offset": String(offset)
]
func fetchBlockedUsers(completion: @escaping (Result<[BlockedUserPayload], Error>) -> Void) {
client.request(
path: "/v1/user/blacklist/list",
method: .get,
query: query,
requiresAuth: true
) { [decoder] result in
switch result {
case .success(let response):
do {
let apiResponse = try decoder.decode(APIResponse<BlockedUsersPayload>.self, from: response.data)
let apiResponse = try decoder.decode(APIResponse<[BlockedUserPayload]>.self, from: response.data)
guard apiResponse.status == "fine" else {
let message = apiResponse.detail ?? NSLocalizedString("Не удалось загрузить список.", comment: "Blocked users service unexpected status")
completion(.failure(BlockedUsersServiceError.unexpectedStatus(message)))
@ -71,9 +73,9 @@ final class BlockedUsersService {
}
}
func fetchBlockedUsers(limit: Int, offset: Int) async throws -> BlockedUsersPayload {
func fetchBlockedUsers() async throws -> [BlockedUserPayload] {
try await withCheckedThrowingContinuation { continuation in
fetchBlockedUsers(limit: limit, offset: offset) { result in
fetchBlockedUsers { result in
continuation.resume(with: result)
}
}

View File

@ -94,9 +94,6 @@
},
"Email не подтверждён. Подтвердите, чтобы активировать дополнительные проверки." : {
"comment" : "Описание необходимости подтверждения email"
},
"error" : {
},
"Fun Fest" : {
"comment" : "Fun Fest",
@ -121,9 +118,6 @@
},
"Home" : {
},
"Login must not end with 'bot' for non-bot accounts" : {
},
"OK" : {
"comment" : "Common OK\nProfile update alert button\nОбщий текст кнопки OK",
@ -515,6 +509,9 @@
},
"Заблокировать контакт" : {
"comment" : "Contacts context action block"
},
"Заблокируйте аккаунт, чтобы скрыть его сообщения и взаимодействия" : {
},
"Завершить" : {
"comment" : "Кнопка завершения конкретной сессии\nПодтверждение завершения других сессий\nПодтверждение завершения конкретной сессии"

View File

@ -3,35 +3,56 @@ import SwiftUI
struct BlockedUsersView: View {
@State private var blockedUsers: [BlockedUser] = []
@State private var isLoading = false
@State private var hasMore = true
@State private var offset = 0
@State private var loadError: String?
@State private var pendingUnblock: BlockedUser?
@State private var showUnblockConfirmation = false
@State private var removingUserIds: Set<UUID> = []
@State private var activeAlert: ActiveAlert?
@State private var errorMessageDown: String?
private let blockedUsersService = BlockedUsersService()
private let limit = 20
var body: some View {
List {
if isLoading && blockedUsers.isEmpty {
initialLoadingState
loadingState
} else if let loadError, blockedUsers.isEmpty {
errorState(loadError)
} else if blockedUsers.isEmpty {
emptyState
} else {
usersSection
if isLoading {
Section {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
Section(header: Text(NSLocalizedString("Заблокированные", comment: ""))) {
ForEach(blockedUsers) { user in
HStack(spacing: 12) {
Circle()
.fill(Color.accentColor.opacity(0.15))
.frame(width: 44, height: 44)
.overlay(
Text(user.initials)
.font(.headline)
.foregroundColor(.accentColor)
)
VStack(alignment: .leading, spacing: 4) {
Text(user.displayName)
.font(.body)
if let handle = user.handle {
Text(handle)
.font(.caption)
.foregroundColor(.secondary)
}
}
Spacer()
}
.padding(.vertical, 4)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
pendingUnblock = user
showUnblockConfirmation = true
} label: {
Label(NSLocalizedString("Разблокировать", comment: ""), systemImage: "person.crop.circle.badge.xmark")
}
.disabled(removingUserIds.contains(user.id))
}
}
} else if errorMessageDown != nil{
Text("error")
}
}
}
@ -49,6 +70,9 @@ struct BlockedUsersView: View {
.task {
await loadBlockedUsers()
}
// .refreshable {
// await loadBlockedUsers()
// }
.alert(item: $activeAlert) { alert in
switch alert {
case .addPlaceholder:
@ -86,51 +110,6 @@ struct BlockedUsersView: View {
}
}
private var usersSection: some View {
Section(header: Text(NSLocalizedString("Заблокированные", comment: ""))) {
ForEach(blockedUsers) {
user in
HStack(spacing: 12) {
Circle()
.fill(Color.accentColor.opacity(0.15))
.frame(width: 44, height: 44)
.overlay(
Text(user.initials)
.font(.headline)
.foregroundColor(.accentColor)
)
VStack(alignment: .leading, spacing: 4) {
Text(user.displayName)
.font(.body)
if let handle = user.handle {
Text(handle)
.font(.caption)
.foregroundColor(.secondary)
}
}
Spacer()
}
.padding(.vertical, 0)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
pendingUnblock = user
showUnblockConfirmation = true
} label: {
Label(NSLocalizedString("Разблокировать", comment: ""), systemImage: "person.crop.circle.badge.xmark")
}
.disabled(removingUserIds.contains(user.id))
}
.onAppear {
if user.id == blockedUsers.last?.id {
Task {
await loadBlockedUsers()
}
}
}
}
}
}
private var emptyState: some View {
VStack(spacing: 12) {
Image(systemName: "hand.raised")
@ -139,6 +118,10 @@ struct BlockedUsersView: View {
Text(NSLocalizedString("У вас нет заблокированных пользователей", comment: ""))
.font(.headline)
.multilineTextAlignment(.center)
// Text(NSLocalizedString("Заблокируйте аккаунт, чтобы скрыть его сообщения и взаимодействия", comment: ""))
// .font(.subheadline)
// .foregroundColor(.secondary)
// .multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity, alignment: .center)
.padding(.vertical, 32)
@ -146,7 +129,7 @@ struct BlockedUsersView: View {
.listRowSeparator(.hidden)
}
private var initialLoadingState: some View {
private var loadingState: some View {
Section {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
@ -163,32 +146,23 @@ struct BlockedUsersView: View {
@MainActor
private func loadBlockedUsers() async {
errorMessageDown = nil
guard !isLoading, hasMore else {
if isLoading {
return
}
isLoading = true
defer { isLoading = false }
if offset == 0 {
loadError = nil
}
loadError = nil
do {
let payload = try await blockedUsersService.fetchBlockedUsers(limit: limit, offset: offset)
blockedUsers.append(contentsOf: payload.items.map(BlockedUser.init))
offset += payload.items.count
hasMore = payload.hasMore
let payloads = try await blockedUsersService.fetchBlockedUsers()
blockedUsers = payloads.map(BlockedUser.init)
} catch {
let message = error.localizedDescription
if offset == 0 {
loadError = message
}
activeAlert = .error(message: message)
errorMessageDown = message
loadError = error.localizedDescription
activeAlert = .error(message: error.localizedDescription)
if AppConfig.DEBUG { print("[BlockedUsersView] load blocked users failed: \(error)") }
}
isLoading = false
}
@MainActor
@ -237,7 +211,7 @@ private struct BlockedUser: Identifiable, Equatable {
return "??"
}
init(payload: BlockedUserInfo) {
init(payload: BlockedUserPayload) {
self.id = payload.userId
self.login = payload.login
self.fullName = payload.fullName