Skip to content

Commit 46d9465

Browse files
author
Isaac
committed
Chat list notices
1 parent b92293e commit 46d9465

File tree

12 files changed

+98
-115
lines changed

12 files changed

+98
-115
lines changed

submodules/ChatListUI/Sources/ChatListController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,13 +2501,13 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
25012501
guard let strongSelf = self else {
25022502
return
25032503
}
2504-
strongSelf.dismissAutoarchiveDisposable.set(strongSelf.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .autoarchivePopular).startStrict())
2504+
strongSelf.dismissAutoarchiveDisposable.set(strongSelf.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.autoarchivePopular.id).startStrict())
25052505
}),
25062506
TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.ChatList_AutoarchiveSuggestion_OpenSettings, action: {
25072507
guard let strongSelf = self else {
25082508
return
25092509
}
2510-
strongSelf.dismissAutoarchiveDisposable.set(strongSelf.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .autoarchivePopular).startStrict())
2510+
strongSelf.dismissAutoarchiveDisposable.set(strongSelf.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.autoarchivePopular.id).startStrict())
25112511
strongSelf.push(strongSelf.context.sharedContext.makePrivacyAndSecurityController(context: strongSelf.context))
25122512
})
25132513
], actionLayout: .vertical, parseMarkdown: true), in: .window(.root))
@@ -6114,7 +6114,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
61146114

61156115
func openBirthdaySetup() {
61166116
let context = self.context
6117-
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: .setupBirthday).startStandalone()
6117+
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupBirthday.id).startStandalone()
61186118

61196119
let settingsPromise: Promise<AccountPrivacySettings?>
61206120
if let rootController = self.context.sharedContext.mainWindow?.viewController as? TelegramRootControllerInterface, let current = rootController.getPrivacySettings() {

submodules/ChatListUI/Sources/Node/ChatListNode.swift

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
778778
nodeInteraction?.openPhotoSetup()
779779
case .accountFreeze:
780780
nodeInteraction?.openAccountFreezeInfo()
781-
case let .link(url, _, _):
781+
case let .link(_, url, _, _):
782782
nodeInteraction?.openUrl(url)
783783
}
784784
case .hide:
@@ -1128,7 +1128,7 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
11281128
nodeInteraction?.openPhotoSetup()
11291129
case .accountFreeze:
11301130
nodeInteraction?.openAccountFreezeInfo()
1131-
case let .link(url, _, _):
1131+
case let .link(_, url, _, _):
11321132
nodeInteraction?.openUrl(url)
11331133
}
11341134
case .hide:
@@ -1731,7 +1731,7 @@ public final class ChatListNode: ListView {
17311731
}
17321732
Queue.mainQueue().after(0.6) { [weak self] in
17331733
if let self {
1734-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .setupPassword).startStandalone()
1734+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupPassword.id).startStandalone()
17351735
}
17361736
}
17371737
let controller = self.context.sharedContext.makeSetupTwoFactorAuthController(context: self.context)
@@ -1742,9 +1742,9 @@ public final class ChatListNode: ListView {
17421742
}
17431743
Queue.mainQueue().after(0.6) { [weak self] in
17441744
if let self {
1745-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .annualPremium).startStandalone()
1746-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .upgradePremium).startStandalone()
1747-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .restorePremium).startStandalone()
1745+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.annualPremium.id).startStandalone()
1746+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.upgradePremium.id).startStandalone()
1747+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.restorePremium.id).startStandalone()
17481748
}
17491749
}
17501750
let controller = self.context.sharedContext.makePremiumIntroController(context: self.context, source: .ads, forceDark: false, dismissed: nil)
@@ -1875,26 +1875,28 @@ public final class ChatListNode: ListView {
18751875
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
18761876
switch notice {
18771877
case .xmasPremiumGift:
1878-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .xmasPremiumGift).startStandalone()
1878+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.xmasPremiumGift.id).startStandalone()
18791879
self.present?(UndoOverlayController(presentationData: presentationData, content: .info(title: nil, text: presentationData.strings.ChatList_PremiumGiftInSettingsInfo, timeout: 5.0, customUndoText: nil), elevatedLayout: false, action: { _ in
18801880
return true
18811881
}))
18821882
case .setupBirthday:
1883-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .setupBirthday).startStandalone()
1883+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupBirthday.id).startStandalone()
18841884
self.present?(UndoOverlayController(presentationData: presentationData, content: .info(title: nil, text: presentationData.strings.ChatList_BirthdayInSettingsInfo, timeout: 5.0, customUndoText: nil), elevatedLayout: false, action: { _ in
18851885
return true
18861886
}))
18871887
case .birthdayPremiumGift:
1888-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .todayBirthdays).startStandalone()
1888+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.todayBirthdays.id).startStandalone()
18891889
self.present?(UndoOverlayController(presentationData: presentationData, content: .info(title: nil, text: presentationData.strings.ChatList_PremiumGiftInSettingsInfo, timeout: 5.0, customUndoText: nil), elevatedLayout: false, action: { _ in
18901890
return true
18911891
}))
18921892
case .premiumGrace:
1893-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .gracePremium).startStandalone()
1893+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.gracePremium.id).startStandalone()
18941894
case .setupPhoto:
1895-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .setupPhoto).startStandalone()
1895+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupPhoto.id).startStandalone()
18961896
case .starsSubscriptionLowBalance:
1897-
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .starsSubscriptionLowBalance).startStandalone()
1897+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.starsSubscriptionLowBalance.id).startStandalone()
1898+
case let .link(id, _, _, _):
1899+
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: id).startStandalone()
18981900
default:
18991901
break
19001902
}
@@ -2063,7 +2065,7 @@ public final class ChatListNode: ListView {
20632065
return lhs < rhs
20642066
}
20652067

