Skip to content

Commit e351bbf

Browse files
committed
Various fixes
1 parent 3f8152d commit e351bbf

File tree

13 files changed

+206
-109
lines changed

13 files changed

+206
-109
lines changed

submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ typedef enum {
4545
@property (nonatomic, strong) id<TGPhotoPaintStickersContext> stickersContext;
4646
@property (nonatomic, assign) bool shortcut;
4747

48+
@property (nonatomic, assign) int64_t sendPaidMessageStars;
49+
4850
@property (nonatomic, strong) NSAttributedString *forcedCaption;
4951

5052
@property (nonatomic, strong) NSString *recipientName;

submodules/LegacyComponents/Sources/TGCameraController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ - (void)_createContextsIfNeeded
14461446
if (editingContext == nil)
14471447
{
14481448
editingContext = [[TGMediaEditingContext alloc] init];
1449+
editingContext.sendPaidMessageStars = self.sendPaidMessageStars;
14491450
if (self.forcedCaption != nil)
14501451
[editingContext setForcedCaption:self.forcedCaption];
14511452
_editingContext = editingContext;

submodules/LegacyComponents/Sources/TGPhotoToolbarView.m

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -673,57 +673,71 @@ - (void)layoutSubviews
673673
CGFloat offset = 8.0f;
674674
if (self.frame.size.width > self.frame.size.height)
675675
{
676-
if (buttons.count == 1)
677-
{
676+
_cancelButton.frame = CGRectMake(0, 0, 49, 49);
677+
678+
CGFloat leftEdge = _cancelButton.frame.size.width;
679+
CGFloat rightEdge = 0.0f;
680+
681+
if (_starsDoneButton != nil) {
682+
CGSize buttonSize = [_starsDoneButton updateCount:_sendPaidMessageStars];
683+
rightEdge = buttonSize.width + 2.0f;
684+
[_starsDoneButton updateFrame:CGRectMake(self.frame.size.width - rightEdge, 2.0f, buttonSize.width, buttonSize.height)];
685+
} else {
686+
rightEdge = _cancelButton.frame.size.width;
687+
}
688+
689+
CGFloat availableWidth = self.frame.size.width - leftEdge - rightEdge;
690+
CGFloat startX = leftEdge;
691+
CGFloat sideOffset = 5.0f;
692+
693+
if (buttons.count == 1) {
678694
UIView *button = buttons.firstObject;
679-
button.frame = CGRectMake(CGFloor(self.frame.size.width / 2 - button.frame.size.width / 2), offset, button.frame.size.width, button.frame.size.height);
695+
CGFloat buttonX = startX + (availableWidth - button.frame.size.width) / 2;
696+
button.frame = CGRectMake(buttonX, offset, button.frame.size.width, button.frame.size.height);
680697
}
681-
else if (buttons.count == 2)
682-
{
698+
else if (buttons.count == 2) {
683699
UIView *leftButton = buttons.firstObject;
684700
UIView *rightButton = buttons.lastObject;
685701

686-
leftButton.frame = CGRectMake(CGFloor(self.frame.size.width / 5 * 2 - 5 - leftButton.frame.size.width / 2), offset, leftButton.frame.size.width, leftButton.frame.size.height);
687-
rightButton.frame = CGRectMake(CGCeil(self.frame.size.width - leftButton.frame.origin.x - rightButton.frame.size.width), offset, rightButton.frame.size.width, rightButton.frame.size.height);
702+
CGFloat leftButtonX = startX + availableWidth / 3 - leftButton.frame.size.width / 2 - sideOffset;
703+
CGFloat rightButtonX = startX + 2 * availableWidth / 3 - rightButton.frame.size.width / 2 + sideOffset;
704+
705+
leftButton.frame = CGRectMake(leftButtonX, offset, leftButton.frame.size.width, leftButton.frame.size.height);
706+
rightButton.frame = CGRectMake(rightButtonX, offset, rightButton.frame.size.width, rightButton.frame.size.height);
688707
}
689-
else if (buttons.count == 3)
690-
{
708+
else if (buttons.count == 3) {
691709
UIView *leftButton = buttons.firstObject;
692710
UIView *centerButton = [buttons objectAtIndex:1];
693711
UIView *rightButton = buttons.lastObject;
694712

695-
centerButton.frame = CGRectMake(CGFloor(self.frame.size.width / 2 - centerButton.frame.size.width / 2), offset, centerButton.frame.size.width, centerButton.frame.size.height);
696-
697-
leftButton.frame = CGRectMake(CGFloor(self.frame.size.width / 6 * 2 - 10 - leftButton.frame.size.width / 2), offset, leftButton.frame.size.width, leftButton.frame.size.height);
713+
CGFloat leftButtonX = startX + availableWidth / 4 - leftButton.frame.size.width / 2 - sideOffset;
714+
CGFloat centerButtonX = startX + availableWidth / 2 - centerButton.frame.size.width / 2;
715+
CGFloat rightButtonX = startX + 3 * availableWidth / 4 - rightButton.frame.size.width / 2 + sideOffset;
698716

699-
rightButton.frame = CGRectMake(CGCeil(self.frame.size.width - leftButton.frame.origin.x - rightButton.frame.size.width), offset, rightButton.frame.size.width, rightButton.frame.size.height);
717+
leftButton.frame = CGRectMake(leftButtonX, offset, leftButton.frame.size.width, leftButton.frame.size.height);
718+
centerButton.frame = CGRectMake(centerButtonX, offset, centerButton.frame.size.width, centerButton.frame.size.height);
719+
rightButton.frame = CGRectMake(rightButtonX, offset, rightButton.frame.size.width, rightButton.frame.size.height);
700720
}
701-
else if (buttons.count == 4)
702-
{
721+
else if (buttons.count == 4) {
703722
UIView *leftButton = buttons.firstObject;
704723
UIView *centerLeftButton = [buttons objectAtIndex:1];
705724
UIView *centerRightButton = [buttons objectAtIndex:2];
706725
UIView *rightButton = buttons.lastObject;
707726

708-
leftButton.frame = CGRectMake(CGFloor(self.frame.size.width / 8 * 2 - 3 - leftButton.frame.size.width / 2), offset, leftButton.frame.size.width, leftButton.frame.size.height);
709-
710-
centerLeftButton.frame = CGRectMake(CGFloor(self.frame.size.width / 10 * 4 + 5 - centerLeftButton.frame.size.width / 2), offset, centerLeftButton.frame.size.width, centerLeftButton.frame.size.height);
711-
712-
centerRightButton.frame = CGRectMake(CGCeil(self.frame.size.width - centerLeftButton.frame.origin.x - centerRightButton.frame.size.width), offset, centerRightButton.frame.size.width, centerRightButton.frame.size.height);
727+
CGFloat leftButtonX = startX + availableWidth / 5 - leftButton.frame.size.width / 2 - sideOffset;
728+
CGFloat centerLeftButtonX = startX + 2 * availableWidth / 5 - centerLeftButton.frame.size.width / 2 - TGScreenPixelFloor(sideOffset / 2.0);
729+
CGFloat centerRightButtonX = startX + 3 * availableWidth / 5 - centerRightButton.frame.size.width / 2 + TGScreenPixelFloor(sideOffset / 2.0);
730+
CGFloat rightButtonX = startX + 4 * availableWidth / 5 - rightButton.frame.size.width / 2 + sideOffset;
713731

714-
rightButton.frame = CGRectMake(CGCeil(self.frame.size.width - leftButton.frame.origin.x - rightButton.frame.size.width), offset, rightButton.frame.size.width, rightButton.frame.size.height);
732+
leftButton.frame = CGRectMake(leftButtonX, offset, leftButton.frame.size.width, leftButton.frame.size.height);
733+
centerLeftButton.frame = CGRectMake(centerLeftButtonX, offset, centerLeftButton.frame.size.width, centerLeftButton.frame.size.height);
734+
centerRightButton.frame = CGRectMake(centerRightButtonX, offset, centerRightButton.frame.size.width, centerRightButton.frame.size.height);
735+
rightButton.frame = CGRectMake(rightButtonX, offset, rightButton.frame.size.width, rightButton.frame.size.height);
715736
}
716737

717-
_cancelButton.frame = CGRectMake(0, 0, 49, 49);
718738
CGFloat offset = 49.0f;
719739
if (_doneButton.frame.size.width > 49.0f)
720740
offset = 60.0f;
721-
722-
if (_starsDoneButton != nil) {
723-
CGSize buttonSize = [_starsDoneButton updateCount:_sendPaidMessageStars];
724-
[_starsDoneButton updateFrame:CGRectMake(self.frame.size.width - buttonSize.width - 2.0, 49.0f - offset + 2.0f, buttonSize.width, buttonSize.height)];
725-
}
726-
727741
_doneButton.frame = CGRectMake(self.frame.size.width - offset, 49.0f - offset, _doneButton.frame.size.width, _doneButton.frame.size.height);
728742

729743
_infoLabel.frame = CGRectMake(49.0f + 10.0f, 0.0f, self.frame.size.width - (49.0f + 10.0f) * 2.0f, 49.0f);

submodules/ShareController/Sources/ShareController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ public final class ShareController: ViewController {
674674

675675
if case let .messages(messages) = self.subject {
676676
messageCount = messages.count
677-
} else if case let .image(images) = self.subject {
678-
messageCount = images.count
677+
} else if case .image = self.subject {
678+
messageCount = 1
679679
} else if case let .fromExternal(count, _) = self.subject {
680680
messageCount = count
681681
}

submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode {
21532153
})))
21542154
}
21552155

2156-
if isSaved {
2156+
if isSaved && interfaceState.sendPaidMessageStars == nil {
21572157
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in
21582158
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.actionSheet.primaryTextColor)
21592159
}, action: { [weak self] _, f in
@@ -2764,6 +2764,13 @@ public final class EmojiContentPeekBehaviorImpl: EmojiContentPeekBehavior {
27642764
}))
27652765
}
27662766
} else {
2767+
let sendPaidMessageStars: Signal<StarsAmount?, NoError>
2768+
if let chatPeerId = strongSelf.chatPeerId {
2769+
sendPaidMessageStars = context.engine.data.get(TelegramEngine.EngineData.Item.Peer.SendPaidMessageStars(id: chatPeerId))
2770+
} else {
2771+
sendPaidMessageStars = .single(nil)
2772+
}
2773+
27672774
return combineLatest(
27682775
context.engine.stickers.isStickerSaved(id: file.fileId),
27692776
context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: accountPeerId)) |> map { peer -> Bool in
@@ -2772,10 +2779,11 @@ public final class EmojiContentPeekBehaviorImpl: EmojiContentPeekBehavior {
27722779
hasPremium = true
27732780
}
27742781
return hasPremium
2775-
}
2782+
},
2783+
sendPaidMessageStars
27762784
)
27772785
|> deliverOnMainQueue
2778-
|> map { [weak itemLayer] isStarred, hasPremium -> (UIView, CGRect, PeekControllerContent)? in
2786+
|> map { [weak itemLayer] isStarred, hasPremium, sendPaidMessageStars -> (UIView, CGRect, PeekControllerContent)? in
27792787
guard let strongSelf = self, let itemLayer = itemLayer else {
27802788
return nil
27812789
}
@@ -2805,18 +2813,20 @@ public final class EmojiContentPeekBehaviorImpl: EmojiContentPeekBehavior {
28052813
})))
28062814
}
28072815

