Various fixes

This commit is contained in:
Ilya Laktyushin 2024-12-28 21:53:53 +04:00
parent f223dabbc2
commit 7efcdb4b8e
10 changed files with 115 additions and 68 deletions

View File

@ -795,12 +795,12 @@ private final class NotificationServiceHandler {
var recordId: AccountRecordId?
var isCurrentAccount: Bool = false
var automaticMediaDownloadSettings: MediaAutoDownloadSettings
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
automaticMediaDownloadSettings = value
} else {
automaticMediaDownloadSettings = MediaAutoDownloadSettings.defaultSettings
}
// var automaticMediaDownloadSettings: MediaAutoDownloadSettings
// if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
// automaticMediaDownloadSettings = value
// } else {
// automaticMediaDownloadSettings = MediaAutoDownloadSettings.defaultSettings
// }
let shouldSynchronizeState = true//automaticMediaDownloadSettings.energyUsageSettings.synchronizeInBackground
if let keyId = notificationPayloadKeyId(data: payloadData) {
@ -1186,7 +1186,7 @@ private final class NotificationServiceHandler {
action = .pollStories(peerId: peerId, content: content, storyId: storyId, isReaction: isReaction)
} else {
var reportDelivery = false
if let reportDeliveryUntilDate = aps["report_delivery_until_date"] as? Int32, let messageId = messageIdValue {
if let reportDeliveryUntilDate = aps["report_delivery_until_date"] as? Int32 {
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
if reportDeliveryUntilDate > currentTime {
reportDelivery = true
@ -1696,9 +1696,6 @@ private final class NotificationServiceHandler {
let reportDeliverySignal: Signal<Bool, NoError>
if reportDelivery, let messageId {
reportDeliverySignal = _internal_reportMessageDelivery(postbox: stateManager.postbox, network: stateManager.network, messageIds: [messageId], fromPushNotification: true)
|> mapToSignal { _ -> Signal<Bool, NoError> in
return .single(true)
}
|> then(.single(true))
} else {
reportDeliverySignal = .single(true)

View File

@ -263,6 +263,8 @@
"PUSH_MESSAGE_WALLPAPER" = "%1$@ set a new wallpaper for the chat with you";
"PUSH_MESSAGE_SAME_WALLPAPER" = "%1$@ set the same wallpaper for the chat with you";
"PUSH_MESSAGE_UNIQUE_STARGIFT" = "%1$@ sent you a Gift";
"PUSH_REMINDER_TITLE" = "🗓 Reminder";
"PUSH_SENDER_YOU" = "📅 You";
@ -13532,7 +13534,7 @@ Sorry for the inconvenience.";
"Gift.Transfer.Confirmation.Transfer" = "Transfer for";
"Gift.Transfer.Confirmation.TransferFree" = "Transfer";
"Gift.Transfer.Success" = "You have successfully gifter **%1$@** to **%2$@**.";
"Gift.Transfer.Success" = "You have successfully gifted **%1$@** to **%2$@**.";
"Gift.View.UpgradeForFree" = "Upgrade for Free";
"Gift.View.KeepUpgradeOrConvertDescription" = "You can keep this gift, upgrade it, or sell it for %@. [More About Stars >]()";
@ -13571,6 +13573,7 @@ Sorry for the inconvenience.";
"Notification.StarsGift.Upgrade" = "%@ turned the gift from you to a unique collectible";
"Notification.StarsGift.UpgradeYou" = "You turned the gift from %@ to a unique collectible";
"Notification.StarsGift.UpgradeSelf" = "You turned the gift to a unique collectible";
"Notification.StarsGift.Transfer" = "%@ transferred you a unique collectible";
"Notification.StarsGift.TransferYou" = "You transferred a unique collectible";
@ -13605,8 +13608,8 @@ Sorry for the inconvenience.";
"Gift.SendSelf.HideMyName.Info" = "Hide my name and message from visitors to my profile.";
"Notification.StarGift.Self.Title" = "Saved Gift";
"Notification.StarGift.Self.Bought" = "You bought a gift for %@";
"Notification.StarGift.Self.Bought" = "You can display this gift on your page or turn it into a unique collectible and send to others.";
"Notification.StarsGift.Self.Bought" = "You bought a gift for %@";
"Notification.StarsGift.Subtitle.Self" = "You can display this gift on your page or turn it into a unique collectible and send to others.";
"Gift.View.Self.Title" = "Saved Gift";
"Gift.View.Self.Description" = "You can display this gift on your page or turn it into a unique collectible and send to others.";
@ -13637,3 +13640,6 @@ Sorry for the inconvenience.";
"Premium.Gift.ContactSelection.ThisIsYou" = "THIS IS YOU";
"Premium.Gift.ContactSelection.BuySelf" = "buy yourself a gift";
"Gift.View.Outgoing.NameHidden" = "Only %@ can see your name.";
"Gift.View.Outgoing.NameAndMessageHidden" = "Only %@ can see your name and message.";

View File

@ -3,13 +3,15 @@ import Postbox
import SwiftSignalKit
import TelegramApi
public func _internal_reportMessageDelivery(postbox: Postbox, network: Network, messageIds: [EngineMessage.Id], fromPushNotification: Bool) -> Signal<Never, NoError> {
public func _internal_reportMessageDelivery(postbox: Postbox, network: Network, messageIds: [EngineMessage.Id], fromPushNotification: Bool) -> Signal<Bool, NoError> {
var signals: [Signal<Void, NoError>] = []
for (peerId, messageIds) in messagesIdsGroupedByPeerId(messageIds) {
signals.append(_internal_reportMessageDeliveryByPeerId(postbox: postbox, network: network, peerId: peerId, messageIds: messageIds, fromPushNotification: fromPushNotification))
}
return combineLatest(signals)
|> ignoreValues
|> mapToSignal { _ in
return .single(true)
}
}
private func _internal_reportMessageDeliveryByPeerId(postbox: Postbox, network: Network, peerId: EnginePeer.Id, messageIds: [EngineMessage.Id], fromPushNotification: Bool) -> Signal<Void, NoError> {

View File

@ -1086,7 +1086,9 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
authorName = strings.Notification_StarsGift_UnknownUser
peerIds = []
}
if message.author?.id == accountPeerId {
if message.id.peerId == accountPeerId {
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Self_Bought(starsPrice)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
} else if message.author?.id == accountPeerId {
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(starsPrice)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
} else {
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
@ -1102,7 +1104,9 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
let peerName = EnginePeer(messagePeer).compactDisplayTitle
let peerIds: [(Int, EnginePeer.Id?)] = [(0, messagePeer.id)]
if isUpgrade {
if message.author?.id == accountPeerId {
if message.id.peerId == accountPeerId {
attributedString = NSAttributedString(string: strings.Notification_StarsGift_UpgradeSelf, font: titleFont, textColor: primaryTextColor)
} else if message.author?.id == accountPeerId {
let attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_UpgradeYou(peerName)._tuple, body: bodyAttributes, argumentAttributes: attributes)
} else {

View File

@ -466,7 +466,13 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if case let .generic(gift) = gift {
isStarGift = true
let authorName = item.message.author.flatMap { EnginePeer($0) }?.compactDisplayTitle ?? ""
title = item.presentationData.strings.Notification_StarGift_Title(authorName).string
let isSelfGift = item.message.id.peerId == item.context.account.peerId
if isSelfGift {
title = item.presentationData.strings.Notification_StarGift_Self_Title
} else {
title = item.presentationData.strings.Notification_StarGift_Title(authorName).string
}
if let giftText, !giftText.isEmpty {
text = giftText
entities = giftEntities ?? []
@ -480,6 +486,8 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
text = item.presentationData.strings.Notification_StarGift_Subtitle_Converted(item.presentationData.strings.Notification_StarGift_Subtitle_Converted_Stars(Int32(convertStars ?? 0))).string
} else if upgradeStars != nil {
text = item.presentationData.strings.Notification_StarGift_Subtitle_Upgrade
} else if isSelfGift {
text = item.presentationData.strings.Notification_StarsGift_Subtitle_Self
} else if savedToProfile {
if let convertStars {
text = item.presentationData.strings.Notification_StarGift_Subtitle_Displaying(item.presentationData.strings.Notification_StarGift_Subtitle_Displaying_Stars(Int32(convertStars))).string

View File

@ -31,6 +31,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
let accountPeer: EnginePeer?
let subject: ChatGiftPreviewItem.Subject
let isSelf: Bool
let text: String
let entities: [MessageTextEntity]
let includeUpgrade: Bool
@ -48,6 +49,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
nameDisplayOrder: PresentationPersonNameOrder,
accountPeer: EnginePeer?,
subject: ChatGiftPreviewItem.Subject,
isSelf: Bool,
text: String,
entities: [MessageTextEntity],
includeUpgrade: Bool
@ -64,6 +66,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
self.nameDisplayOrder = nameDisplayOrder
self.accountPeer = accountPeer
self.subject = subject
self.isSelf = isSelf
self.text = text
self.entities = entities
self.includeUpgrade = includeUpgrade
@ -206,6 +209,10 @@ final class ChatGiftPreviewItemNode: ListViewItemNode {
let separatorHeight = UIScreenPixel
let peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(1))
var chatPeerId = peerId
if item.isSelf {
chatPeerId = item.accountPeer?.id ?? chatPeerId
}
var items: [ListViewItem] = []
for _ in 0 ..< 1 {
@ -232,7 +239,7 @@ final class ChatGiftPreviewItemNode: ListViewItemNode {
]
}
let message = Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], customTags: [], forwardInfo: nil, author: peers[authorPeerId], text: "", attributes: [], media: media, peers: peers, associatedMessages: messages, associatedMessageIds: [], associatedMedia: [:], associatedThreadInfo: nil, associatedStories: [:])
let message = Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: chatPeerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], customTags: [], forwardInfo: nil, author: peers[authorPeerId], text: "", attributes: [], media: media, peers: peers, associatedMessages: messages, associatedMessageIds: [], associatedMedia: [:], associatedThreadInfo: nil, associatedStories: [:])
items.append(item.context.sharedContext.makeChatMessagePreviewItem(context: item.context, messages: [message], theme: item.componentTheme, strings: item.strings, wallpaper: item.wallpaper, fontSize: item.fontSize, chatBubbleCorners: item.chatBubbleCorners, dateTimeFormat: item.dateTimeFormat, nameOrder: item.nameDisplayOrder, forcedResourceStatus: nil, tapMessage: nil, clickThroughMessage: nil, backgroundNode: currentBackgroundNode, availableReactions: nil, accountPeer: nil, isCentered: false, isPreview: true, isStandalone: false))
}

View File

@ -819,6 +819,7 @@ final class GiftSetupScreenComponent: Component {
nameDisplayOrder: presentationData.nameDisplayOrder,
accountPeer: accountPeer,
subject: subject,
isSelf: component.peerId == component.context.account.peerId,
text: self.textInputState.text.string,
entities: generateChatInputTextEntities(self.textInputState.text),
includeUpgrade: self.includeUpgrade

View File

@ -382,6 +382,8 @@ private final class GiftViewSheetContent: CombinedComponent {
var canUpgrade = false
var upgradeStars: Int64?
var uniqueGift: StarGift.UniqueGift?
var isSelfGift = false
if case let .soldOutGift(gift) = subject {
animationFile = gift.file
stars = gift.price
@ -417,7 +419,14 @@ private final class GiftViewSheetContent: CombinedComponent {
savedToProfile = arguments.savedToProfile
incoming = arguments.incoming || arguments.peerId == component.context.account.peerId
nameHidden = arguments.nameHidden
titleString = incoming ? strings.Gift_View_ReceivedTitle : strings.Gift_View_Title
isSelfGift = arguments.messageId?.peerId == component.context.account.peerId
if isSelfGift {
titleString = strings.Gift_View_Self_Title
} else {
titleString = incoming ? strings.Gift_View_ReceivedTitle : strings.Gift_View_Title
}
} else {
animationFile = nil
stars = 0
@ -839,13 +848,22 @@ private final class GiftViewSheetContent: CombinedComponent {
originY += 21.0
}
if nameHidden && incoming && uniqueGift == nil {
if nameHidden && uniqueGift == nil {
let textFont = Font.regular(13.0)
let textColor = theme.list.itemSecondaryTextColor
let hiddenDescription: String
if incoming {
hiddenDescription = text != nil ? strings.Gift_View_NameAndMessageHidden : strings.Gift_View_NameHidden
} else if let peerId = subject.arguments?.peerId, let peer = state.peerMap[peerId] {
hiddenDescription = text != nil ? strings.Gift_View_Outgoing_NameAndMessageHidden(peer.compactDisplayTitle).string : strings.Gift_View_Outgoing_NameHidden(peer.compactDisplayTitle).string
} else {
hiddenDescription = ""
}
let hiddenText = hiddenText.update(
component: MultilineTextComponent(
text: .plain(NSAttributedString(string: text != nil ? strings.Gift_View_NameAndMessageHidden : strings.Gift_View_NameHidden, font: textFont, textColor: textColor)),
text: .plain(NSAttributedString(string: hiddenDescription, font: textFont, textColor: textColor)),
horizontalAlignment: .center,
maximumNumberOfLines: 2,
lineSpacing: 0.2
@ -1003,24 +1021,28 @@ private final class GiftViewSheetContent: CombinedComponent {
}
))
}
tableItems.append(.init(
id: "from",
title: strings.Gift_View_From,
component: fromComponent
))
if !isSelfGift {
tableItems.append(.init(
id: "from",
title: strings.Gift_View_From,
component: fromComponent
))
}
} else {
tableItems.append(.init(
id: "from_anon",
title: strings.Gift_View_From,
component: AnyComponent(
PeerCellComponent(
context: component.context,
theme: theme,
strings: strings,
peer: nil
if !isSelfGift {
tableItems.append(.init(
id: "from_anon",
title: strings.Gift_View_From,
component: AnyComponent(
PeerCellComponent(
context: component.context,
theme: theme,
strings: strings,
peer: nil
)
)
)
))
))
}
}
}

View File

@ -1622,18 +1622,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
}))
}
if user.isVerified {
let description = presentationData.strings.PeerInfo_VerificationInfo_Bot
let attributedPrefix = NSMutableAttributedString(string: " ")
attributedPrefix.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .verification), range: NSMakeRange(0, 1))
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: description, attributedPrefix: attributedPrefix, useAccentLinkColor: false, linkAction: { action in
if case .tap = action, let navigationController = interaction.getController()?.navigationController as? NavigationController {
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: presentationData.strings.PeerInfo_VerificationInfo_URL, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
} else if let verification = (data.cachedData as? CachedUserData)?.verification {
if let verification = (data.cachedData as? CachedUserData)?.verification {
let description: String
let descriptionString = verification.description
let entities = generateTextEntities(descriptionString, enabledTypes: [.allUrl])
@ -1652,6 +1641,17 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: url, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
} else if user.isVerified {
let description = presentationData.strings.PeerInfo_VerificationInfo_Bot
let attributedPrefix = NSMutableAttributedString(string: " ")
attributedPrefix.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .verification), range: NSMakeRange(0, 1))
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: description, attributedPrefix: attributedPrefix, useAccentLinkColor: false, linkAction: { action in
if case .tap = action, let navigationController = interaction.getController()?.navigationController as? NavigationController {
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: presentationData.strings.PeerInfo_VerificationInfo_URL, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
} else if let botInfo = user.botInfo, botInfo.flags.contains(.worksWithGroups) {
items[currentPeerInfoSection]!.append(PeerInfoScreenActionItem(id: 7, text: presentationData.strings.Bot_AddToChat, color: .accent, action: {
interaction.openAddBotToGroup()
@ -1801,23 +1801,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
}))
}
if channel.isVerified {
let description: String
if case .group = channel.info {
description = presentationData.strings.PeerInfo_VerificationInfo_Group
} else {
description = presentationData.strings.PeerInfo_VerificationInfo_Channel
}
let attributedPrefix = NSMutableAttributedString(string: " ")
attributedPrefix.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .verification), range: NSMakeRange(0, 1))
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: description, attributedPrefix: attributedPrefix, useAccentLinkColor: false, linkAction: { action in
if case .tap = action, let navigationController = interaction.getController()?.navigationController as? NavigationController {
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: presentationData.strings.PeerInfo_VerificationInfo_URL, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
} else if let verification = (data.cachedData as? CachedChannelData)?.verification {
if let verification = (data.cachedData as? CachedChannelData)?.verification {
let description: String
let descriptionString = verification.description
let entities = generateTextEntities(descriptionString, enabledTypes: [.allUrl])
@ -1837,6 +1821,22 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: url, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
} else if channel.isVerified {
let description: String
if case .group = channel.info {
description = presentationData.strings.PeerInfo_VerificationInfo_Group
} else {
description = presentationData.strings.PeerInfo_VerificationInfo_Channel
}
let attributedPrefix = NSMutableAttributedString(string: " ")
attributedPrefix.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .verification), range: NSMakeRange(0, 1))
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: description, attributedPrefix: attributedPrefix, useAccentLinkColor: false, linkAction: { action in
if case .tap = action, let navigationController = interaction.getController()?.navigationController as? NavigationController {
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: presentationData.strings.PeerInfo_VerificationInfo_URL, forceExternal: false, presentationData: presentationData, navigationController: navigationController, dismissInput: {})
}
}))
}
if case .broadcast = channel.info {

View File

@ -2501,7 +2501,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
Queue.mainQueue().after(0.3) {
let tooltipController = UndoOverlayController(
presentationData: presentationData,
content: .forward(savedMessages: false, text: presentationData.strings.Gift_Transfer_Success("\(gift) #\(gift.number)", peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string),
content: .forward(savedMessages: false, text: presentationData.strings.Gift_Transfer_Success("\(gift.title) #\(gift.number)", peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string),
elevatedLayout: false,
action: { _ in return true }
)