Residual coding

This commit is contained in:
Ali
2022-07-29 18:32:51 +02:00
parent 64076541cd
commit f6ad7dc77a
35 changed files with 2784 additions and 498 deletions

View File

@@ -873,7 +873,7 @@ private final class NotificationServiceHandler {
enum Action {
case logout
case poll(peerId: PeerId, content: NotificationContent)
case poll(peerId: PeerId, content: NotificationContent, messageId: MessageId?)
case deleteMessage([MessageId])
case readMessage(MessageId)
case call(CallData)
@@ -889,7 +889,7 @@ private final class NotificationServiceHandler {
action = .logout
case "MESSAGE_MUTED":
if let peerId = peerId {
action = .poll(peerId: peerId, content: NotificationContent(isLockedMessage: nil))
action = .poll(peerId: peerId, content: NotificationContent(isLockedMessage: nil), messageId: nil)
}
case "MESSAGE_DELETED":
if let peerId = peerId {
@@ -930,9 +930,12 @@ private final class NotificationServiceHandler {
return
}
var messageIdValue: MessageId?
if let messageId = messageId {
content.userInfo["msg_id"] = "\(messageId)"
interactionAuthorId = peerId
messageIdValue = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: messageId)
}
if peerId.namespace == Namespaces.Peer.CloudUser {
@@ -1021,7 +1024,7 @@ private final class NotificationServiceHandler {
}
}*/
action = .poll(peerId: peerId, content: content)
action = .poll(peerId: peerId, content: content, messageId: messageIdValue)
updateCurrentContent(content)
}
@@ -1066,7 +1069,7 @@ private final class NotificationServiceHandler {
let content = NotificationContent(isLockedMessage: nil)
updateCurrentContent(content)
completed()
case let .poll(peerId, initialContent):
case let .poll(peerId, initialContent, messageId):
Logger.shared.log("NotificationService \(episode)", "Will poll")
if let stateManager = strongSelf.stateManager {
let pollCompletion: (NotificationContent) -> Void = { content in
@@ -1325,12 +1328,31 @@ private final class NotificationServiceHandler {
}
let pollWithUpdatedContent: Signal<NotificationContent, NoError>
if let interactionAuthorId = interactionAuthorId {
if interactionAuthorId != nil || messageId != nil {
pollWithUpdatedContent = stateManager.postbox.transaction { transaction -> NotificationContent in
var content = initialContent
if inAppNotificationSettings.displayNameOnLockscreen, let peer = transaction.getPeer(interactionAuthorId) {
content.addSenderInfo(mediaBox: stateManager.postbox.mediaBox, accountPeerId: stateManager.accountPeerId, peer: peer)
if let interactionAuthorId = interactionAuthorId {
if inAppNotificationSettings.displayNameOnLockscreen, let peer = transaction.getPeer(interactionAuthorId) {
content.addSenderInfo(mediaBox: stateManager.postbox.mediaBox, accountPeerId: stateManager.accountPeerId, peer: peer)
}
}
if let messageId = messageId {
if let readState = transaction.getCombinedPeerReadState(messageId.peerId) {
for (namespace, state) in readState.states {
if namespace == messageId.namespace {
switch state {
case let .idBased(maxIncomingReadId, _, _, _, _):
if maxIncomingReadId >= messageId.id {
content = NotificationContent(isLockedMessage: nil)
}
case .indexBased:
break
}
}
}
}
}
return content