wip
This commit is contained in:
parent
cbe67fe3f1
commit
b4a708ffad
|
@ -59,20 +59,21 @@ struct MessageAttr: View {
|
|||
.foregroundColor(.Material.Shape.separator)
|
||||
|
||||
case .delivered:
|
||||
HStack {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.sub1)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
Image(systemName: "checkmark")
|
||||
.font(.sub1)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
}
|
||||
let img = Image(systemName: "checkmark")
|
||||
Text("\(img)\(img)")
|
||||
.font(.sub1)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
|
||||
case .error:
|
||||
Image(systemName: "exclamationmark.circle")
|
||||
.font(.sub1)
|
||||
.foregroundColor(.Rainbow.red500)
|
||||
|
||||
case .pending:
|
||||
Image(systemName: "clock")
|
||||
.font(.sub1)
|
||||
.foregroundColor(.Material.Shape.separator)
|
||||
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
|
|
|
@ -35,18 +35,22 @@ struct Message: Identifiable {
|
|||
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 {
|
||||
if obj.inbound {
|
||||
status = .inbound
|
||||
} else {
|
||||
if obj.hasBeenReceived {
|
||||
status = .delivered
|
||||
} else if obj.hasBeenSent {
|
||||
status = .sent
|
||||
} else {
|
||||
if !obj.errorReason.isEmpty {
|
||||
status = .error
|
||||
} else {
|
||||
status = .pending
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print("AAAAAA", body, status, "\n", "orig: ", obj.hasBeenReceived, obj.hasBeenSent, " id:", dbId, " stanza:", stanzaId)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ final class WrapperChat: ObservableObject {
|
|||
if let newMlMessage = db.message(forHistoryID: histId), let message = Message(newMlMessage) {
|
||||
messages.insert(message, at: 0)
|
||||
}
|
||||
print("CCCCC", newMessageId)
|
||||
xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId)
|
||||
}
|
||||
|
||||
|
@ -125,6 +126,9 @@ private extension WrapperChat {
|
|||
let notificationNames = [
|
||||
kMonalNewMessageNotice,
|
||||
kMonalHistoryMessagesNotice,
|
||||
kMonalMessageDisplayedNotice,
|
||||
kMonalMessageErrorNotice,
|
||||
kMonalSentMessageNotice,
|
||||
kMonalMessageDisplayedNotice
|
||||
]
|
||||
notificationObservers = notificationNames.map { name in
|
||||
|
@ -135,13 +139,23 @@ private extension WrapperChat {
|
|||
}
|
||||
|
||||
func processEvent(notification: Notification) {
|
||||
guard let mlMessage = notification.userInfo?["message"] as? MLMessage else { return }
|
||||
guard let message = Message(mlMessage) else { return }
|
||||
if let index = messages.firstIndex(where: { $0.id == message.id }) {
|
||||
messages[index] = message
|
||||
} else {
|
||||
messages.append(message)
|
||||
messages.sort { $0.timestamp > $1.timestamp }
|
||||
switch notification.name.rawValue {
|
||||
case kMonalSentMessageNotice:
|
||||
if let stanza = notification.userInfo?["message"] as? XMPPStanza, let id = stanza.id {
|
||||
if let index = messages.firstIndex(where: { $0.stanzaId == id }) {
|
||||
print(index)
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
guard let mlMessage = notification.userInfo?["message"] as? MLMessage else { return }
|
||||
guard let message = Message(mlMessage) else { return }
|
||||
if let index = messages.firstIndex(where: { $0.id == message.id }) {
|
||||
messages[index] = message
|
||||
} else {
|
||||
messages.append(message)
|
||||
messages.sort { $0.timestamp > $1.timestamp }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue