patch msg
This commit is contained in:
parent
4a045ac140
commit
3b1b2f3282
@ -280,6 +280,9 @@
|
|||||||
"Блокировка контакта \"%1$@\" появится позже." : {
|
"Блокировка контакта \"%1$@\" появится позже." : {
|
||||||
"comment" : "Contacts block placeholder message"
|
"comment" : "Contacts block placeholder message"
|
||||||
},
|
},
|
||||||
|
"Больше сообщений нет" : {
|
||||||
|
"comment" : "Chat history top reached"
|
||||||
|
},
|
||||||
"Бот" : {
|
"Бот" : {
|
||||||
"comment" : "Тип сессии — бот"
|
"comment" : "Тип сессии — бот"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -7,13 +7,13 @@ final class PrivateChatViewModel: ObservableObject {
|
|||||||
@Published private(set) var isLoadingMore: Bool = false
|
@Published private(set) var isLoadingMore: Bool = false
|
||||||
@Published var errorMessage: String?
|
@Published var errorMessage: String?
|
||||||
@Published private(set) var isSending: Bool = false
|
@Published private(set) var isSending: Bool = false
|
||||||
|
@Published private(set) var hasMore: Bool = true
|
||||||
|
|
||||||
private let chatService: ChatService
|
private let chatService: ChatService
|
||||||
private let chatId: String
|
private let chatId: String
|
||||||
private let currentUserId: String?
|
private let currentUserId: String?
|
||||||
private let pageSize: Int
|
private let pageSize: Int
|
||||||
private let maxMessageLength: Int = 4096
|
private let maxMessageLength: Int = 4096
|
||||||
private var hasMore: Bool = true
|
|
||||||
private var didLoadInitially: Bool = false
|
private var didLoadInitially: Bool = false
|
||||||
private var messageObserver: NSObjectProtocol?
|
private var messageObserver: NSObjectProtocol?
|
||||||
|
|
||||||
@ -127,11 +127,21 @@ final class PrivateChatViewModel: ObservableObject {
|
|||||||
|
|
||||||
func loadMoreIfNeeded(for message: MessageItem) {
|
func loadMoreIfNeeded(for message: MessageItem) {
|
||||||
guard didLoadInitially, !isInitialLoading, hasMore, !isLoadingMore else { return }
|
guard didLoadInitially, !isInitialLoading, hasMore, !isLoadingMore else { return }
|
||||||
guard let first = messages.first, first.id == message.id else { return }
|
|
||||||
|
guard let messageIndex = messages.firstIndex(where: { $0.id == message.id }) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let threshold = 10
|
||||||
|
guard messageIndex < threshold else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let oldestMessage = messages.first else { return }
|
||||||
|
|
||||||
isLoadingMore = true
|
isLoadingMore = true
|
||||||
|
|
||||||
chatService.fetchPrivateChatHistory(chatId: chatId, beforeMessageId: message.id, limit: pageSize) { [weak self] result in
|
chatService.fetchPrivateChatHistory(chatId: chatId, beforeMessageId: oldestMessage.id, limit: pageSize) { [weak self] result in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
switch result {
|
switch result {
|
||||||
|
|||||||
@ -153,6 +153,9 @@ struct PrivateChatView: View {
|
|||||||
if viewModel.isLoadingMore {
|
if viewModel.isLoadingMore {
|
||||||
loadingMoreView
|
loadingMoreView
|
||||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||||
|
} else if !viewModel.hasMore && !viewModel.messages.isEmpty {
|
||||||
|
noMoreMessagesView
|
||||||
|
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||||
} else if viewModel.messages.isEmpty {
|
} else if viewModel.messages.isEmpty {
|
||||||
emptyState
|
emptyState
|
||||||
.scaleEffect(x: 1, y: -1, anchor: .center)
|
.scaleEffect(x: 1, y: -1, anchor: .center)
|
||||||
@ -187,6 +190,14 @@ struct PrivateChatView: View {
|
|||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var noMoreMessagesView: some View {
|
||||||
|
Text(NSLocalizedString("Больше сообщений нет", comment: "Chat history top reached"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.vertical, 16)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
|
||||||
private func errorView(message: String) -> some View {
|
private func errorView(message: String) -> some View {
|
||||||
VStack(spacing: 12) {
|
VStack(spacing: 12) {
|
||||||
Text(message)
|
Text(message)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user