Various improvements

This commit is contained in:
Ilya Laktyushin 2024-03-20 19:55:36 +04:00
parent a2b6e41fd2
commit 2acb93f386
12 changed files with 100 additions and 51 deletions

View File

@ -10675,6 +10675,9 @@ Sorry for the inconvenience.";
"Premium.Gift.ContactSelection.DeselectAll" = "DESELECT ALL";
"Premium.Gift.ContactSelection.SelectAll" = "SELECT ALL";
"Premium.Gift.ContactSelection.MaximumReached" = "You can select up to %@ users.";
"Premium.Gift.ContactSelection.BirthdayToday" = "🎂 BIRTHDAY TODAY";
"Premium.Gift.ContactSelection.BirthdayYesterday" = "BIRTHDAY YESTERDAY";
"Premium.Gift.ContactSelection.BirthdayTomorrow" = "BIRTHDAY TOMORROW";
"Premium.Gift.GiftMultipleSubscriptionsFormat" = "%1$@ for %2$@";
"Premium.Gift.GiftMultipleSubscriptions_1" = "Gift %@ Subscription";
@ -11642,3 +11645,15 @@ Sorry for the inconvenience.";
"Birthday.Added" = "Date of birth added.";
"Chat.BirthdayTooltip" = "🎂 %1$@ is having a birthday today. You can give %2$@ **Telegram Premium** as a birthday gift.";
"ChatList.AddBirthdayTitle" = "Add your birthday! 🎂";
"ChatList.AddBirthdayText" = "Let your contacts know when you're celebrating.";
"ChatList.BirthdaySingleTitle" = "It's %@ **birthday** today! 🎂";
"ChatList.BirthdaySingleText" = "Gift them Telegram Premium.";
"ChatList.BirthdayMultipleTitle_1" = "%@ contact have **birthday** today! 🎂";
"ChatList.BirthdayMultipleTitle_any" = "%@ contacts have **birthdays** today! 🎂";
"ChatList.BirthdayMultipleText" = "Gift them Telegram Premium.";
"ChatList.BirthdayInSettingsInfo" = "You can set your date of birth later in **Settings**.";

View File

@ -75,7 +75,7 @@ public enum ContactMultiselectionControllerMode {
case peerSelection(searchChatList: Bool, searchGroups: Bool, searchChannels: Bool)
case channelCreation
case chatSelection(ChatSelection)
case premiumGifting(birthdays: [EnginePeer.Id: TelegramBirthday]?)
case premiumGifting(birthdays: [EnginePeer.Id: TelegramBirthday]?, selectToday: Bool)
case requestedUsersSelection
}

View File

@ -44,7 +44,7 @@ public enum PremiumIntroSource {
public enum PremiumGiftSource: Equatable {
case profile
case attachMenu
case settings
case settings([EnginePeer.Id: TelegramBirthday]?)
case chatList([EnginePeer.Id: TelegramBirthday]?)
case channelBoost
case deeplink(String?)

View File

@ -5794,14 +5794,12 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
let _ = context.engine.accountData.updateBirthday(birthday: value).startStandalone()
//TODO:localize
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
self.present(UndoOverlayController(presentationData: presentationData, content: .actionSucceeded(title: nil, text: self.presentationData.strings.Birthday_Added, cancel: nil, destructive: false), elevatedLayout: false, action: { _ in
return true
}), in: .current)
})
self.push(controller)
//self.present(controller, in: .current)
}
private var storyCameraTransitionInCoordinator: StoryCameraTransitionInCoordinator?

View File

