no message

This commit is contained in:
Peter 2017-02-02 11:47:45 +03:00
parent eaa061add0
commit 15c9274a8e
8 changed files with 188 additions and 12 deletions

View File

@ -46,6 +46,8 @@
D01AC9211DD5E7E500E8160F /* RequestEditMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01AC9201DD5E7E500E8160F /* RequestEditMessage.swift */; }; D01AC9211DD5E7E500E8160F /* RequestEditMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01AC9201DD5E7E500E8160F /* RequestEditMessage.swift */; };
D01AC9231DD5E9A200E8160F /* ApplyUpdateMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01AC9221DD5E9A200E8160F /* ApplyUpdateMessage.swift */; }; D01AC9231DD5E9A200E8160F /* ApplyUpdateMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01AC9221DD5E9A200E8160F /* ApplyUpdateMessage.swift */; };
D01B27A21E394D8B0022A4C0 /* PrivacySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01B27A11E394D8B0022A4C0 /* PrivacySettings.swift */; }; D01B27A21E394D8B0022A4C0 /* PrivacySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01B27A11E394D8B0022A4C0 /* PrivacySettings.swift */; };
D01D6BF91E42A713006151C6 /* SearchStickers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D6BF81E42A713006151C6 /* SearchStickers.swift */; };
D01D6BFA1E42A718006151C6 /* SearchStickers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D6BF81E42A713006151C6 /* SearchStickers.swift */; };
D021E0DF1DB539FC00C6B04F /* StickerPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D021E0DE1DB539FC00C6B04F /* StickerPack.swift */; }; D021E0DF1DB539FC00C6B04F /* StickerPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D021E0DE1DB539FC00C6B04F /* StickerPack.swift */; };
D021E0E21DB5401A00C6B04F /* StickerManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = D021E0E11DB5401A00C6B04F /* StickerManagement.swift */; }; D021E0E21DB5401A00C6B04F /* StickerManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = D021E0E11DB5401A00C6B04F /* StickerManagement.swift */; };
D02ABC7B1E30058F00CAE539 /* DeleteMessagesInteractively.swift in Sources */ = {isa = PBXBuildFile; fileRef = D02ABC7A1E30058F00CAE539 /* DeleteMessagesInteractively.swift */; }; D02ABC7B1E30058F00CAE539 /* DeleteMessagesInteractively.swift in Sources */ = {isa = PBXBuildFile; fileRef = D02ABC7A1E30058F00CAE539 /* DeleteMessagesInteractively.swift */; };
@ -349,6 +351,7 @@
D01AC9201DD5E7E500E8160F /* RequestEditMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestEditMessage.swift; sourceTree = "<group>"; }; D01AC9201DD5E7E500E8160F /* RequestEditMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestEditMessage.swift; sourceTree = "<group>"; };
D01AC9221DD5E9A200E8160F /* ApplyUpdateMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplyUpdateMessage.swift; sourceTree = "<group>"; }; D01AC9221DD5E9A200E8160F /* ApplyUpdateMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplyUpdateMessage.swift; sourceTree = "<group>"; };
D01B27A11E394D8B0022A4C0 /* PrivacySettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacySettings.swift; sourceTree = "<group>"; }; D01B27A11E394D8B0022A4C0 /* PrivacySettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacySettings.swift; sourceTree = "<group>"; };
D01D6BF81E42A713006151C6 /* SearchStickers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchStickers.swift; sourceTree = "<group>"; };
D021E0DE1DB539FC00C6B04F /* StickerPack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerPack.swift; sourceTree = "<group>"; }; D021E0DE1DB539FC00C6B04F /* StickerPack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerPack.swift; sourceTree = "<group>"; };
D021E0E11DB5401A00C6B04F /* StickerManagement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerManagement.swift; sourceTree = "<group>"; }; D021E0E11DB5401A00C6B04F /* StickerManagement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerManagement.swift; sourceTree = "<group>"; };
D02ABC7A1E30058F00CAE539 /* DeleteMessagesInteractively.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteMessagesInteractively.swift; sourceTree = "<group>"; }; D02ABC7A1E30058F00CAE539 /* DeleteMessagesInteractively.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteMessagesInteractively.swift; sourceTree = "<group>"; };
@ -580,6 +583,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D021E0E11DB5401A00C6B04F /* StickerManagement.swift */, D021E0E11DB5401A00C6B04F /* StickerManagement.swift */,
D01D6BF81E42A713006151C6 /* SearchStickers.swift */,
); );
name = "Sticker Management"; name = "Sticker Management";
sourceTree = "<group>"; sourceTree = "<group>";
@ -1216,6 +1220,7 @@
D03B0CD91D62245B00955575 /* PeerUtils.swift in Sources */, D03B0CD91D62245B00955575 /* PeerUtils.swift in Sources */,
D03B0CE41D62249F00955575 /* TextEntitiesMessageAttribute.swift in Sources */, D03B0CE41D62249F00955575 /* TextEntitiesMessageAttribute.swift in Sources */,
D03B0CD31D62244300955575 /* Namespaces.swift in Sources */, D03B0CD31D62244300955575 /* Namespaces.swift in Sources */,
D01D6BF91E42A713006151C6 /* SearchStickers.swift in Sources */,
D0FA8BB91E2240B4001E855B /* SecretChatIncomingDecryptedOperation.swift in Sources */, D0FA8BB91E2240B4001E855B /* SecretChatIncomingDecryptedOperation.swift in Sources */,
D0DF0C8A1D819C7E008AEB01 /* JoinChannel.swift in Sources */, D0DF0C8A1D819C7E008AEB01 /* JoinChannel.swift in Sources */,
D0F7AB2F1DCF507E009AD9A1 /* ReplyMarkupMessageAttribute.swift in Sources */, D0F7AB2F1DCF507E009AD9A1 /* ReplyMarkupMessageAttribute.swift in Sources */,
@ -1298,6 +1303,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
D01D6BFA1E42A718006151C6 /* SearchStickers.swift in Sources */,
C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */, C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */,
D0F7B1EA1E045C87007EB8A5 /* ChangePeerNotificationSettings.swift in Sources */, D0F7B1EA1E045C87007EB8A5 /* ChangePeerNotificationSettings.swift in Sources */,
D0B418A71D7E0592004562A4 /* Fetch.swift in Sources */, D0B418A71D7E0592004562A4 /* Fetch.swift in Sources */,