2066-
if dismissedSuggestions.contains(.todayBirthdays) {
2068+
if dismissedSuggestions.contains(ServerProvidedSuggestion.todayBirthdays.id) {
20672069
todayBirthdayPeerIds = []
20682070
}
20692071

@@ -2147,20 +2149,15 @@ public final class ChatListNode: ListView {
21472149
}
21482150
return .birthdayPremiumGift(peers: todayBirthdayPeers, birthdays: birthdays)
21492151
}
2150-
} else if case let .link(url, title, subtitle) = suggestions.first(where: { if case .link = $0 { return true } else { return false} }) {
2151-
return .single(.link(url: url, title: title, subtitle: subtitle))
2152+
} else if case let .link(id, url, title, subtitle) = suggestions.first(where: { if case .link = $0 { return true } else { return false} }) {
2153+
return .single(.link(id: id, url: url, title: title, subtitle: subtitle))
21522154
} else {
21532155
return .single(nil)
21542156
}
21552157
}
21562158
|> distinctUntilChanged
21572159

21582160
self.suggestedChatListNotice.set(suggestedChatListNoticeSignal)
2159-
2160-
/*#if DEBUG
2161-
let testNotice: Signal<ChatListNotice?, NoError> = Signal<ChatListNotice?, NoError>.single(.setupPassword) |> then(Signal<ChatListNotice?, NoError>.complete() |> delay(1.0, queue: .mainQueue())) |> then(Signal<ChatListNotice?, NoError>.single(.xmasPremiumGift)) |> then(Signal<ChatListNotice?, NoError>.complete() |> delay(1.0, queue: .mainQueue())) |> restart
2162-
self.suggestedChatListNotice.set(testNotice)
2163-
#endif*/
21642161
}).strict()
21652162

21662163
let storageInfo: Signal<Double?, NoError>

submodules/ChatListUI/Sources/Node/ChatListNodeEntries.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public enum ChatListNotice: Equatable {
9393
case starsSubscriptionLowBalance(amount: StarsAmount, peers: [EnginePeer])
9494
case setupPhoto(EnginePeer)
9595
case accountFreeze
96-
case link(url: String, title: String, subtitle: String)
96+
case link(id: String, url: String, title: ServerSuggestionInfo.Item.Text, subtitle: ServerSuggestionInfo.Item.Text)
9797
}
9898

