patch msg

This commit is contained in:
cheykrym 2025-12-11 21:15:45 +03:00
parent 4a045ac140
commit 3b1b2f3282
3 changed files with 27 additions and 3 deletions

View File

@ -280,6 +280,9 @@
"Блокировка контакта \"%1$@\" появится позже." : {
"comment" : "Contacts block placeholder message"
},
"Больше сообщений нет" : {
"comment" : "Chat history top reached"
},
"Бот" : {
"comment" : "Тип сессии — бот"
},

View File

@ -7,13 +7,13 @@ final class PrivateChatViewModel: ObservableObject {
@Published private(set) var isLoadingMore: Bool = false
@Published var errorMessage: String?
@Published private(set) var isSending: Bool = false
@Published private(set) var hasMore: Bool = true
private let chatService: ChatService
private let chatId: String
private let currentUserId: String?
private let pageSize: Int
private let maxMessageLength: Int = 4096
private var hasMore: Bool = true
private var didLoadInitially: Bool = false
private var messageObserver: NSObjectProtocol?
@ -127,11 +127,21 @@ final class PrivateChatViewModel: ObservableObject {
func loadMoreIfNeeded(for message: MessageItem) {
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
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 }
switch result {

View File

@ -153,6 +153,9 @@ struct PrivateChatView: View {
if viewModel.isLoadingMore {
loadingMoreView
.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 {
emptyState
.scaleEffect(x: 1, y: -1, anchor: .center)
@ -187,6 +190,14 @@ struct PrivateChatView: View {
.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 {
VStack(spacing: 12) {
Text(message)