View File

@ -185,7 +185,7 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network,
return .complete() return .complete()
} }
} else if peer.id.namespace == Namespaces.Peer.CloudGroup { } else if peer.id.namespace == Namespaces.Peer.CloudGroup {
return network.request(Api.functions.messages.deleteChatUser(chatId: peer.id.id, userId: Api.InputUser.inputUserSelf)) let deleteUser: Signal<Void, NoError> = network.request(Api.functions.messages.deleteChatUser(chatId: peer.id.id, userId: Api.InputUser.inputUserSelf))
|> map { result -> Api.Updates? in |> map { result -> Api.Updates? in
return result return result
} }
@ -198,6 +198,28 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network,
} }
return .complete() return .complete()
} }
let deleteMessages: Signal<Void, NoError>
if let inputPeer = apiInputPeer(peer), let topMessageId = modifier.getTopPeerMessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud) {
deleteMessages = network.request(Api.functions.messages.deleteHistory(flags: 0, peer: inputPeer, maxId: topMessageId.id))
|> map { result -> Api.messages.AffectedHistory? in
return result
}
|> `catch` { _ in
return .single(nil)
}
|> mapToSignal { result in
if let result = result {
switch result {
case let .affectedHistory(pts, ptsCount, _):
stateManager.addUpdateGroups([.updatePts(pts: pts, ptsCount: ptsCount)])
}
}
return .complete()
}
} else {
deleteMessages = .complete()
}
return deleteMessages |> then(deleteUser)
} else if peer.id.namespace == Namespaces.Peer.CloudUser { } else if peer.id.namespace == Namespaces.Peer.CloudUser {
if let inputPeer = apiInputPeer(peer), let topMessageId = modifier.getTopPeerMessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud) { if let inputPeer = apiInputPeer(peer), let topMessageId = modifier.getTopPeerMessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud) {
return network.request(Api.functions.messages.deleteHistory(flags: 0, peer: inputPeer, maxId: topMessageId.id)) return network.request(Api.functions.messages.deleteHistory(flags: 0, peer: inputPeer, maxId: topMessageId.id))

View File

@ -114,10 +114,108 @@ func managedSynchronizePinnedChatsOperations(postbox: Postbox, network: Network,
} }
private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, network: Network, stateManager: AccountStateManager, operation: SynchronizePinnedChatsOperation) -> Signal<Void, NoError> { private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, network: Network, stateManager: AccountStateManager, operation: SynchronizePinnedChatsOperation) -> Signal<Void, NoError> {
let peerIds = modifier.getPinnedPeerIds().filter { let rawPeerIds = modifier.getPinnedPeerIds()
let peerIds = rawPeerIds.filter {
$0.namespace != Namespaces.Peer.SecretChat $0.namespace != Namespaces.Peer.SecretChat
} }
/*let peerIdsSet = Set(peerIds)
let previousCachedIds = Set(operation.previousPeerIds.filter { $0.namespace != Namespaces.Peer.SecretChat })
let removedIds = previousCachedIds.subtracting(peerIdsSet)
//messages.peerDialogs#3371c354 dialogs:Vector<Dialog> messages:Vector<Message> chats:Vector<Chat> users:Vector<User> state:updates.State = messages.PeerDialogs;
let s = network.request(Api.functions.messages.getPinnedDialogs())
|> retryRequest
|> mapToSignal { dialogs -> Signal<Void, NoError> in
let dialogsChats: [Api.Chat]
let dialogsUsers: [Api.User]
var storeMessages: [StoreMessage] = []
var readStates: [PeerId: [MessageId.Namespace: PeerReadState]] = [:]
var chatStates: [PeerId: PeerChatState] = [:]
var notificationSettings: [PeerId: PeerNotificationSettings] = [:]
switch dialogs {
case let .peerDialogs(dialogs, messages, chats, users, _):
dialogsChats = chats
dialogsUsers = users
for dialog in dialogs {
let apiPeer: Api.Peer
let apiReadInboxMaxId: Int32
let apiReadOutboxMaxId: Int32
let apiTopMessage: Int32
let apiUnreadCount: Int32
var apiChannelPts: Int32?
let apiNotificationSettings: Api.PeerNotifySettings
switch dialog {
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, peerNotificationSettings, pts, _):
apiPeer = peer
apiTopMessage = topMessage
apiReadInboxMaxId = readInboxMaxId
apiReadOutboxMaxId = readOutboxMaxId
apiUnreadCount = unreadCount
apiNotificationSettings = peerNotificationSettings
apiChannelPts = pts
}
let peerId: PeerId
switch apiPeer {
case let .peerUser(userId):
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
case let .peerChat(chatId):
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId)
case let .peerChannel(channelId):
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)
}
if readStates[peerId] == nil {
readStates[peerId] = [:]
}
readStates[peerId]![Namespaces.Message.Cloud] = .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount)
if let apiChannelPts = apiChannelPts {
chatStates[peerId] = ChannelState(pts: apiChannelPts)
}
notificationSettings[peerId] = TelegramPeerNotificationSettings(apiSettings: apiNotificationSettings)
}
for message in messages {
if let storeMessage = StoreMessage(apiMessage: message) {
storeMessages.append(storeMessage)
}
}
}
var chatPeers: [Peer] = []
var peers: [Peer] = []
var peerPresences: [PeerId: PeerPresence] = [:]
for chat in dialogsChats {
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
peers.append(groupOrChannel)
chatPeers.append(groupOrChannel)
}
}
for user in dialogsUsers {
let telegramUser = TelegramUser(user: user)
peers.append(telegramUser)
if let presence = TelegramUserPresence(apiUser: user) {
peerPresences[telegramUser.id] = presence
}
}
let currentPeersIds = chatPeers.map({ $0.id })
let cleanedUpPeerIds = currentPeersIds.filter { !removedIds.contains($0) }
var finalPeerIds: [PeerId] = []
return .never()
}*/
var inputPeers: [Api.InputPeer] = [] var inputPeers: [Api.InputPeer] = []
for peerId in peerIds { for peerId in peerIds {
if let peer = modifier.getPeer(peerId), let inputPeer = apiInputPeer(peer) { if let peer = modifier.getPeer(peerId), let inputPeer = apiInputPeer(peer) {

View File

@ -15,8 +15,10 @@ void setBridgingTraceFunction(void (*f)(NSString *, NSString *)) {
#if TARGET_IPHONE_SIMULATOR #if TARGET_IPHONE_SIMULATOR
static bool loggingEnabled = true; static bool loggingEnabled = true;
#else #elif defined(DEBUG)
static bool loggingEnabled = true; static bool loggingEnabled = true;
#else
static bool loggingEnabled = false;
#endif #endif
static void TGTelegramLoggingFunction(NSString *format, va_list args) { static void TGTelegramLoggingFunction(NSString *format, va_list args) {

View File

@ -0,0 +1,20 @@
import Foundation
#if os(macOS)
import PostboxMac
import SwiftSignalKitMac
#else
import Postbox
import SwiftSignalKit
#endif
public func searchStickers(postbox: Postbox, query: String) -> Signal<[StickerPackItem], NoError> {
return postbox.modify { modifier -> [StickerPackItem] in
var result: [StickerPackItem] = []
for item in modifier.searchItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, key: ValueBoxKey(query).toMemoryBuffer()) {
if let item = item as? StickerPackItem {
result.append(item)
}
}
return result
}
}

View File

@ -12,10 +12,10 @@ private func hashForInfos(_ infos: [StickerPackCollectionInfo]) -> Int32 {
var acc: UInt32 = 0 var acc: UInt32 = 0
for info in infos { for info in infos {
acc = (acc &* 20261) &+ unsafeBitCast(info.hash, to: UInt32.self) acc = (acc &* 20261) &+ UInt32(bitPattern: info.hash)
} }
return unsafeBitCast(acc % UInt32(0x7FFFFFFF), to: Int32.self) return Int32(bitPattern: acc % UInt32(0x7FFFFFFF))
} }
func manageStickerPacks(network: Network, postbox: Postbox) -> Signal<Void, NoError> { func manageStickerPacks(network: Network, postbox: Postbox) -> Signal<Void, NoError> {
@ -28,7 +28,7 @@ func manageStickerPacks(network: Network, postbox: Postbox) -> Signal<Void, NoEr
let remoteStickerPacks = currentHash let remoteStickerPacks = currentHash
|> mapToSignal { hash -> Signal<Void, NoError> in |> mapToSignal { hash -> Signal<Void, NoError> in
if hash != 0 { if hash != 0 {
return .never() //return .never()
} }
return network.request(Api.functions.messages.getAllStickers(hash: hash)) return network.request(Api.functions.messages.getAllStickers(hash: hash))
@ -55,10 +55,34 @@ func manageStickerPacks(network: Network, postbox: Postbox) -> Signal<Void, NoEr
|> map { result -> (ItemCollectionId, [ItemCollectionItem]) in |> map { result -> (ItemCollectionId, [ItemCollectionItem]) in
var items: [ItemCollectionItem] = [] var items: [ItemCollectionItem] = []
switch result { switch result {
case let .stickerSet(_, _, documents): case let .stickerSet(_, packs, documents):
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
//stickerPack#12b299d4 emoticon:string documents:Vector<long> = StickerPack;
for pack in packs {
switch pack {
case let .stickerPack(text, fileIds):
let key = ValueBoxKey(text).toMemoryBuffer()
for fileId in fileIds {
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
if indexKeysByFile[mediaId] == nil {
indexKeysByFile[mediaId] = [key]
} else {
indexKeysByFile[mediaId]!.append(key)
}
}
break
}
}
for apiDocument in documents { for apiDocument in documents {
if let file = telegramMediaFileFromApiDocument(apiDocument), let id = file.id { if let file = telegramMediaFileFromApiDocument(apiDocument), let id = file.id {
items.append(StickerPackItem(index: ItemCollectionItemIndex(index: Int32(items.count), id: id.id), file: file)) let fileIndexKeys: [MemoryBuffer]
if let indexKeys = indexKeysByFile[id] {
fileIndexKeys = indexKeys
} else {
fileIndexKeys = []
}
items.append(StickerPackItem(index: ItemCollectionItemIndex(index: Int32(items.count), id: id.id), file: file, indexKeys: fileIndexKeys))
} }
} }
break break

View File

@ -46,24 +46,28 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
public final class StickerPackItem: ItemCollectionItem, Equatable { public final class StickerPackItem: ItemCollectionItem, Equatable {
public let index: ItemCollectionItemIndex public let index: ItemCollectionItemIndex
public let file: TelegramMediaFile public let file: TelegramMediaFile
public var indexKeys: [MemoryBuffer]
init(index: ItemCollectionItemIndex, file: TelegramMediaFile) { init(index: ItemCollectionItemIndex, file: TelegramMediaFile, indexKeys: [MemoryBuffer]) {
self.index = index self.index = index
self.file = file self.file = file
self.indexKeys = indexKeys
} }
public init(decoder: Decoder) { public init(decoder: Decoder) {
self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n"), id: decoder.decodeInt64ForKey("i.i")) self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n"), id: decoder.decodeInt64ForKey("i.i"))
self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile
self.indexKeys = decoder.decodeBytesArrayForKey("s")
} }
public func encode(_ encoder: Encoder) { public func encode(_ encoder: Encoder) {
encoder.encodeInt32(self.index.index, forKey: "i.n") encoder.encodeInt32(self.index.index, forKey: "i.n")
encoder.encodeInt64(self.index.id, forKey: "i.i") encoder.encodeInt64(self.index.id, forKey: "i.i")
encoder.encodeObject(self.file, forKey: "f") encoder.encodeObject(self.file, forKey: "f")
encoder.encodeBytesArray(self.indexKeys, forKey: "s")
} }
public static func ==(lhs: StickerPackItem, rhs: StickerPackItem) -> Bool { public static func ==(lhs: StickerPackItem, rhs: StickerPackItem) -> Bool {
return lhs.index == rhs.index && lhs.file == rhs.file return lhs.index == rhs.index && lhs.file == rhs.file && lhs.indexKeys == rhs.indexKeys
} }
} }

View File

@ -6,7 +6,7 @@ import Foundation
#endif #endif
final class SynchronizePinnedChatsOperation: Coding { final class SynchronizePinnedChatsOperation: Coding {
private let previousPeerIds: [PeerId] let previousPeerIds: [PeerId]
init(previousPeerIds: [PeerId]) { init(previousPeerIds: [PeerId]) {
self.previousPeerIds = previousPeerIds self.previousPeerIds = previousPeerIds