9999
enum ChatListNodeEntry: Comparable, Identifiable {

submodules/ChatListUI/Sources/Node/ChatListNoticeItem.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,21 @@ class ChatListNoticeItem: ListViewItem {
8585
private let separatorHeight = 1.0 / UIScreen.main.scale
8686

8787
private let titleFont = Font.semibold(15.0)
88+
private let titleBoldFont = Font.bold(15.0)
89+
private let titleItalicFont = Font.semiboldItalic(15.0)
90+
private let titleBoldItalicFont = Font.semiboldItalic(15.0)
91+
8892
private let textFont = Font.regular(15.0)
93+
private let textBoldFont = Font.semibold(15.0)
94+
private let textItalicFont = Font.italic(15.0)
95+
private let textBoldItalicFont = Font.semiboldItalic(15.0)
96+
8997
private let smallTextFont = Font.regular(14.0)
9098

9199
final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
92100
private let contentContainer: ASDisplayNode
93101
private let titleNode: TextNodeWithEntities
94-
private let textNode: TextNode
102+
private let textNode: TextNodeWithEntities
95103
private let arrowNode: ASImageNode
96104
private let separatorNode: ASDisplayNode
97105

@@ -118,7 +126,7 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
118126
self.contentContainer = ASDisplayNode()
119127

120128
self.titleNode = TextNodeWithEntities()
121-
self.textNode = TextNode()
129+
self.textNode = TextNodeWithEntities()
122130
self.arrowNode = ASImageNode()
123131
self.separatorNode = ASDisplayNode()
124132

@@ -128,7 +136,7 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
128136
self.clipsToBounds = true
129137

130138
self.contentContainer.addSubnode(self.titleNode.textNode)
131-
self.contentContainer.addSubnode(self.textNode)
139+
self.contentContainer.addSubnode(self.textNode.textNode)
132140
self.contentContainer.addSubnode(self.arrowNode)
133141

134142
self.addSubnode(self.contentContainer)
@@ -154,7 +162,7 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
154162
let previousItem = self.item
155163

156164
let makeTitleLayout = TextNodeWithEntities.asyncLayout(self.titleNode)
157-
let makeTextLayout = TextNode.asyncLayout(self.textNode)
165+
let makeTextLayout = TextNodeWithEntities.asyncLayout(self.textNode)
158166

159167
let makeOkButtonTextLayout = TextNode.asyncLayout(self.okButtonText)
160168
let makeCancelButtonTextLayout = TextNode.asyncLayout(self.cancelButtonText)
@@ -291,9 +299,9 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
291299
case .accountFreeze:
292300
titleString = NSAttributedString(string: item.strings.ChatList_FrozenAccount_Title, font: titleFont, textColor: item.theme.list.itemDestructiveColor)
293301
textString = NSAttributedString(string: item.strings.ChatList_FrozenAccount_Text, font: smallTextFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)
294-
case let .link(_, title, subtitle):
295-
titleString = NSAttributedString(string: title, font: titleFont, textColor: item.theme.list.itemPrimaryTextColor)
296-
textString = NSAttributedString(string: subtitle, font: smallTextFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)
302+
case let .link(_, _, title, subtitle):
303+
titleString = stringWithAppliedEntities(title.string, entities: title.entities, baseColor: item.theme.list.itemPrimaryTextColor, linkColor: item.theme.list.itemAccentColor, baseFont: titleFont, linkFont: titleFont, boldFont: titleBoldFont, italicFont: titleItalicFont, boldItalicFont: titleBoldItalicFont, fixedFont: titleFont, blockQuoteFont: titleFont, message: nil)
304+
textString = stringWithAppliedEntities(subtitle.string, entities: subtitle.entities, baseColor: item.theme.list.itemPrimaryTextColor, linkColor: item.theme.list.itemAccentColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, boldItalicFont: textBoldItalicFont, fixedFont: textFont, blockQuoteFont: textFont, message: nil)
297305
}
298306

299307
var leftInset: CGFloat = sideInset
@@ -333,12 +341,15 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
333341
strongSelf.titleNode.textNode.frame = CGRect(origin: CGPoint(x: leftInset, y: verticalInset), size: titleLayout.0.size)
334342
}
335343

