mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
c5081979f0
commit
4a9258cc65
@ -97,6 +97,7 @@ public extension Stories {
|
||||
case period
|
||||
case randomId
|
||||
case forwardInfo
|
||||
case uploadInfo
|
||||
}
|
||||
|
||||
public let target: PendingTarget
|
||||
@ -113,6 +114,7 @@ public extension Stories {
|
||||
public let period: Int32
|
||||
public let randomId: Int64
|
||||
public let forwardInfo: PendingForwardInfo?
|
||||
public let uploadInfo: StoryUploadInfo?
|
||||
|
||||
public init(
|
||||
target: PendingTarget,
|
||||
@ -128,7 +130,8 @@ public extension Stories {
|
||||
isForwardingDisabled: Bool,
|
||||
period: Int32,
|
||||
randomId: Int64,
|
||||
forwardInfo: PendingForwardInfo?
|
||||
forwardInfo: PendingForwardInfo?,
|
||||
uploadInfo: StoryUploadInfo?
|
||||
) {
|
||||
self.target = target
|
||||
self.stableId = stableId
|
||||
@ -144,6 +147,7 @@ public extension Stories {
|
||||
self.period = period
|
||||
self.randomId = randomId
|
||||
self.forwardInfo = forwardInfo
|
||||
self.uploadInfo = uploadInfo
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@ -171,6 +175,8 @@ public extension Stories {
|
||||
self.randomId = try container.decode(Int64.self, forKey: .randomId)
|
||||
|
||||
self.forwardInfo = try container.decodeIfPresent(PendingForwardInfo.self, forKey: .forwardInfo)
|
||||
|
||||
self.uploadInfo = try container.decodeIfPresent(StoryUploadInfo.self, forKey: .uploadInfo)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -199,6 +205,7 @@ public extension Stories {
|
||||
try container.encode(self.period, forKey: .period)
|
||||
try container.encode(self.randomId, forKey: .randomId)
|
||||
try container.encodeIfPresent(self.forwardInfo, forKey: .forwardInfo)
|
||||
try container.encodeIfPresent(self.uploadInfo, forKey: .uploadInfo)
|
||||
}
|
||||
|
||||
public static func ==(lhs: PendingItem, rhs: PendingItem) -> Bool {
|
||||
@ -238,6 +245,9 @@ public extension Stories {
|
||||
if lhs.forwardInfo != rhs.forwardInfo {
|
||||
return false
|
||||
}
|
||||
if lhs.uploadInfo != rhs.uploadInfo {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -467,7 +477,12 @@ final class PendingStoryManager {
|
||||
switch event {
|
||||
case let .progress(progress):
|
||||
if let currentPendingItemContext = self.currentPendingItemContext, currentPendingItemContext.item.stableId == stableId {
|
||||
currentPendingItemContext.progress = progress
|
||||
if let uploadInfo = currentPendingItemContext.item.uploadInfo {
|
||||
let partTotalProgress = 1.0 / Float(uploadInfo.total)
|
||||
currentPendingItemContext.progress = Float(uploadInfo.index) * partTotalProgress + progress * partTotalProgress
|
||||
} else {
|
||||
currentPendingItemContext.progress = progress
|
||||
}
|
||||
currentPendingItemContext.updated()
|
||||
}
|
||||
case let .completed(id):
|
||||
|
@ -976,7 +976,19 @@ private func apiInputPrivacyRules(privacy: EngineStoryPrivacy, transaction: Tran
|
||||
return privacyRules
|
||||
}
|
||||
|
||||
func _internal_uploadStory(account: Account, target: Stories.PendingTarget, media: EngineStoryInputMedia, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], pin: Bool, privacy: EngineStoryPrivacy, isForwardingDisabled: Bool, period: Int, randomId: Int64, forwardInfo: Stories.PendingForwardInfo?) -> Signal<Int32, NoError> {
|
||||
public struct StoryUploadInfo: Codable, Equatable {
|
||||
public var groupingId: Int32
|
||||
public var index: Int32
|
||||
public var total: Int32
|
||||
|
||||
public init(groupingId: Int32, index: Int32, total: Int32) {
|
||||
self.groupingId = groupingId
|
||||
self.index = index
|
||||
self.total = total
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_uploadStory(account: Account, target: Stories.PendingTarget, media: EngineStoryInputMedia, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], pin: Bool, privacy: EngineStoryPrivacy, isForwardingDisabled: Bool, period: Int, randomId: Int64, forwardInfo: Stories.PendingForwardInfo?, uploadInfo: StoryUploadInfo? = nil) -> Signal<Int32, NoError> {
|
||||
let inputMedia = prepareUploadStoryContent(account: account, media: media)
|
||||
|
||||
return (account.postbox.transaction { transaction in
|
||||
@ -1004,7 +1016,8 @@ func _internal_uploadStory(account: Account, target: Stories.PendingTarget, medi
|
||||
isForwardingDisabled: isForwardingDisabled,
|
||||
period: Int32(period),
|
||||
randomId: randomId,
|
||||
forwardInfo: forwardInfo
|
||||
forwardInfo: forwardInfo,
|
||||
uploadInfo: uploadInfo
|
||||
))
|
||||
transaction.setLocalStoryState(state: CodableEntry(currentState))
|
||||
return stableId
|
||||
@ -1020,7 +1033,50 @@ func _internal_cancelStoryUpload(account: Account, stableId: Int32) {
|
||||
currentState = Stories.LocalState(items: [])
|
||||
}
|
||||
if let index = currentState.items.firstIndex(where: { $0.stableId == stableId }) {
|
||||
currentState.items.remove(at: index)
|
||||
let cancelledItem = currentState.items[index]
|
||||
if let uploadInfo = cancelledItem.uploadInfo {
|
||||
let groupingId = uploadInfo.groupingId
|
||||
let total = uploadInfo.total - 1
|
||||
|
||||
currentState.items.remove(at: index)
|
||||
|
||||
for i in 0..<currentState.items.count {
|
||||
if let itemUploadInfo = currentState.items[i].uploadInfo, itemUploadInfo.groupingId == groupingId {
|
||||
let newIndex: Int32
|
||||
if itemUploadInfo.index > uploadInfo.index {
|
||||
newIndex = itemUploadInfo.index - 1
|
||||
} else {
|
||||
newIndex = itemUploadInfo.index
|
||||
}
|
||||
|
||||
let updatedItem = Stories.PendingItem(
|
||||
target: currentState.items[i].target,
|
||||
stableId: currentState.items[i].stableId,
|
||||
timestamp: currentState.items[i].timestamp,
|
||||
media: currentState.items[i].media,
|
||||
mediaAreas: currentState.items[i].mediaAreas,
|
||||
text: currentState.items[i].text,
|
||||
entities: currentState.items[i].entities,
|
||||
embeddedStickers: currentState.items[i].embeddedStickers,
|
||||
pin: currentState.items[i].pin,
|
||||
privacy: currentState.items[i].privacy,
|
||||
isForwardingDisabled: currentState.items[i].isForwardingDisabled,
|
||||
period: currentState.items[i].period,
|
||||
randomId: currentState.items[i].randomId,
|
||||
forwardInfo: currentState.items[i].forwardInfo,
|
||||
uploadInfo: StoryUploadInfo(
|
||||
groupingId: groupingId,
|
||||
index: newIndex,
|
||||
total: total
|
||||
)
|
||||
)
|
||||
|
||||
currentState.items[i] = updatedItem
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentState.items.remove(at: index)
|
||||
}
|
||||
transaction.setLocalStoryState(state: CodableEntry(currentState))
|
||||
}
|
||||
}).start()
|
||||
|
@ -1349,8 +1349,8 @@ public extension TelegramEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public func uploadStory(target: Stories.PendingTarget, media: EngineStoryInputMedia, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], pin: Bool, privacy: EngineStoryPrivacy, isForwardingDisabled: Bool, period: Int, randomId: Int64, forwardInfo: Stories.PendingForwardInfo?) -> Signal<Int32, NoError> {
|
||||
return _internal_uploadStory(account: self.account, target: target, media: media, mediaAreas: mediaAreas, text: text, entities: entities, pin: pin, privacy: privacy, isForwardingDisabled: isForwardingDisabled, period: period, randomId: randomId, forwardInfo: forwardInfo)
|
||||
public func uploadStory(target: Stories.PendingTarget, media: EngineStoryInputMedia, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], pin: Bool, privacy: EngineStoryPrivacy, isForwardingDisabled: Bool, period: Int, randomId: Int64, forwardInfo: Stories.PendingForwardInfo?, uploadInfo: StoryUploadInfo? = nil) -> Signal<Int32, NoError> {
|
||||
return _internal_uploadStory(account: self.account, target: target, media: media, mediaAreas: mediaAreas, text: text, entities: entities, pin: pin, privacy: privacy, isForwardingDisabled: isForwardingDisabled, period: period, randomId: randomId, forwardInfo: forwardInfo, uploadInfo: uploadInfo)
|
||||
}
|
||||
|
||||
public func allStoriesUploadEvents() -> Signal<(Int32, Int32), NoError> {
|
||||
|
@ -44,8 +44,10 @@ extension MediaEditorScreenImpl {
|
||||
|
||||
let storyCount = min(storyMaxCombinedVideoCount, Int(ceil(duration / storyMaxVideoDuration)))
|
||||
var start = values.videoTrimRange?.lowerBound ?? 0
|
||||
let end = values.videoTrimRange?.upperBound ?? (min(originalDuration, start + storyMaxCombinedVideoDuration))
|
||||
|
||||
for i in 0 ..< storyCount {
|
||||
let trimmedValues = values.withUpdatedVideoTrimRange(start ..< min(start + storyMaxVideoDuration, originalDuration))
|
||||
let trimmedValues = values.withUpdatedVideoTrimRange(start ..< min(end, start + storyMaxVideoDuration))
|
||||
|
||||
var editingItem = EditingItem(asset: asset)
|
||||
if i == 0 {
|
||||
@ -526,7 +528,7 @@ extension MediaEditorScreenImpl {
|
||||
}
|
||||
|
||||
var items = items
|
||||
if let mediaEditor = self.node.mediaEditor, case let .asset(asset) = self.node.subject, let currentItemIndex = items.firstIndex(where: { $0.asset.localIdentifier == asset.localIdentifier }) {
|
||||
if !isLongVideo, let mediaEditor = self.node.mediaEditor, case let .asset(asset) = self.node.subject, let currentItemIndex = items.firstIndex(where: { $0.asset.localIdentifier == asset.localIdentifier }) {
|
||||
var updatedCurrentItem = items[currentItemIndex]
|
||||
updatedCurrentItem.caption = self.node.getCaption()
|
||||
updatedCurrentItem.values = mediaEditor.values
|
||||
|
@ -659,6 +659,8 @@ public final class TelegramRootController: NavigationController, TelegramRootCon
|
||||
}
|
||||
|
||||
if let _ = self.chatListController as? ChatListControllerImpl {
|
||||
var index: Int32 = 0
|
||||
let groupingId = Int32.random(in: 2000000 ..< Int32.max)
|
||||
for result in results {
|
||||
var media: EngineStoryInputMedia?
|
||||
|
||||
@ -732,12 +734,14 @@ public final class TelegramRootController: NavigationController, TelegramRootCon
|
||||
isForwardingDisabled: result.options.isForwardingDisabled,
|
||||
period: result.options.timeout,
|
||||
randomId: result.randomId,
|
||||
forwardInfo: forwardInfo
|
||||
forwardInfo: forwardInfo,
|
||||
uploadInfo: results.count > 1 ? StoryUploadInfo(groupingId: groupingId, index: index, total: Int32(results.count)) : nil
|
||||
)
|
||||
|> deliverOnMainQueue).startStandalone(next: { stableId in
|
||||
moveStorySource(engine: context.engine, peerId: context.account.peerId, from: result.randomId, to: Int64(stableId))
|
||||
})
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
completionImpl()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user