2808-
menuItems.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in
2809-
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.actionSheet.primaryTextColor)
2810-
}, action: { _, f in
2811-
if let strongSelf = self, let peekController = strongSelf.peekController {
2812-
if let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
2813-
let _ = sendSticker(.standalone(media: file), false, true, nil, false, animationNode.view, animationNode.bounds, nil)
2814-
} else if let imageNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.imageNode {
2815-
let _ = sendSticker(.standalone(media: file), false, true, nil, false, imageNode.view, imageNode.bounds, nil)
2816+
if sendPaidMessageStars == nil {
2817+
menuItems.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in
2818+
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.actionSheet.primaryTextColor)
2819+
}, action: { _, f in
2820+
if let strongSelf = self, let peekController = strongSelf.peekController {
2821+
if let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
2822+
let _ = sendSticker(.standalone(media: file), false, true, nil, false, animationNode.view, animationNode.bounds, nil)
2823+
} else if let imageNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.imageNode {
2824+
let _ = sendSticker(.standalone(media: file), false, true, nil, false, imageNode.view, imageNode.bounds, nil)
2825+
}
28162826
}
2817-
}
2818-
f(.default)
2819-
})))
2827+
f(.default)
2828+
})))
2829+
}
28202830
}
28212831

28222832
menuItems.append(

submodules/TelegramUI/Components/LegacyCamera/Sources/LegacyCamera.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ShareController
1010
import LegacyUI
1111
import LegacyMediaPickerUI
1212

13-
public func presentedLegacyCamera(context: AccountContext, peer: Peer?, chatLocation: ChatLocation, cameraView: TGAttachmentCameraView?, menuController: TGMenuSheetController?, parentController: ViewController, attachmentController: ViewController? = nil, editingMedia: Bool, saveCapturedPhotos: Bool, mediaGrouping: Bool, initialCaption: NSAttributedString, hasSchedule: Bool, enablePhoto: Bool, enableVideo: Bool, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32, ChatSendMessageActionSheetController.SendParameters?) -> Void, recognizedQRCode: @escaping (String) -> Void = { _ in }, presentSchedulePicker: @escaping (Bool, @escaping (Int32) -> Void) -> Void, presentTimerPicker: @escaping (@escaping (Int32) -> Void) -> Void, getCaptionPanelView: @escaping () -> TGCaptionPanelView?, dismissedWithResult: @escaping () -> Void = {}, finishedTransitionIn: @escaping () -> Void = {}) {
13+
public func presentedLegacyCamera(context: AccountContext, peer: Peer?, chatLocation: ChatLocation, cameraView: TGAttachmentCameraView?, menuController: TGMenuSheetController?, parentController: ViewController, attachmentController: ViewController? = nil, editingMedia: Bool, saveCapturedPhotos: Bool, mediaGrouping: Bool, initialCaption: NSAttributedString, hasSchedule: Bool, enablePhoto: Bool, enableVideo: Bool, sendPaidMessageStars: Int64 = 0, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32, ChatSendMessageActionSheetController.SendParameters?) -> Void, recognizedQRCode: @escaping (String) -> Void = { _ in }, presentSchedulePicker: @escaping (Bool, @escaping (Int32) -> Void) -> Void, presentTimerPicker: @escaping (@escaping (Int32) -> Void) -> Void, getCaptionPanelView: @escaping () -> TGCaptionPanelView?, dismissedWithResult: @escaping () -> Void = {}, finishedTransitionIn: @escaping () -> Void = {}) {
1414
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
1515
let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme)
1616
legacyController.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .portrait, compactSize: .portrait)
@@ -35,6 +35,7 @@ public func presentedLegacyCamera(context: AccountContext, peer: Peer?, chatLoca
3535
} else {
3636
controller = TGCameraController(context: legacyController.context, saveEditedPhotos: saveCapturedPhotos && !isSecretChat, saveCapturedMedia: saveCapturedPhotos && !isSecretChat)
3737
}
38+
controller.sendPaidMessageStars = sendPaidMessageStars
3839
controller.modalPresentationStyle = .fullScreen
3940
controller.inhibitMultipleCapture = editingMedia
4041

submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerViewSendMessage.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,17 @@ final class StoryItemSetContainerSendMessage {
429429
})))
430430
}
431431

432-
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.contextMenu.primaryColor)
433-
}, action: { [weak self, weak view] _, a in
434-
a(.default)
435-
436-
guard let self, let view else {
437-
return
438-
}
439-
self.presentScheduleTimePicker(view: view)
440-
})))
432+
if component.slice.additionalPeerData.sendPaidMessageStars == nil {
433+
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.contextMenu.primaryColor)
434+
}, action: { [weak self, weak view] _, a in
435+
a(.default)
436+
437+
guard let self, let view else {
438+
return
439+
}
440+
self.presentScheduleTimePicker(view: view)
441+
})))
442+
}
441443

442444

443445
let contextItems = ContextController.Items(content: .list(items))

submodules/TelegramUI/Sources/Chat/ChatControllerPaidMessage.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ extension ChatControllerImpl {
2828
guard let self, let starsContext = self.context.starsContext else {
2929
return
3030
}
31-
if let dismissedAmount, dismissedAmount == sendPaidMessageStars.value, let currentState = starsContext.currentState, currentState.balance.value > totalAmount, count < 3 && totalAmount < 100 {
32-
completion(true)
33-
self.displayPaidMessageUndo(count: count, amount: sendPaidMessageStars)
31+
if let dismissedAmount, dismissedAmount == sendPaidMessageStars.value, let currentState = starsContext.currentState, currentState.balance.value > totalAmount {
32+
if count < 3 && totalAmount < 100 {
33+
completion(false)
34+
} else {
35+
completion(true)
36+
self.displayPaidMessageUndo(count: count, amount: sendPaidMessageStars)
37+
}
3438
} else {
3539
var presentationData = self.presentationData
3640
if forceDark {

submodules/TelegramUI/Sources/ChatController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9288,12 +9288,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
92889288
var attributes = attributes
92899289

92909290
if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars {
9291+
var effectivePostpone = postpone
92919292
for i in (0 ..< attributes.count).reversed() {
9292-
if attributes[i] is PaidStarsMessageAttribute {
9293+
if let paidStarsMessageAttribute = attributes[i] as? PaidStarsMessageAttribute {
9294+
effectivePostpone = effectivePostpone || paidStarsMessageAttribute.postponeSending
92939295
attributes.remove(at: i)
92949296
}
92959297
}
9296-
attributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: postpone))
9298+
attributes.append(PaidStarsMessageAttribute(stars: sendPaidMessageStars, postponeSending: effectivePostpone))
92979299
}
92989300

92999301
if silentPosting || scheduleTime != nil {

0 commit comments

Comments
 (0)