Skip to content

Commit 084bb5b

Browse files
author
Isaac
committed
[WIP] Post suggestions
1 parent d6334b9 commit 084bb5b

File tree

21 files changed

+412
-93
lines changed

21 files changed

+412
-93
lines changed

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,13 @@ public enum SendInviteLinkScreenSubject {
996996
}
997997

998998
public enum StarsWithdrawalScreenSubject {
999+
public enum PaidMessageKind {
1000+
case privacy
1001+
case postSuggestion
1002+
}
1003+
9991004
case withdraw
1000-
case enterAmount(current: StarsAmount)
1005+
case enterAmount(current: StarsAmount, minValue: StarsAmount, fractionAfterCommission: Int, kind: PaidMessageKind)
10011006
}
10021007

10031008
public protocol SharedAccountContext: AnyObject {

submodules/SettingsUI/Sources/Privacy and Security/IncomingMessagePrivacyScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public func incomingMessagePrivacyScreen(context: AccountContext, value: GlobalP
376376
if case let .paidMessages(value) = stateValue.with({ $0 }).updatedValue {
377377
currentAmount = value
378378
}
379-
let starsScreen = context.sharedContext.makeStarsWithdrawalScreen(context: context, subject: .enterAmount(current: currentAmount), completion: { amount in
379+
let starsScreen = context.sharedContext.makeStarsWithdrawalScreen(context: context, subject: .enterAmount(current: currentAmount, minValue: StarsAmount(value: 1, nanos: 0), fractionAfterCommission: 80, kind: .privacy), completion: { amount in
380380
updateState { state in
381381
var state = state
382382
state.updatedValue = .paidMessages(StarsAmount(value: amount, nanos: 0))

submodules/TelegramUI/Components/Chat/ChatChannelSubscriberInputPanelNode/Sources/ChatChannelSubscriberInputPanelNode.swift

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -321,48 +321,88 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
321321
return self.updateLayout(width: width, leftInset: leftInset, rightInset: rightInset, bottomInset: bottomInset, additionalSideInsets: additionalSideInsets, maxHeight: maxHeight, isSecondary: isSecondary, transition: transition, interfaceState: interfaceState, metrics: metrics, force: false)
322322
}
323323

324-
private var displayedGiftTooltip = false
325-
private func presentGiftTooltip() {
326-
guard let context = self.context, !self.displayedGiftTooltip, let parentController = self.interfaceInteraction?.chatController() else {
324+
private var displayedGiftOrSuggestTooltip = false
325+
private func presentGiftOrSuggestTooltip() {
326+
guard let context = self.context, !self.displayedGiftOrSuggestTooltip, let parentController = self.interfaceInteraction?.chatController() else {
327327
return
328328
}
329-
self.displayedGiftTooltip = true
329+
self.displayedGiftOrSuggestTooltip = true
330330

331-
let _ = (ApplicationSpecificNotice.getChannelSendGiftTooltip(accountManager: context.sharedContext.accountManager)
332-
|> deliverOnMainQueue).start(next: { [weak self] count in
331+
let _ = (combineLatest(queue: .mainQueue(),
332+
ApplicationSpecificNotice.getChannelSendGiftTooltip(accountManager: context.sharedContext.accountManager),
333+
ApplicationSpecificNotice.getChannelSuggestTooltip(accountManager: context.sharedContext.accountManager)
334+
|> deliverOnMainQueue)).start(next: { [weak self] giftCount, suggestCount in
333335
guard let self else {
334336
return
335337
}
336-
guard count < 2 else {
337-
return
338-
}
339338

340-
let _ = ApplicationSpecificNotice.incrementChannelSendGiftTooltip(accountManager: context.sharedContext.accountManager).start()
339+
/*#if DEBUG
340+
var giftCount = giftCount
341+
var suggestCount = suggestCount
342+
if "".isEmpty {
343+
giftCount = 2
344+
suggestCount = 0
345+
}
346+
#endif*/
341347

342-
Queue.mainQueue().after(0.4, {
343-
let absoluteFrame = self.giftButton.view.convert(self.giftButton.bounds, to: parentController.view)
344-
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.minY + 11.0), size: CGSize())
348+
if giftCount < 2 && !self.giftButton.isHidden {
349+
let _ = ApplicationSpecificNotice.incrementChannelSendGiftTooltip(accountManager: context.sharedContext.accountManager).start()
345350

346-
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
347-
let text: String = presentationData.strings.Chat_SendGiftTooltip
348-
349-
let tooltipController = TooltipScreen(
350-
account: context.account,
351-
sharedContext: context.sharedContext,
352-
text: .plain(text: text),
353-
balancedTextLayout: false,
354-
style: .wide,
355-
arrowStyle: .small,
356-
icon: nil,
357-
location: .point(location, .bottom),
358-
displayDuration: .default,
359-
inset: 8.0,
360-
shouldDismissOnTouch: { _, _ in
361-
return .ignore
362-
}
363-
)
364-
self.interfaceInteraction?.presentControllerInCurrent(tooltipController, nil)
365-
})
351+
Queue.mainQueue().after(0.4, {
352+
let absoluteFrame = self.giftButton.view.convert(self.giftButton.bounds, to: parentController.view)
353+
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.minY + 11.0), size: CGSize())
354+
355+
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
356+
let text: String = presentationData.strings.Chat_SendGiftTooltip
357+
358+
let tooltipController = TooltipScreen(
359+
account: context.account,
360+
sharedContext: context.sharedContext,
361+
text: .plain(text: text),
362+
balancedTextLayout: false,
363+
style: .wide,
364+
arrowStyle: .small,
365+
icon: nil,
366+
location: .point(location, .bottom),
367+
displayDuration: .default,
368+
inset: 8.0,
369+
shouldDismissOnTouch: { _, _ in
370+
return .ignore
371+
}
372+
)
373+
self.interfaceInteraction?.presentControllerInCurrent(tooltipController, nil)
374+
})
375+
} else if suggestCount < 2 && !self.suggestedPostButton.isHidden {
376+
let _ = ApplicationSpecificNotice.incrementChannelSuggestTooltip(accountManager: context.sharedContext.accountManager).start()
377+
378+
Queue.mainQueue().after(0.4, {
379+
let absoluteFrame = self.suggestedPostButton.view.convert(self.suggestedPostButton.bounds, to: parentController.view)
380+
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.minY + 11.0), size: CGSize())
381+
382+
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
383+
let _ = presentationData
384+
//TODO:localize
385+
let text: String = "Tap here to suggest a message"
386+
387+
let tooltipController = TooltipScreen(
388+
account: context.account,
389+
sharedContext: context.sharedContext,
390+
text: .plain(text: text),
391+
textBadge: "NEW",
392+
balancedTextLayout: false,
393+
style: .wide,
394+
arrowStyle: .small,
395+
icon: nil,
396+
location: .point(location, .bottom),
397+
displayDuration: .default,
398+
inset: 8.0,
399+
shouldDismissOnTouch: { _, _ in
400+
return .ignore
401+
}
402+
)
403+
self.interfaceInteraction?.presentControllerInCurrent(tooltipController, nil)
404+
})
405+
}
366406
})
367407
}
368408

@@ -377,7 +417,7 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
377417
if previousState?.theme !== interfaceState.theme {
378418
self.badgeBackground.image = PresentationResourcesChatList.badgeBackgroundActive(interfaceState.theme, diameter: 20.0)
379419
self.helpButton.setImage(generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/Help"), color: interfaceState.theme.chat.inputPanel.panelControlAccentColor), for: .normal)
380-
self.suggestedPostButton.setImage(generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/Gift"), color: interfaceState.theme.chat.inputPanel.panelControlAccentColor), for: .normal)
420+
self.suggestedPostButton.setImage(generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/SuggestPost"), color: interfaceState.theme.chat.inputPanel.panelControlAccentColor), for: .normal)
381421
self.giftButton.setImage(generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/Gift"), color: interfaceState.theme.chat.inputPanel.panelControlAccentColor), for: .normal)
382422
}
383423

@@ -431,11 +471,12 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
431471
self.helpButton.isHidden = true
432472
//TODO:release
433473
self.suggestedPostButton.isHidden = false
434-
self.presentGiftTooltip()
474+
self.presentGiftOrSuggestTooltip()
435475
} else if case .broadcast = peer.info {
436476
self.giftButton.isHidden = true
437477
self.helpButton.isHidden = true
438478
self.suggestedPostButton.isHidden = false
479+
self.presentGiftOrSuggestTooltip()
439480
} else if peer.flags.contains(.isGigagroup), self.action == .muteNotifications || self.action == .unmuteNotifications {
440481
self.giftButton.isHidden = true
441482
self.helpButton.isHidden = false

submodules/TelegramUI/Components/Chat/ChatEmptyNode/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ swift_library(
3232
"//submodules/TelegramUI/Components/Chat/ChatMediaInputStickerGridItem",
3333
"//submodules/PremiumUI",
3434
"//submodules/TelegramUI/Components/LottieComponent",
35+
"//submodules/Components/BundleIconComponent",
3536
],
3637
visibility = [
3738
"//visibility:public",

submodules/TelegramUI/Components/Chat/ChatEmptyNode/Sources/ChatEmptyNode.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import ChatMediaInputStickerGridItem
2323
import UndoUI
2424
import PremiumUI
2525
import LottieComponent
26+
import BundleIconComponent
2627

2728
private protocol ChatEmptyNodeContent {
2829
func updateLayout(interfaceState: ChatPresentationInterfaceState, subject: ChatEmptyNode.Subject, size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize
@@ -1367,16 +1368,27 @@ public final class ChatEmptyNodePremiumRequiredChatContent: ASDisplayNode, ChatE
13671368
contentsHeight += iconBackgroundSize
13681369
contentsHeight += iconTextSpacing
13691370

1370-
let iconSize = self.icon.update(
1371-
transition: .immediate,
1372-
component: AnyComponent(
1371+
let iconComponent: AnyComponent<Empty>
1372+
if case let .customChatContents(customChatContents) = interfaceState.subject, case .postSuggestions = customChatContents.kind {
1373+
iconComponent = AnyComponent(
1374+
BundleIconComponent(
1375+
name: "Chat/Empty Chat/PostSuggestions",
1376+
tintColor: serviceColor.primaryText
1377+
)
1378+
)
1379+
} else {
1380+
iconComponent = AnyComponent(
13731381
LottieComponent(
13741382
content: LottieComponent.AppBundleContent(name: "PremiumRequired"),
13751383
color: serviceColor.primaryText,
13761384
size: CGSize(width: 120.0, height: 120.0),
13771385
loop: true
13781386
)
1379-
),
1387+
)
1388+
}
1389+
let iconSize = self.icon.update(
1390+
transition: .immediate,
1391+
component: iconComponent,
13801392
environment: {},
13811393
containerSize: CGSize(width: maxWidth - sideInset * 2.0, height: 500.0)
13821394
)

submodules/TelegramUI/Components/ChatScheduleTimeController/Sources/ChatScheduleTimeControllerNode.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
2626
private let backgroundNode: ASDisplayNode
2727
private let contentBackgroundNode: ASDisplayNode
2828
private let titleNode: ASTextNode
29+
private let textNode: ASTextNode?
2930
private let cancelButton: HighlightableButtonNode
3031
private let doneButton: SolidRoundedButtonNode
3132
private let onlineButton: SolidRoundedButtonNode
@@ -93,6 +94,7 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
9394
self.contentBackgroundNode.backgroundColor = backgroundColor
9495

9596
let title: String
97+
var text: String?
9698
switch mode {
9799
case .scheduledMessages:
98100
title = self.presentationData.strings.Conversation_ScheduleMessage_Title
@@ -101,13 +103,27 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
101103
case .suggestPost:
102104
//TODO:localize
103105
title = "Time"
106+
text = "Set the date and time you want\nyour message to be published."
104107
}
105108

106109
self.titleNode = ASTextNode()
107110
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.bold(17.0), textColor: textColor)
108111
self.titleNode.accessibilityLabel = title
109112
self.titleNode.accessibilityTraits = [.staticText]
110113

114+
if let text {
115+
let textNode = ASTextNode()
116+
textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: textColor)
117+
textNode.maximumNumberOfLines = 0
118+
textNode.textAlignment = .center
119+
textNode.lineSpacing = 0.2
120+
textNode.accessibilityLabel = text
121+
textNode.accessibilityTraits = [.staticText]
122+
self.textNode = textNode
123+
} else {
124+
self.textNode = nil
125+
}
126+
111127
self.cancelButton = HighlightableButtonNode()
112128
self.cancelButton.setTitle(self.presentationData.strings.Common_Cancel, with: Font.regular(17.0), with: accentColor, for: .normal)
113129
self.cancelButton.accessibilityLabel = self.presentationData.strings.Common_Cancel
@@ -146,6 +162,9 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
146162
self.backgroundNode.addSubnode(self.effectNode)
147163
self.backgroundNode.addSubnode(self.contentBackgroundNode)
148164
self.contentContainerNode.addSubnode(self.titleNode)
165+
if let textNode = self.textNode {
166+
self.contentContainerNode.addSubnode(textNode)
167+
}
149168
self.contentContainerNode.addSubnode(self.cancelButton)
150169
self.contentContainerNode.addSubnode(self.doneButton)
151170
if case .scheduledMessages(true) = self.mode {
@@ -422,6 +441,13 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
422441
}
423442
let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 0.0)
424443

444+
let textControlSpacing: CGFloat = -8.0
445+
let textDoneSpacing: CGFloat = 21.0
446+
let textSize = self.textNode?.measure(CGSize(width: width, height: 1000.0))
447+
if let textSize {
448+
contentHeight += textSize.height + textControlSpacing + textDoneSpacing
449+
}
450+
425451
let sideInset = floor((layout.size.width - width) / 2.0)
426452
let contentContainerFrame = CGRect(origin: CGPoint(x: sideInset, y: layout.size.height - contentHeight), size: CGSize(width: width, height: contentHeight))
427453
let contentFrame = contentContainerFrame
@@ -446,7 +472,13 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, ASScrollViewDel
446472

447473
let buttonInset: CGFloat = 16.0
448474
let doneButtonHeight = self.doneButton.updateLayout(width: contentFrame.width - buttonInset * 2.0, transition: transition)
449-
transition.updateFrame(node: self.doneButton, frame: CGRect(x: buttonInset, y: contentHeight - doneButtonHeight - insets.bottom - 16.0 - buttonOffset, width: contentFrame.width, height: doneButtonHeight))
475+
let doneButtonFrame = CGRect(x: buttonInset, y: contentHeight - doneButtonHeight - insets.bottom - 16.0 - buttonOffset, width: contentFrame.width, height: doneButtonHeight)
476+
transition.updateFrame(node: self.doneButton, frame: doneButtonFrame)
477+
478+
if let textNode = self.textNode, let textSize {
479+
let textFrame = CGRect(origin: CGPoint(x: floor((contentFrame.width - textSize.width) / 2.0), y: doneButtonFrame.minY - textDoneSpacing - textSize.height), size: textSize)
480+
transition.updateFrame(node: textNode, frame: textFrame)
481+
}
450482

451483
let onlineButtonHeight = self.onlineButton.updateLayout(width: contentFrame.width - buttonInset * 2.0, transition: transition)
452484
transition.updateFrame(node: self.onlineButton, frame: CGRect(x: buttonInset, y: contentHeight - onlineButtonHeight - cleanInsets.bottom - 16.0, width: contentFrame.width, height: onlineButtonHeight))

submodules/TelegramUI/Components/PeerInfo/MessagePriceItem/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ swift_library(
2323
"//submodules/TelegramUI/Components/ButtonComponent",
2424
"//submodules/Components/BundleIconComponent",
2525
"//submodules/Components/MultilineTextComponent",
26+
"//submodules/TelegramUI/Components/ListItemComponentAdaptor",
2627
],
2728
visibility = [
2829
"//visibility:public",

0 commit comments

Comments
 (0)