336-
let _ = textLayout.1()
344+
let _ = textLayout.1(TextNodeWithEntities.Arguments(context: item.context, cache: item.context.animationCache, renderer: item.context.animationRenderer, placeholderColor: .white, attemptSynchronous: true))
345+
346+
strongSelf.titleNode.visibilityRect = CGRect(origin: CGPoint(), size: CGSize(width: 1000000.0, height: 1000000.0))
347+
strongSelf.textNode.visibilityRect = CGRect(origin: CGPoint(), size: CGSize(width: 1000000.0, height: 1000000.0))
337348

338349
if case .center = alignment {
339-
strongSelf.textNode.frame = CGRect(origin: CGPoint(x: floor((params.width - textLayout.0.size.width) * 0.5), y: strongSelf.titleNode.textNode.frame.maxY + spacing), size: textLayout.0.size)
350+
strongSelf.textNode.textNode.frame = CGRect(origin: CGPoint(x: floor((params.width - textLayout.0.size.width) * 0.5), y: strongSelf.titleNode.textNode.frame.maxY + spacing), size: textLayout.0.size)
340351
} else {
341-
strongSelf.textNode.frame = CGRect(origin: CGPoint(x: leftInset, y: strongSelf.titleNode.textNode.frame.maxY + spacing), size: textLayout.0.size)
352+
strongSelf.textNode.textNode.frame = CGRect(origin: CGPoint(x: leftInset, y: strongSelf.titleNode.textNode.frame.maxY + spacing), size: textLayout.0.size)
342353
}
343354

344355
if !avatarPeers.isEmpty {
@@ -434,8 +445,8 @@ final class ChatListNoticeItemNode: ItemListRevealOptionsItemNode {
434445
let buttonWidth: CGFloat = floor(buttonsWidth * 0.5)
435446
let buttonHeight: CGFloat = 32.0
436447

437-
let okButtonFrame = CGRect(origin: CGPoint(x: floor((params.width - buttonsWidth) * 0.5), y: strongSelf.textNode.frame.maxY + 6.0), size: CGSize(width: buttonWidth, height: buttonHeight))
438-
let cancelButtonFrame = CGRect(origin: CGPoint(x: okButtonFrame.maxX, y: strongSelf.textNode.frame.maxY + 6.0), size: CGSize(width: buttonWidth, height: buttonHeight))
448+
let okButtonFrame = CGRect(origin: CGPoint(x: floor((params.width - buttonsWidth) * 0.5), y: strongSelf.textNode.textNode.frame.maxY + 6.0), size: CGSize(width: buttonWidth, height: buttonHeight))
449+
let cancelButtonFrame = CGRect(origin: CGPoint(x: okButtonFrame.maxX, y: strongSelf.textNode.textNode.frame.maxY + 6.0), size: CGSize(width: buttonWidth, height: buttonHeight))
439450

440451
okButton.frame = okButtonFrame
441452
cancelButton.frame = cancelButtonFrame

submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func changePhoneNumberCodeController(context: AccountContext, phoneNumber: Strin
285285
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
286286
presentControllerImpl?(OverlayStatusController(theme: presentationData.theme, type: .success), nil)
287287

288-
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: .validatePhoneNumber).start()
288+
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.validatePhoneNumber.id).start()
289289

290290
dismissImpl?()
291291
}))

submodules/SettingsUI/Sources/ChangePhoneNumberController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public func ChangePhoneNumberController(context: AccountContext) -> ViewControll
8484
}, completed: { [weak codeController] in
8585
codeController?.present(OverlayStatusController(theme: presentationData.theme, type: .success), in: .window(.root))
8686

87-
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: .validatePhoneNumber).start()
87+
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.validatePhoneNumber.id).start()
8888

8989
if let navigationController = codeController?.navigationController as? NavigationController {
9090
var viewControllers = navigationController.viewControllers

submodules/TelegramCore/Sources/State/ManagedProxyInfoUpdates.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public final class ServerSuggestionInfo: Codable, Equatable {
106106
let container = try decoder.container(keyedBy: CodingKeys.self)
107107
self = .link(url: try container.decode(String.self, forKey: .link))
108108
}
109+
110+
public func encode(to encoder: any Encoder) throws {
111+
var container = encoder.container(keyedBy: CodingKeys.self)
112+
switch self {
113+
case let .link(url):
114+
try container.encode(url, forKey: .link)
115+
}
116+
}
109117
}
110118

111119
public let id: String

0 commit comments

Comments
 (0)