Skip to content

Commit d8dd96e

Browse files
committed
[WIP] Multiple story upload
1 parent 746239c commit d8dd96e

File tree

21 files changed

+1351
-348
lines changed

21 files changed

+1351
-348
lines changed

Telegram/Telegram-iOS/en.lproj/Localizable.strings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14188,3 +14188,12 @@ Sorry for the inconvenience.";
1418814188
"SendInviteLink.TextCallsRestrictedMultipleUsers_1" = "{user_list}, and **%d** more person do not accept calls.";
1418914189
"SendInviteLink.TextCallsRestrictedMultipleUsers_any" = "{user_list}, and **%d** more people do not accept calls.";
1419014190
"SendInviteLink.TextCallsRestrictedSendInviteLink" = "You can try to send an invite link instead.";
14191+
14192+
"Story.Privacy.ShareStories" = "Share Stories";
14193+
"Story.Privacy.PostStoriesAsHeader" = "POST STORIES AS";
14194+
"Story.Privacy.WhoCanViewStoriesHeader" = "WHO CAN VIEW THIS STORIES";
14195+
"Story.Privacy.PostStories_1" = "Post %@ Story";
14196+
"Story.Privacy.PostStories_any" = "Post %@ Stories";
14197+
"Story.Privacy.KeepOnMyPageManyInfo" = "Keep these stories on your profile even after they expire in %@. Privacy settings will apply.";
14198+
"Story.Privacy.KeepOnChannelPageManyInfo" = "Keep these stories on the channel profile even after they expire in %@.";
14199+
"Story.Privacy.KeepOnGroupPageManyInfo" = "Keep these stories on the group page even after they expire in %@.";

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public protocol MediaEditorScreenResult {
809809
public protocol TelegramRootControllerInterface: NavigationController {
810810
@discardableResult
811811
func openStoryCamera(customTarget: Stories.PendingTarget?, transitionIn: StoryCameraTransitionIn?, transitionedIn: @escaping () -> Void, transitionOut: @escaping (Stories.PendingTarget?, Bool) -> StoryCameraTransitionOut?) -> StoryCameraTransitionInCoordinator?
812-
func proceedWithStoryUpload(target: Stories.PendingTarget, result: MediaEditorScreenResult, existingMedia: EngineMedia?, forwardInfo: Stories.PendingForwardInfo?, externalState: MediaEditorTransitionOutExternalState, commit: @escaping (@escaping () -> Void) -> Void)
812+
func proceedWithStoryUpload(target: Stories.PendingTarget, results: [MediaEditorScreenResult], existingMedia: EngineMedia?, forwardInfo: Stories.PendingForwardInfo?, externalState: MediaEditorTransitionOutExternalState, commit: @escaping (@escaping () -> Void) -> Void)
813813

814814
func getContactsController() -> ViewController?
815815
func getChatsController() -> ViewController?
@@ -1152,7 +1152,7 @@ public protocol SharedAccountContext: AnyObject {
11521152

11531153
func makeAvatarMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect?, canDelete: Bool, performDelete: @escaping () -> Void, completion: @escaping (Any?, UIView?, CGRect, UIImage?, Bool, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void) -> ViewController
11541154

1155-
func makeStoryMediaPickerScreen(context: AccountContext, isDark: Bool, forCollage: Bool, selectionLimit: Int?, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, multipleCompletion: @escaping ([Any]) -> Void, dismissed: @escaping () -> Void, groupsPresented: @escaping () -> Void) -> ViewController
1155+
func makeStoryMediaPickerScreen(context: AccountContext, isDark: Bool, forCollage: Bool, selectionLimit: Int?, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, multipleCompletion: @escaping ([Any], Bool) -> Void, dismissed: @escaping () -> Void, groupsPresented: @escaping () -> Void) -> ViewController
11561156

11571157
func makeStickerPickerScreen(context: AccountContext, inputData: Promise<StickerPickerInput>, completion: @escaping (FileMediaReference) -> Void) -> ViewController
11581158

submodules/AccountContext/Sources/AttachmentMainButtonState.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public struct AttachmentMainButtonState {
4242
public let isEnabled: Bool
4343
public let hasShimmer: Bool
4444
public let iconName: String?
45+
public let smallSpacing: Bool
4546
public let position: Position?
4647

4748
public init(
@@ -55,6 +56,7 @@ public struct AttachmentMainButtonState {
5556
isEnabled: Bool,
5657
hasShimmer: Bool,
5758
iconName: String? = nil,
59+
smallSpacing: Bool = false,
5860
position: Position? = nil
5961
) {
6062
self.text = text
@@ -67,6 +69,7 @@ public struct AttachmentMainButtonState {
6769
self.isEnabled = isEnabled
6870
self.hasShimmer = hasShimmer
6971
self.iconName = iconName
72+
self.smallSpacing = smallSpacing
7073
self.position = position
7174
}
7275

submodules/AttachmentUI/Sources/AttachmentPanel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
790790
iconNode = ASImageNode()
791791
iconNode.displaysAsynchronously = false
792792
iconNode.image = generateTintedImage(image: UIImage(bundleImageName: iconName), color: state.textColor)
793+
self.iconNode = iconNode
793794
self.addSubnode(iconNode)
794795
}
795796
if let iconSize = iconNode.image?.size {
@@ -1806,7 +1807,9 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate {
18061807
} else {
18071808
height = bounds.height + 8.0
18081809
}
1809-
if !isNarrowButton {
1810+
if isTwoVerticalButtons && self.secondaryButtonState.smallSpacing {
1811+
1812+
} else if !isNarrowButton {
18101813
height += 9.0
18111814
}
18121815
if isTwoVerticalButtons {
@@ -1896,7 +1899,8 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate {
18961899
mainButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX, y: buttonOriginY + sideInset + buttonSize.height), size: buttonSize)
18971900
case .bottom:
18981901
mainButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX, y: buttonOriginY), size: buttonSize)
1899-
secondaryButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX, y: buttonOriginY + sideInset + buttonSize.height), size: buttonSize)
1902+
let buttonSpacing = self.secondaryButtonState.smallSpacing ? 8.0 : sideInset
1903+
secondaryButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX, y: buttonOriginY + buttonSpacing + buttonSize.height), size: buttonSize)
19001904
case .left:
19011905
secondaryButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX, y: buttonOriginY), size: buttonSize)
19021906
mainButtonFrame = CGRect(origin: CGPoint(x: buttonOriginX + buttonSize.width + sideInset, y: buttonOriginY), size: buttonSize)

