wip
This commit is contained in:
parent
02801e46b4
commit
e6b3d856a7
|
@ -45,16 +45,30 @@ struct MessageAttr: View {
|
|||
.foregroundColor(.Material.Shape.separator)
|
||||
}
|
||||
|
||||
// message state commented for now
|
||||
// if message.status == .error {
|
||||
// Image(systemName: "exclamationmark.circle")
|
||||
// .font(.body3)
|
||||
// .foregroundColor(.Rainbow.red500)
|
||||
// } else if message.status == .pending {
|
||||
// Image(systemName: "clock")
|
||||
// .font(.body3)
|
||||
// .foregroundColor(.Material.Shape.separator)
|
||||
// }
|
||||
switch message.status {
|
||||
case .sent:
|
||||
Image(systemName: "checkmark")
|
||||
.font(.body3)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
|
||||
case .delivered:
|
||||
HStack {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.body3)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
Image(systemName: "checkmark")
|
||||
.font(.body3)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
}
|
||||
|
||||
case .error:
|
||||
Image(systemName: "exclamationmark.circle")
|
||||
.font(.body3)
|
||||
.foregroundColor(.Rainbow.red500)
|
||||
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
import Foundation
|
||||
import monalxmpp
|
||||
|
||||
enum MessageStatus {
|
||||
case pending
|
||||
case sent
|
||||
case delivered
|
||||
case error
|
||||
case inbound
|
||||
}
|
||||
|
||||
struct Message: Identifiable {
|
||||
let accountId: Int
|
||||
let participantJid: String
|
||||
|
@ -10,6 +18,7 @@ struct Message: Identifiable {
|
|||
let body: String
|
||||
let isInbound: Bool
|
||||
let encrypted: Bool
|
||||
let status: MessageStatus
|
||||
|
||||
var id: String {
|
||||
"\(accountId)|\(dbId)"
|
||||
|
@ -25,5 +34,19 @@ struct Message: Identifiable {
|
|||
body = obj.messageText
|
||||
isInbound = obj.inbound
|
||||
encrypted = obj.encrypted
|
||||
|
||||
if !obj.inbound {
|
||||
if obj.hasBeenSent {
|
||||
status = .sent
|
||||
} else if obj.hasBeenReceived {
|
||||
status = .delivered
|
||||
} else if !obj.errorType.isEmpty {
|
||||
status = .error
|
||||
} else {
|
||||
status = .pending
|
||||
}
|
||||
} else {
|
||||
status = .inbound
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ final class WrapperChat: ObservableObject {
|
|||
acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
||||
self?.mamRequestInProgress = false
|
||||
print(msgs)
|
||||
print(msgs ?? [])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,8 @@ private extension WrapperChat {
|
|||
func subscribe() {
|
||||
let notificationNames = [
|
||||
kMonalNewMessageNotice,
|
||||
kMonalHistoryMessagesNotice
|
||||
kMonalHistoryMessagesNotice,
|
||||
kMonalMessageDisplayedNotice
|
||||
]
|
||||
notificationObservers = notificationNames.map { name in
|
||||
NotificationCenter.default.addObserver(forName: Notification.Name(name), object: nil, queue: .main) { [weak self] notification in
|
||||
|
@ -132,10 +133,13 @@ private extension WrapperChat {
|
|||
}
|
||||
|
||||
func processEvent(notification: Notification) {
|
||||
switch notification.name.rawValue {
|
||||
default:
|
||||
break
|
||||
if let mlMessage = notification.userInfo?["message"] {
|
||||
print("AAAAAAAAAA", mlMessage)
|
||||
}
|
||||
// switch notification.name.rawValue {
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
}
|
||||
|
||||
func reloadMessages() {
|
||||
|
|
Loading…
Reference in a new issue