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