submodules/DrawingUI/Sources/DrawingEntitiesView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
566566
self.hasSelectionChanged(false)
567567
}
568568

569+
public func clearAll() {
570+
for case let view as DrawingEntityView in self.subviews {
571+
view.reset()
572+
view.selectionView?.removeFromSuperview()
573+
view.removeFromSuperview()
574+
}
575+
}
576+
569577
private func clear(animated: Bool = false) {
570578
if animated {
571579
for case let view as DrawingEntityView in self.subviews {

submodules/MediaPickerUI/Sources/MediaPickerScreen.swift

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
184184
private let bannedSendVideos: (Int32, Bool)?
185185
private let canBoostToUnrestrict: Bool
186186
fileprivate let paidMediaAllowed: Bool
187-
private let subject: Subject
187+
fileprivate let subject: Subject
188188
fileprivate let forCollage: Bool
189189
private let saveEditedPhotos: Bool
190190

@@ -1826,6 +1826,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18261826
fileprivate let secondaryButtonStatePromise = Promise<AttachmentMainButtonState?>(nil)
18271827

18281828
private let mainButtonAction: (() -> Void)?
1829+
private let secondaryButtonAction: (() -> Void)?
18291830

18301831
public init(
18311832
context: AccountContext,
@@ -1845,7 +1846,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18451846
selectionContext: TGMediaSelectionContext? = nil,
18461847
saveEditedPhotos: Bool = false,
18471848
mainButtonState: AttachmentMainButtonState? = nil,
1848-
mainButtonAction: (() -> Void)? = nil
1849+
mainButtonAction: (() -> Void)? = nil,
1850+
secondaryButtonAction: (() -> Void)? = nil
18491851
) {
18501852
self.context = context
18511853

@@ -1865,6 +1867,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18651867
self.saveEditedPhotos = saveEditedPhotos
18661868
self.mainButtonStatePromise.set(.single(mainButtonState))
18671869
self.mainButtonAction = mainButtonAction
1870+
self.secondaryButtonAction = secondaryButtonAction
18681871

18691872
let selectionContext = selectionContext ?? TGMediaSelectionContext()
18701873

@@ -1998,7 +2001,14 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
19982001
} else if collection == nil {
19992002
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed))
20002003

2004+
var hasSelect = false
20012005
if forCollage {
2006+
hasSelect = true
2007+
} else if case .story = mode {
2008+
hasSelect = true
2009+
}
2010+
2011+
if hasSelect {
20022012
self.navigationItem.rightBarButtonItem = UIBarButtonItem(backButtonAppearanceWithTitle: self.presentationData.strings.Common_Select, target: self, action: #selector(self.selectPressed))
20032013
} else {
20042014
if [.createSticker].contains(mode) {
@@ -2338,6 +2348,9 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23382348
let transition = ContainedViewLayoutTransition.animated(duration: 0.25, curve: .easeInOut)
23392349
var moreIsVisible = false
23402350
if case let .assets(_, mode) = self.subject, [.story, .createSticker].contains(mode) {
2351+
if count == 1 {
2352+
self.requestAttachmentMenuExpansion()
2353+
}
23412354
moreIsVisible = true
23422355
} else if case let .media(media) = self.subject {
23432356
self.titleView.title = media.count == 1 ? self.presentationData.strings.Attachment_Pasteboard : self.presentationData.strings.Attachment_SelectedMedia(count)
@@ -2381,7 +2394,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23812394
transition.updateAlpha(node: self.moreButtonNode.iconNode, alpha: moreIsVisible ? 1.0 : 0.0)
23822395
transition.updateTransformScale(node: self.moreButtonNode.iconNode, scale: moreIsVisible ? 1.0 : 0.1)
23832396

2384-
if self.selectionCount > 0 {
2397+
if case .assets(_, .story) = self.subject, self.selectionCount > 0 {
23852398
//TODO:localize
23862399
var text = "Create 1 Story"
23872400
if self.selectionCount > 1 {
@@ -2390,7 +2403,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23902403
self.mainButtonStatePromise.set(.single(AttachmentMainButtonState(text: text, badge: nil, font: .bold, background: .color(self.presentationData.theme.actionSheet.controlAccentColor), textColor: self.presentationData.theme.list.itemCheckColors.foregroundColor, isVisible: true, progress: .none, isEnabled: true, hasShimmer: false, position: .top)))
23912404

23922405
if self.selectionCount > 1 && self.selectionCount <= 6 {
2393-
self.secondaryButtonStatePromise.set(.single(AttachmentMainButtonState(text: "Combine into Collage", badge: nil, font: .regular, background: .color(.clear), textColor: self.presentationData.theme.actionSheet.controlAccentColor, isVisible: true, progress: .none, isEnabled: true, hasShimmer: false, iconName: "Media Editor/Collage", position: .bottom)))
2406+
self.secondaryButtonStatePromise.set(.single(AttachmentMainButtonState(text: "Combine into Collage", badge: nil, font: .regular, background: .color(.clear), textColor: self.presentationData.theme.actionSheet.controlAccentColor, isVisible: true, progress: .none, isEnabled: true, hasShimmer: false, iconName: "Media Editor/Collage", smallSpacing: true, position: .bottom)))
23942407
} else {
23952408
self.secondaryButtonStatePromise.set(.single(nil))
23962409
}
@@ -2427,6 +2440,10 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
24272440
self.mainButtonAction?()
24282441
}
24292442

2443+
func secondaryButtonPressed() {
2444+
self.secondaryButtonAction?()
2445+
}
2446+
24302447
func dismissAllTooltips() {
24312448
self.undoOverlayController?.dismissWithCommitAction()
24322449
}
@@ -2810,7 +2827,7 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
28102827
private weak var controller: MediaPickerScreenImpl?
28112828

28122829
var selectionCount: Signal<Int, NoError> {
2813-
if self.controller?.forCollage == true {
2830+
if let controller = self.controller, case .assets(_, .story) = controller.subject {
28142831
return .single(0)
28152832
} else {
28162833
return Signal { [weak self] subscriber in
@@ -2973,7 +2990,7 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
29732990
}
29742991

29752992
func secondaryButtonAction() {
2976-
self.controller?.mainButtonPressed()
2993+
self.controller?.secondaryButtonPressed()
29772994
}
29782995
}
29792996

@@ -3162,7 +3179,7 @@ public func storyMediaPickerController(
31623179
selectionLimit: Int?,
31633180
getSourceRect: @escaping () -> CGRect,
31643181
completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void,
3165-
multipleCompletion: @escaping ([Any]) -> Void,
3182+
multipleCompletion: @escaping ([Any], Bool) -> Void,
31663183
dismissed: @escaping () -> Void,
31673184
groupsPresented: @escaping () -> Void
31683185
) -> ViewController {
@@ -3181,9 +3198,18 @@ public func storyMediaPickerController(
31813198
}
31823199
}
31833200

3184-
let controller = AttachmentController(context: context, updatedPresentationData: updatedPresentationData, chatLocation: nil, buttons: [.standalone], initialButton: .standalone, fromMenu: false, hasTextInput: false, makeEntityInputView: {
3185-
return nil
3186-
})
3201+
let controller = AttachmentController(
3202+
context: context,
3203+
updatedPresentationData: updatedPresentationData,
3204+
chatLocation: nil,
3205+
buttons: [.standalone],
3206+
initialButton: .standalone,
3207+
fromMenu: false,
3208+
hasTextInput: false,
3209+
makeEntityInputView: {
3210+
return nil
3211+
}
3212+
)
31873213
controller.forceSourceRect = true
31883214
controller.getSourceRect = getSourceRect
31893215
controller.requestController = { _, present in
@@ -3207,7 +3233,18 @@ public func storyMediaPickerController(
32073233
results.append(asset)
32083234
}
32093235
}
3210-
multipleCompletion(results)
3236+
multipleCompletion(results, false)
3237+
}
3238+
},
3239+
secondaryButtonAction: { [weak selectionContext] in
3240+
if let selectionContext, let selectedItems = selectionContext.selectedItems() {
3241+
var results: [Any] = []
3242+
for item in selectedItems {
3243+
if let item = item as? TGMediaAsset, let asset = item.backingAsset {
3244+
results.append(asset)
3245+
}
3246+
}
3247+
multipleCompletion(results, true)
32113248
}
32123249
}
32133250
)

0 commit comments

Comments
 (0)