@ -1698,21 +1698,6 @@ public final class ChatListNode: ListView {
guard let self else {
return
}
if let birthdays {
let today = Calendar(identifier: .gregorian).component(.day, from: Date())
var todayBirthdayPeerIds: [EnginePeer.Id] = []
for (peerId, birthday) in birthdays {
if birthday.day == today {
todayBirthdayPeerIds.append(peerId)
}
}
let peerIds = todayBirthdayPeerIds.sorted { lhs, rhs in
return lhs < rhs
}
Queue.mainQueue().after(0.4) {
let _ = ApplicationSpecificNotice.setDismissedBirthdayPremiumGifts(accountManager: self.context.sharedContext.accountManager, values: peerIds.map { $0.toInt64() }).start()
}
}
let controller = self.context.sharedContext.makePremiumGiftController(context: self.context, source: .chatList(birthdays), completion: nil)
controller.navigationPresentation = .modal
self.push?(controller)
@ -1819,9 +1804,8 @@ public final class ChatListNode: ListView {
return true
}))
case .setupBirthday:
//TODO:localize
let _ = self.context.engine.notices.dismissServerProvidedSuggestion(suggestion: .setupBirthday).startStandalone()
self.present?(UndoOverlayController(presentationData: presentationData, content: .info(title: nil, text: "You can set your date of birth later in **Settings**.", timeout: 5.0, customUndoText: nil), elevatedLayout: false, action: { _ in
self.present?(UndoOverlayController(presentationData: presentationData, content: .info(title: nil, text: presentationData.strings.ChatList_BirthdayInSettingsInfo, timeout: 5.0, customUndoText: nil), elevatedLayout: false, action: { _ in
return true
}))
case let .birthdayPremiumGift(peers, _):

View File

@ -225,19 +225,17 @@ class ChatListStorageInfoItemNode: ItemListRevealOptionsItemNode {
titleString = parseMarkdownIntoAttributedString(item.strings.ChatList_PremiumXmasGiftTitle, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor), bold: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.accentTextColor), link: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor), linkAttribute: { _ in return nil }))
textString = NSAttributedString(string: item.strings.ChatList_PremiumXmasGiftText, font: textFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)
case .setupBirthday:
//TODO:localize
titleString = NSAttributedString(string: "Add your birthday! 🎂", font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor)
textString = NSAttributedString(string: "Let your contacts know when you're celebrating.", font: textFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)
titleString = NSAttributedString(string: item.strings.ChatList_AddBirthdayTitle, font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor)
textString = NSAttributedString(string: item.strings.ChatList_AddBirthdayText, font: textFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)
case let .birthdayPremiumGift(peers, _):
//TODO:localize
let title: String
let text: String
if peers.count == 1, let peer = peers.first {
title = "It's \(peer.compactDisplayTitle)'s **birthday** today! 🎂"
text = "Gift them Telegram Premium."
title = item.strings.ChatList_BirthdaySingleTitle(peer.compactDisplayTitle).string
text = item.strings.ChatList_BirthdaySingleText
} else {
title = "\(peers.count) contacts have **birthdays** today! 🎂"
text = "Gift them Telegram Premium."
title = item.strings.ChatList_BirthdayMultipleTitle(Int32(peers.count))
text = item.strings.ChatList_BirthdayMultipleText
}
titleString = parseMarkdownIntoAttributedString(title, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor), bold: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.accentTextColor), link: MarkdownAttributeSet(font: titleFont, textColor: item.theme.rootController.navigationBar.primaryTextColor), linkAttribute: { _ in return nil }))
textString = NSAttributedString(string: text, font: textFont, textColor: item.theme.rootController.navigationBar.secondaryTextColor)

View File

