mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 12:17:53 +00:00
Update API
This commit is contained in:
parent
a751220fea
commit
e752d51c91
@ -59,7 +59,7 @@ enum AccountStateMutationOperation {
|
|||||||
case DeleteMessagesWithGlobalIds([Int32])
|
case DeleteMessagesWithGlobalIds([Int32])
|
||||||
case DeleteMessages([MessageId])
|
case DeleteMessages([MessageId])
|
||||||
case EditMessage(MessageId, StoreMessage)
|
case EditMessage(MessageId, StoreMessage)
|
||||||
case UpdateMessagePoll(MessageId, Api.Poll?, Api.PollResults)
|
case UpdateMessagePoll(MediaId, Api.Poll?, Api.PollResults)
|
||||||
case UpdateMedia(MediaId, Media?)
|
case UpdateMedia(MediaId, Media?)
|
||||||
case ReadInbox(MessageId)
|
case ReadInbox(MessageId)
|
||||||
case ReadOutbox(MessageId, Int32?)
|
case ReadOutbox(MessageId, Int32?)
|
||||||
@ -195,7 +195,7 @@ struct AccountMutableState {
|
|||||||
self.addOperation(.EditMessage(id, message))
|
self.addOperation(.EditMessage(id, message))
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func updateMessagePoll(_ id: MessageId, poll: Api.Poll?, results: Api.PollResults) {
|
mutating func updateMessagePoll(_ id: MediaId, poll: Api.Poll?, results: Api.PollResults) {
|
||||||
self.addOperation(.UpdateMessagePoll(id, poll, results))
|
self.addOperation(.UpdateMessagePoll(id, poll, results))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1241,8 +1241,8 @@ private func finalStateWithUpdatesAndServerTime(account: Account, state: Account
|
|||||||
langCode = langPackDifference.langCode
|
langCode = langPackDifference.langCode
|
||||||
}
|
}
|
||||||
updatedState.updateLangPack(langCode: langCode, difference: difference)
|
updatedState.updateLangPack(langCode: langCode, difference: difference)
|
||||||
case let .updateMessagePoll(flags, peer, msgId, poll, results):
|
case let .updateMessagePoll(flags, pollId, poll, results):
|
||||||
updatedState.updateMessagePoll(MessageId(peerId: peer.peerId, namespace: Namespaces.Message.Cloud, id: msgId), poll: poll, results: results)
|
updatedState.updateMessagePoll(MediaId(namespace: Namespaces.Media.CloudPoll, id: pollId), poll: poll, results: results)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -2099,35 +2099,24 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, transaction: Tr
|
|||||||
}
|
}
|
||||||
return .update(message.withUpdatedLocalTags(updatedLocalTags).withUpdatedFlags(updatedFlags))
|
return .update(message.withUpdatedLocalTags(updatedLocalTags).withUpdatedFlags(updatedFlags))
|
||||||
})
|
})
|
||||||
case let .UpdateMessagePoll(id, apiPoll, results):
|
case let .UpdateMessagePoll(pollId, apiPoll, results):
|
||||||
transaction.updateMessage(id, update: { currentMessage in
|
if let poll = transaction.getMedia(pollId) as? TelegramMediaPoll {
|
||||||
var storeForwardInfo: StoreMessageForwardInfo?
|
var updatedPoll = poll
|
||||||
if let forwardInfo = currentMessage.forwardInfo {
|
if let apiPoll = apiPoll {
|
||||||
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature)
|
switch apiPoll {
|
||||||
}
|
case let .poll(id, flags, question, answers):
|
||||||
var media = currentMessage.media
|
updatedPoll = TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0)
|
||||||
loop: for j in 0 ..< media.count {
|
|
||||||
if let poll = media[j] as? TelegramMediaPoll {
|
|
||||||
var updatedPoll = poll
|
|
||||||
if let apiPoll = apiPoll {
|
|
||||||
switch apiPoll {
|
|
||||||
case let .poll(id, flags, question, answers):
|
|
||||||
updatedPoll = TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let resultsMin: Bool
|
|
||||||
switch results {
|
|
||||||
case let .pollResults(pollResults):
|
|
||||||
resultsMin = (pollResults.flags & (1 << 0)) != 0
|
|
||||||
}
|
|
||||||
updatedPoll = updatedPoll.withUpdatedResults(TelegramMediaPollResults(apiResults: results), min: resultsMin)
|
|
||||||
media[j] = updatedPoll
|
|
||||||
break loop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: media))
|
|
||||||
})
|
let resultsMin: Bool
|
||||||
|
switch results {
|
||||||
|
case let .pollResults(pollResults):
|
||||||
|
resultsMin = (pollResults.flags & (1 << 0)) != 0
|
||||||
|
}
|
||||||
|
updatedPoll = updatedPoll.withUpdatedResults(TelegramMediaPollResults(apiResults: results), min: resultsMin)
|
||||||
|
updateMessageMedia(transaction: transaction, id: pollId, media: updatedPoll)
|
||||||
|
}
|
||||||
case let .UpdateMedia(id, media):
|
case let .UpdateMedia(id, media):
|
||||||
if let media = media as? TelegramMediaWebpage {
|
if let media = media as? TelegramMediaWebpage {
|
||||||
updatedWebpages[id] = media
|
updatedWebpages[id] = media
|
||||||
|
|||||||
@ -217,7 +217,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[1180041828] = { return Api.Update.parse_updateLangPackTooLong($0) }
|
dict[1180041828] = { return Api.Update.parse_updateLangPackTooLong($0) }
|
||||||
dict[1279515160] = { return Api.Update.parse_updateUserPinnedMessage($0) }
|
dict[1279515160] = { return Api.Update.parse_updateUserPinnedMessage($0) }
|
||||||
dict[579418918] = { return Api.Update.parse_updateChatPinnedMessage($0) }
|
dict[579418918] = { return Api.Update.parse_updateChatPinnedMessage($0) }
|
||||||
dict[-1727571636] = { return Api.Update.parse_updateMessagePoll($0) }
|
dict[-1398708869] = { return Api.Update.parse_updateMessagePoll($0) }
|
||||||
dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) }
|
dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) }
|
||||||
dict[367766557] = { return Api.ChannelParticipant.parse_channelParticipant($0) }
|
dict[367766557] = { return Api.ChannelParticipant.parse_channelParticipant($0) }
|
||||||
dict[-1557620115] = { return Api.ChannelParticipant.parse_channelParticipantSelf($0) }
|
dict[-1557620115] = { return Api.ChannelParticipant.parse_channelParticipantSelf($0) }
|
||||||
|
|||||||
@ -3554,7 +3554,7 @@ extension Api {
|
|||||||
case updateLangPackTooLong(langCode: String)
|
case updateLangPackTooLong(langCode: String)
|
||||||
case updateUserPinnedMessage(userId: Int32, id: Int32)
|
case updateUserPinnedMessage(userId: Int32, id: Int32)
|
||||||
case updateChatPinnedMessage(chatId: Int32, id: Int32)
|
case updateChatPinnedMessage(chatId: Int32, id: Int32)
|
||||||
case updateMessagePoll(flags: Int32, peer: Api.Peer, msgId: Int32, poll: Api.Poll?, results: Api.PollResults)
|
case updateMessagePoll(flags: Int32, pollId: Int64, poll: Api.Poll?, results: Api.PollResults)
|
||||||
|
|
||||||
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
switch self {
|
||||||
@ -4116,13 +4116,12 @@ extension Api {
|
|||||||
serializeInt32(chatId, buffer: buffer, boxed: false)
|
serializeInt32(chatId, buffer: buffer, boxed: false)
|
||||||
serializeInt32(id, buffer: buffer, boxed: false)
|
serializeInt32(id, buffer: buffer, boxed: false)
|
||||||
break
|
break
|
||||||
case .updateMessagePoll(let flags, let peer, let msgId, let poll, let results):
|
case .updateMessagePoll(let flags, let pollId, let poll, let results):
|
||||||
if boxed {
|
if boxed {
|
||||||
buffer.appendInt32(-1727571636)
|
buffer.appendInt32(-1398708869)
|
||||||
}
|
}
|
||||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||||
peer.serialize(buffer, true)
|
serializeInt64(pollId, buffer: buffer, boxed: false)
|
||||||
serializeInt32(msgId, buffer: buffer, boxed: false)
|
|
||||||
if Int(flags) & Int(1 << 0) != 0 {poll!.serialize(buffer, true)}
|
if Int(flags) & Int(1 << 0) != 0 {poll!.serialize(buffer, true)}
|
||||||
results.serialize(buffer, true)
|
results.serialize(buffer, true)
|
||||||
break
|
break
|
||||||
@ -4267,8 +4266,8 @@ extension Api {
|
|||||||
return ("updateUserPinnedMessage", [("userId", userId), ("id", id)])
|
return ("updateUserPinnedMessage", [("userId", userId), ("id", id)])
|
||||||
case .updateChatPinnedMessage(let chatId, let id):
|
case .updateChatPinnedMessage(let chatId, let id):
|
||||||
return ("updateChatPinnedMessage", [("chatId", chatId), ("id", id)])
|
return ("updateChatPinnedMessage", [("chatId", chatId), ("id", id)])
|
||||||
case .updateMessagePoll(let flags, let peer, let msgId, let poll, let results):
|
case .updateMessagePoll(let flags, let pollId, let poll, let results):
|
||||||
return ("updateMessagePoll", [("flags", flags), ("peer", peer), ("msgId", msgId), ("poll", poll), ("results", results)])
|
return ("updateMessagePoll", [("flags", flags), ("pollId", pollId), ("poll", poll), ("results", results)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5401,27 +5400,22 @@ extension Api {
|
|||||||
static func parse_updateMessagePoll(_ reader: BufferReader) -> Update? {
|
static func parse_updateMessagePoll(_ reader: BufferReader) -> Update? {
|
||||||
var _1: Int32?
|
var _1: Int32?
|
||||||
_1 = reader.readInt32()
|
_1 = reader.readInt32()
|
||||||
var _2: Api.Peer?
|
var _2: Int64?
|
||||||
if let signature = reader.readInt32() {
|
_2 = reader.readInt64()
|
||||||
_2 = Api.parse(reader, signature: signature) as? Api.Peer
|
var _3: Api.Poll?
|
||||||
}
|
|
||||||
var _3: Int32?
|
|
||||||
_3 = reader.readInt32()
|
|
||||||
var _4: Api.Poll?
|
|
||||||
if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() {
|
if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() {
|
||||||
_4 = Api.parse(reader, signature: signature) as? Api.Poll
|
_3 = Api.parse(reader, signature: signature) as? Api.Poll
|
||||||
} }
|
} }
|
||||||
var _5: Api.PollResults?
|
var _4: Api.PollResults?
|
||||||
if let signature = reader.readInt32() {
|
if let signature = reader.readInt32() {
|
||||||
_5 = Api.parse(reader, signature: signature) as? Api.PollResults
|
_4 = Api.parse(reader, signature: signature) as? Api.PollResults
|
||||||
}
|
}
|
||||||
let _c1 = _1 != nil
|
let _c1 = _1 != nil
|
||||||
let _c2 = _2 != nil
|
let _c2 = _2 != nil
|
||||||
let _c3 = _3 != nil
|
let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil
|
||||||
let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
|
let _c4 = _4 != nil
|
||||||
let _c5 = _5 != nil
|
if _c1 && _c2 && _c3 && _c4 {
|
||||||
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
return Api.Update.updateMessagePoll(flags: _1!, pollId: _2!, poll: _3, results: _4!)
|
||||||
return Api.Update.updateMessagePoll(flags: _1!, peer: _2!, msgId: _3!, poll: _4, results: _5!)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user