mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-03 21:16:35 +00:00
- some refactor
This commit is contained in:
parent
0549ec9cd5
commit
e1d6329524
@ -17,8 +17,8 @@
|
|||||||
C239BE981E62F0D200C2C453 /* LoadMessagesIfNecessary.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE961E62EE1E00C2C453 /* LoadMessagesIfNecessary.swift */; };
|
C239BE981E62F0D200C2C453 /* LoadMessagesIfNecessary.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE961E62EE1E00C2C453 /* LoadMessagesIfNecessary.swift */; };
|
||||||
C239BE9C1E630CA700C2C453 /* UpdatePinnedMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */; };
|
C239BE9C1E630CA700C2C453 /* UpdatePinnedMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */; };
|
||||||
C239BE9D1E630CB300C2C453 /* UpdatePinnedMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */; };
|
C239BE9D1E630CB300C2C453 /* UpdatePinnedMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */; };
|
||||||
C251D7431E65E50500283EDE /* StickersCloudInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickersCloudInstallation.swift */; };
|
C251D7431E65E50500283EDE /* StickerSetInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickerSetInstallation.swift */; };
|
||||||
C251D7441E65E50500283EDE /* StickersCloudInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickersCloudInstallation.swift */; };
|
C251D7441E65E50500283EDE /* StickerSetInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickerSetInstallation.swift */; };
|
||||||
C26A37EF1E5E0C41006977AC /* ChannelParticipants.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BB7C591E5C8074001527C3 /* ChannelParticipants.swift */; };
|
C26A37EF1E5E0C41006977AC /* ChannelParticipants.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BB7C591E5C8074001527C3 /* ChannelParticipants.swift */; };
|
||||||
C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01749581E1092BC0057C89A /* RequestStartBot.swift */; };
|
C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01749581E1092BC0057C89A /* RequestStartBot.swift */; };
|
||||||
D001F3E81E128A1C007A8C60 /* ChannelState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03B0CFF1D62255C00955575 /* ChannelState.swift */; };
|
D001F3E81E128A1C007A8C60 /* ChannelState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03B0CFF1D62255C00955575 /* ChannelState.swift */; };
|
||||||
@ -429,7 +429,7 @@
|
|||||||
C2366C881E4F40480097CCFF /* SupportPeerId.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupportPeerId.swift; sourceTree = "<group>"; };
|
C2366C881E4F40480097CCFF /* SupportPeerId.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupportPeerId.swift; sourceTree = "<group>"; };
|
||||||
C239BE961E62EE1E00C2C453 /* LoadMessagesIfNecessary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadMessagesIfNecessary.swift; sourceTree = "<group>"; };
|
C239BE961E62EE1E00C2C453 /* LoadMessagesIfNecessary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadMessagesIfNecessary.swift; sourceTree = "<group>"; };
|
||||||
C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePinnedMessage.swift; sourceTree = "<group>"; };
|
C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePinnedMessage.swift; sourceTree = "<group>"; };
|
||||||
C251D7421E65E50500283EDE /* StickersCloudInstallation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickersCloudInstallation.swift; sourceTree = "<group>"; };
|
C251D7421E65E50500283EDE /* StickerSetInstallation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerSetInstallation.swift; sourceTree = "<group>"; };
|
||||||
D003702A1DA42586004308D3 /* PhoneNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhoneNumber.swift; sourceTree = "<group>"; };
|
D003702A1DA42586004308D3 /* PhoneNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhoneNumber.swift; sourceTree = "<group>"; };
|
||||||
D00C7CCB1E3620C30080C3D5 /* CachedChannelParticipants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedChannelParticipants.swift; sourceTree = "<group>"; };
|
D00C7CCB1E3620C30080C3D5 /* CachedChannelParticipants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedChannelParticipants.swift; sourceTree = "<group>"; };
|
||||||
D00C7CCE1E3628180080C3D5 /* UpdateCachedChannelParticipants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateCachedChannelParticipants.swift; sourceTree = "<group>"; };
|
D00C7CCE1E3628180080C3D5 /* UpdateCachedChannelParticipants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateCachedChannelParticipants.swift; sourceTree = "<group>"; };
|
||||||
@ -709,7 +709,7 @@
|
|||||||
D021E0E11DB5401A00C6B04F /* StickerManagement.swift */,
|
D021E0E11DB5401A00C6B04F /* StickerManagement.swift */,
|
||||||
D01D6BF81E42A713006151C6 /* SearchStickers.swift */,
|
D01D6BF81E42A713006151C6 /* SearchStickers.swift */,
|
||||||
D049EAD71E43DAD200A2CD3A /* ManagedRecentStickers.swift */,
|
D049EAD71E43DAD200A2CD3A /* ManagedRecentStickers.swift */,
|
||||||
C251D7421E65E50500283EDE /* StickersCloudInstallation.swift */,
|
C251D7421E65E50500283EDE /* StickerSetInstallation.swift */,
|
||||||
);
|
);
|
||||||
name = "Sticker Management";
|
name = "Sticker Management";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1496,7 +1496,7 @@
|
|||||||
D0B843C51DA7FF30005F29E1 /* NBPhoneNumber.m in Sources */,
|
D0B843C51DA7FF30005F29E1 /* NBPhoneNumber.m in Sources */,
|
||||||
D03B0D0D1D62255C00955575 /* SynchronizePeerReadState.swift in Sources */,
|
D03B0D0D1D62255C00955575 /* SynchronizePeerReadState.swift in Sources */,
|
||||||
D03B0D081D62255C00955575 /* ChannelState.swift in Sources */,
|
D03B0D081D62255C00955575 /* ChannelState.swift in Sources */,
|
||||||
C251D7431E65E50500283EDE /* StickersCloudInstallation.swift in Sources */,
|
C251D7431E65E50500283EDE /* StickerSetInstallation.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -1693,7 +1693,7 @@
|
|||||||
D073CE6F1DCBCF17007511FD /* OutgoingMessageInfoAttribute.swift in Sources */,
|
D073CE6F1DCBCF17007511FD /* OutgoingMessageInfoAttribute.swift in Sources */,
|
||||||
D0B844431DAB91FD005F29E1 /* Account.swift in Sources */,
|
D0B844431DAB91FD005F29E1 /* Account.swift in Sources */,
|
||||||
D0448CA01E27F5EB005A61A7 /* Random.swift in Sources */,
|
D0448CA01E27F5EB005A61A7 /* Random.swift in Sources */,
|
||||||
C251D7441E65E50500283EDE /* StickersCloudInstallation.swift in Sources */,
|
C251D7441E65E50500283EDE /* StickerSetInstallation.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import Foundation
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public enum CloudStickersLoadingError {
|
|
||||||
|
public enum RequestStickerSetError {
|
||||||
case generic
|
case generic
|
||||||
case invalid
|
case invalid
|
||||||
}
|
}
|
||||||
@ -30,32 +31,48 @@ fileprivate extension Api.StickerSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func requestCloudStickerPack(account:Account, reference: StickerPackReference) -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem], Bool), CloudStickersLoadingError> {
|
public enum RequestStickerSetResult {
|
||||||
|
case local(info: ItemCollectionInfo, items: [ItemCollectionItem])
|
||||||
|
case remote(info: ItemCollectionInfo, items: [ItemCollectionItem], installed: Bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func requestStickerSet(account:Account, reference: StickerPackReference) -> Signal<RequestStickerSetResult, RequestStickerSetError> {
|
||||||
|
|
||||||
|
let collectionId:ItemCollectionId?
|
||||||
let input:Api.InputStickerSet
|
let input:Api.InputStickerSet
|
||||||
|
|
||||||
switch reference {
|
switch reference {
|
||||||
case let .name(name):
|
case let .name(name):
|
||||||
|
collectionId = nil
|
||||||
input = .inputStickerSetShortName(shortName: name)
|
input = .inputStickerSetShortName(shortName: name)
|
||||||
case let .id(id, accessHash):
|
case let .id(id, accessHash):
|
||||||
|
collectionId = ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id)
|
||||||
input = .inputStickerSetID(id: id, accessHash: accessHash)
|
input = .inputStickerSetID(id: id, accessHash: accessHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.network.request(Api.functions.messages.getStickerSet(stickerset: input))
|
let localSignal:(ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, Void> = { collectionId in
|
||||||
|> mapError { _ -> CloudStickersLoadingError in
|
return account.postbox.modify { modifier -> (ItemCollectionInfo, [ItemCollectionItem])? in
|
||||||
|
return modifier.getItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: collectionId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let remoteSignal = account.network.request(Api.functions.messages.getStickerSet(stickerset: input))
|
||||||
|
|> mapError { _ -> RequestStickerSetError in
|
||||||
return .invalid
|
return .invalid
|
||||||
}
|
}
|
||||||
|> map { result -> (StickerPackCollectionInfo, [ItemCollectionItem], Bool) in
|
|> map { result -> RequestStickerSetResult in
|
||||||
var items: [ItemCollectionItem] = []
|
var items: [ItemCollectionItem] = []
|
||||||
let info:StickerPackCollectionInfo
|
let info:ItemCollectionInfo
|
||||||
let installed:Bool
|
let installed:Bool
|
||||||
switch result {
|
switch result {
|
||||||
case let .stickerSet(set, packs, documents):
|
case let .stickerSet(set, packs, documents):
|
||||||
|
|
||||||
|
info = set.info
|
||||||
|
|
||||||
switch set {
|
switch set {
|
||||||
case let .stickerSet(data):
|
case let .stickerSet(data):
|
||||||
installed = (data.flags & (1 << 0) != 0)
|
installed = (data.flags & (1 << 0) != 0)
|
||||||
}
|
}
|
||||||
info = set.info
|
|
||||||
|
|
||||||
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
|
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
|
||||||
for pack in packs {
|
for pack in packs {
|
||||||
@ -87,9 +104,23 @@ public func requestCloudStickerPack(account:Account, reference: StickerPackRefer
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return (info, items, installed)
|
return .remote(info: info, items: items, installed: installed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if let collectionId = collectionId {
|
||||||
|
return localSignal(collectionId) |> mapError {_ in return .generic} |> mapToSignal { result -> Signal<RequestStickerSetResult, RequestStickerSetError> in
|
||||||
|
if let result = result {
|
||||||
|
return .single(.local(info: result.0, items: result.1))
|
||||||
|
} else {
|
||||||
|
return remoteSignal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return remoteSignal
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum InstallStickerSetError {
|
public enum InstallStickerSetError {
|
||||||
@ -171,11 +202,11 @@ public func installStickerSetInteractively(account:Account, info: StickerPackCol
|
|||||||
for index in removableIndexes {
|
for index in removableIndexes {
|
||||||
collections.remove(at: index)
|
collections.remove(at: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
collections.insert((info.id, info, items), at: 0)
|
collections.insert((info.id, info, items), at: 0)
|
||||||
|
|
||||||
modifier.replaceItemCollections(namespace: info.id.namespace, itemCollections: collections)
|
modifier.replaceItemCollections(namespace: info.id.namespace, itemCollections: collections)
|
||||||
} |> map { _ in return addResult} |> mapError {_ in return .generic}
|
} |> map { _ in return addResult} |> mapError {_ in return .generic}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user