@ -556,7 +556,7 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
case let .custom(sections):
if !topPeers.isEmpty {
var index: Int = 0
var sectionId: Int = 0
var sectionId: Int = 1
for (title, peerIds) in sections {
var allSelected = true
if let selectedPeerIndices = selectionState?.selectedPeerIndices, !selectedPeerIndices.isEmpty {
@ -575,6 +575,9 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
for peerId in peerIds {
if let peer = topPeers.first(where: { $0.id == peerId }) {
if existingPeerIds.contains(.peer(peer.id)) {
continue
}
existingPeerIds.insert(.peer(peer.id))
let selection: ContactsPeerItemSelection
@ -592,6 +595,30 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
}
sectionId += 1
}
let hasDeselectAll = !(selectionState?.selectedPeerIndices ?? [:]).isEmpty
let header: ListViewItemHeader? = ChatListSearchItemHeader(type: .text(strings.Premium_Gift_ContactSelection_FrequentContacts.uppercased(), AnyHashable(hasDeselectAll ? 1 : 0)), theme: theme, strings: strings, actionTitle: hasDeselectAll ? strings.Premium_Gift_ContactSelection_DeselectAll.uppercased() : nil, action: {
interaction.deselectAll()
})
for peer in topPeers.prefix(15) {
if existingPeerIds.contains(.peer(peer.id)) {
continue
}
existingPeerIds.insert(.peer(peer.id))
let selection: ContactsPeerItemSelection
if let selectionState = selectionState {
selection = .selectable(selected: selectionState.selectedPeerIndices[.peer(peer.id)] != nil)
} else {
selection = .none
}
let presence = presences[peer.id]
entries.append(.peer(index, .peer(peer: peer._asPeer(), isGlobal: false, participantCount: nil), presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false, true, nil, false))
index += 1
}
}
case .none:
break
@ -1573,17 +1600,19 @@ public final class ContactListNode: ASDisplayNode {
for (_, sectionPeers) in sections {
peerIds.append(contentsOf: sectionPeers)
}
topPeers = context.engine.data.get(
EngineDataMap(peerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))
)
|> map { peers in
topPeers = combineLatest(
context.engine.data.get(EngineDataMap(peerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))),
context.engine.peers.recentPeers()
) |> map { peers, recentPeers in
var result: [EnginePeer] = []
for peer in peers.values {
if let peer {
result.append(peer)
}
}
if case let .peers(peers) = recentPeers {
result.append(contentsOf: peers.map(EnginePeer.init))
}
return result
}
case .none:

View File

@ -1032,7 +1032,6 @@ private func settingsEditingItems(data: PeerInfoScreenData?, state: PeerInfoStat
birthday = (data.cachedData as? CachedUserData)?.birthday
}
//TODO:localize
var birthDateString: String
if let birthday {
birthDateString = stringForCompactBirthday(birthday, strings: presentationData.strings)
@ -9040,8 +9039,15 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
let controller = self.context.sharedContext.makePremiumIntroController(context: self.context, source: .settings, forceDark: false, dismissed: nil)
self.controller?.push(controller)
case .premiumGift:
let controller = self.context.sharedContext.makePremiumGiftController(context: self.context, source: .settings, completion: nil)
let _ = (self.context.account.stateManager.contactBirthdays
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] birthdays in
guard let self else {
return
}
let controller = self.context.sharedContext.makePremiumGiftController(context: self.context, source: .settings(birthdays), completion: nil)
self.controller?.push(controller)
})
case .stickers:
if let settings = self.data?.globalSettings {
push(installedStickerPacksController(context: self.context, mode: .general, archivedPacks: settings.archivedStickerPacks, updatedPacks: { [weak self] packs in

View File

@ -111,7 +111,6 @@ private final class BirthdayPickerSheetContentComponent: Component {
transition.setFrame(view: cancelView, frame: cancelFrame)
}
//TODO:localize
let buttonSize = self.button.update(
transition: transition,
component: AnyComponent(ButtonComponent(

View File

@ -166,8 +166,8 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection
strongSelf.updateTitle()
})
case let .premiumGifting(birthdays):
if let birthdays {
case let .premiumGifting(birthdays, selectToday):
if let birthdays, selectToday {
let today = Calendar(identifier: .gregorian).component(.day, from: Date())
var todayPeers: [EnginePeer.Id] = []
for (peerId, birthday) in birthdays {

View File

@ -183,9 +183,8 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
} else {
let displayTopPeers: ContactListPresentation.TopPeers
var selectedPeers: [EnginePeer.Id] = []
if case let .premiumGifting(birthdays) = mode {
if case let .premiumGifting(birthdays, selectToday) = mode {
if let birthdays {
//TODO:localize
let today = Calendar(identifier: .gregorian).component(.day, from: Date())
var sections: [(String, [EnginePeer.Id])] = []
var todayPeers: [EnginePeer.Id] = []
@ -195,7 +194,9 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
for (peerId, birthday) in birthdays {
if birthday.day == today {
todayPeers.append(peerId)
if selectToday {
selectedPeers.append(peerId)
}
} else if birthday.day == today - 1 || birthday.day > today + 5 {
yesterdayPeers.append(peerId)
} else if birthday.day == today + 1 || birthday.day < today + 5 {
@ -204,13 +205,13 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
}
if !todayPeers.isEmpty {
sections.append(("🎂 BIRTHDAY TODAY", todayPeers))
sections.append((presentationData.strings.Premium_Gift_ContactSelection_BirthdayToday, todayPeers))
}
if !yesterdayPeers.isEmpty {
sections.append(("BIRTHDAY YESTERDAY", yesterdayPeers))
sections.append((presentationData.strings.Premium_Gift_ContactSelection_BirthdayYesterday, yesterdayPeers))
}
if !tomorrowPeers.isEmpty {
sections.append(("BIRTHDAY TOMORROW", tomorrowPeers))
sections.append((presentationData.strings.Premium_Gift_ContactSelection_BirthdayTomorrow, tomorrowPeers))
}
displayTopPeers = .custom(sections)

View File

@ -60,6 +60,7 @@ import StickerPickerScreen
import MediaEditor
import MediaEditorScreen
import BusinessIntroSetupScreen
import TelegramNotices
private final class AccountUserInterfaceInUseContext {
let subscribers = Bag<(Bool) -> Void>()
@ -2125,11 +2126,15 @@ public final class SharedAccountContextImpl: SharedAccountContext {
var reachedLimitImpl: ((Int32) -> Void)?
let mode: ContactMultiselectionControllerMode
if case let .chatList(birthdays) = source, let birthdays {
//TODO:localize
mode = .premiumGifting(birthdays: birthdays)
var currentBirthdays: [EnginePeer.Id: TelegramBirthday]?
if case let .chatList(birthdays) = source, let birthdays, !birthdays.isEmpty {
mode = .premiumGifting(birthdays: birthdays, selectToday: true)
currentBirthdays = birthdays
} else if case let .settings(birthdays) = source, let birthdays, !birthdays.isEmpty {
mode = .premiumGifting(birthdays: birthdays, selectToday: false)
currentBirthdays = birthdays
} else {
mode = .premiumGifting(birthdays: nil)
mode = .premiumGifting(birthdays: nil, selectToday: false)
}
let controller = context.sharedContext.makeContactMultiselectionController(ContactMultiselectionControllerParams(context: context, mode: mode, options: [], isPeerEnabled: { peer in
@ -2177,6 +2182,20 @@ public final class SharedAccountContextImpl: SharedAccountContext {
}, completion: {
filterImpl?()
completion?()
if let currentBirthdays {
let today = Calendar(identifier: .gregorian).component(.day, from: Date())
var todayBirthdayPeerIds: [EnginePeer.Id] = []
for (peerId, birthday) in currentBirthdays {
if birthday.day == today {
todayBirthdayPeerIds.append(peerId)
}
}
let peerIds = todayBirthdayPeerIds.sorted { lhs, rhs in
return lhs < rhs
}
let _ = ApplicationSpecificNotice.setDismissedBirthdayPremiumGifts(accountManager: context.sharedContext.accountManager, values: peerIds.map { $0.toInt64() }).start()
}
})
pushImpl = { [weak giftController] c in
giftController?.push(c)