[WIP] General UI improvements

This commit is contained in:
Ali
2022-09-16 22:59:16 +04:00
parent f05031cc9d
commit ff22c7e981
34 changed files with 497 additions and 171 deletions

View File

@@ -464,7 +464,7 @@ private struct NotificationContent: CustomStringConvertible {
return string
}
mutating func addSenderInfo(mediaBox: MediaBox, accountPeerId: PeerId, peer: Peer) {
mutating func addSenderInfo(mediaBox: MediaBox, accountPeerId: PeerId, peer: Peer, contactIdentifier: String?) {
if #available(iOS 15.0, *) {
let image = peerAvatar(mediaBox: mediaBox, accountPeerId: accountPeerId, peer: peer)
@@ -483,7 +483,7 @@ private struct NotificationContent: CustomStringConvertible {
nameComponents: personNameComponents,
displayName: displayName,
image: image,
contactIdentifier: nil,
contactIdentifier: contactIdentifier,
customIdentifier: "\(peer.id.toInt64())",
isMe: false,
suggestionType: .none
@@ -818,6 +818,7 @@ private final class NotificationServiceHandler {
var updates: String
var accountId: Int64
var peer: EnginePeer?
var localContactId: String?
}
var callData: CallData?
@@ -1033,35 +1034,51 @@ private final class NotificationServiceHandler {
if let action = action {
switch action {
case let .call(callData):
let voipPayload: [AnyHashable: Any] = [
"call_id": "\(callData.id)",
"call_ah": "\(callData.accessHash)",
"from_id": "\(callData.fromId.id._internalGetInt64Value())",
"updates": callData.updates,
"accountId": "\(callData.accountId)"
]
if #available(iOS 14.5, *), voiceCallSettings.enableSystemIntegration {
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
if let stateManager = strongSelf.stateManager {
let content = NotificationContent(isLockedMessage: nil)
updateCurrentContent(content)
CXProvider.reportNewIncomingVoIPPushPayload(voipPayload, completion: { error in
Logger.shared.log("NotificationService \(episode)", "Did report voip notification, error: \(String(describing: error))")
let _ = (stateManager.postbox.transaction { transaction -> String? in
if let peer = transaction.getPeer(callData.fromId) as? TelegramUser {
return peer.phone
} else {
return nil
}
}).start(next: { phoneNumber in
var voipPayload: [AnyHashable: Any] = [
"call_id": "\(callData.id)",
"call_ah": "\(callData.accessHash)",
"from_id": "\(callData.fromId.id._internalGetInt64Value())",
"updates": callData.updates,
"accountId": "\(callData.accountId)"
]
if let phoneNumber = phoneNumber {
voipPayload["phoneNumber"] = phoneNumber
}
completed()
if #available(iOS 14.5, *), voiceCallSettings.enableSystemIntegration {
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
let content = NotificationContent(isLockedMessage: nil)
updateCurrentContent(content)
CXProvider.reportNewIncomingVoIPPushPayload(voipPayload, completion: { error in
Logger.shared.log("NotificationService \(episode)", "Did report voip notification, error: \(String(describing: error))")
completed()
})
} else {
var content = NotificationContent(isLockedMessage: nil)
if let peer = callData.peer {
content.title = peer.debugDisplayTitle
content.body = incomingCallMessage
} else {
content.body = "Incoming Call"
}
updateCurrentContent(content)
completed()
}
})
} else {
var content = NotificationContent(isLockedMessage: nil)
if let peer = callData.peer {
content.title = peer.debugDisplayTitle
content.body = incomingCallMessage
} else {
content.body = "Incoming Call"
}
updateCurrentContent(content)
completed()
}
case .logout:
Logger.shared.log("NotificationService \(episode)", "Will logout")
@@ -1334,7 +1351,23 @@ private final class NotificationServiceHandler {
if let interactionAuthorId = interactionAuthorId {
if inAppNotificationSettings.displayNameOnLockscreen, let peer = transaction.getPeer(interactionAuthorId) {
content.addSenderInfo(mediaBox: stateManager.postbox.mediaBox, accountPeerId: stateManager.accountPeerId, peer: peer)
var foundLocalId: String?
transaction.enumerateDeviceContactImportInfoItems({ _, value in
if let value = value as? TelegramDeviceContactImportedData {
switch value {
case let .imported(data, _, peerId):
if peerId == interactionAuthorId {
foundLocalId = data.localIdentifiers.first
return false
}
default:
break
}
}
return true
})
content.addSenderInfo(mediaBox: stateManager.postbox.mediaBox, accountPeerId: stateManager.accountPeerId, peer: peer, contactIdentifier: foundLocalId)
}
}