Group stories

This commit is contained in:
Ilya Laktyushin 2024-02-11 20:31:36 +04:00
parent c3af008cd2
commit 2533b65879
11 changed files with 166 additions and 71 deletions

View file

@ -833,7 +833,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[2008112412] = { return Api.StickerSetCovered.parse_stickerSetNoCovered($0) }
dict[1898850301] = { return Api.StoriesStealthMode.parse_storiesStealthMode($0) }
dict[-1205411504] = { return Api.StoryFwdHeader.parse_storyFwdHeader($0) }
dict[-1352440415] = { return Api.StoryItem.parse_storyItem($0) }
dict[2041735716] = { return Api.StoryItem.parse_storyItem($0) }
dict[1374088783] = { return Api.StoryItem.parse_storyItemDeleted($0) }
dict[-5388013] = { return Api.StoryItem.parse_storyItemSkipped($0) }
dict[1620104917] = { return Api.StoryReaction.parse_storyReaction($0) }

View file

@ -1034,19 +1034,20 @@ public extension Api {
}
public extension Api {
indirect enum StoryItem: TypeConstructorDescription {
case storyItem(flags: Int32, id: Int32, date: Int32, fwdFrom: Api.StoryFwdHeader?, expireDate: Int32, caption: String?, entities: [Api.MessageEntity]?, media: Api.MessageMedia, mediaAreas: [Api.MediaArea]?, privacy: [Api.PrivacyRule]?, views: Api.StoryViews?, sentReaction: Api.Reaction?)
case storyItem(flags: Int32, id: Int32, date: Int32, fromId: Api.Peer?, fwdFrom: Api.StoryFwdHeader?, expireDate: Int32, caption: String?, entities: [Api.MessageEntity]?, media: Api.MessageMedia, mediaAreas: [Api.MediaArea]?, privacy: [Api.PrivacyRule]?, views: Api.StoryViews?, sentReaction: Api.Reaction?)
case storyItemDeleted(id: Int32)
case storyItemSkipped(flags: Int32, id: Int32, date: Int32, expireDate: Int32)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .storyItem(let flags, let id, let date, let fwdFrom, let expireDate, let caption, let entities, let media, let mediaAreas, let privacy, let views, let sentReaction):
case .storyItem(let flags, let id, let date, let fromId, let fwdFrom, let expireDate, let caption, let entities, let media, let mediaAreas, let privacy, let views, let sentReaction):
if boxed {
buffer.appendInt32(-1352440415)
buffer.appendInt32(2041735716)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt32(id, buffer: buffer, boxed: false)
serializeInt32(date, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 18) != 0 {fromId!.serialize(buffer, true)}
if Int(flags) & Int(1 << 17) != 0 {fwdFrom!.serialize(buffer, true)}
serializeInt32(expireDate, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {serializeString(caption!, buffer: buffer, boxed: false)}
@ -1089,8 +1090,8 @@ public extension Api {
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .storyItem(let flags, let id, let date, let fwdFrom, let expireDate, let caption, let entities, let media, let mediaAreas, let privacy, let views, let sentReaction):
return ("storyItem", [("flags", flags as Any), ("id", id as Any), ("date", date as Any), ("fwdFrom", fwdFrom as Any), ("expireDate", expireDate as Any), ("caption", caption as Any), ("entities", entities as Any), ("media", media as Any), ("mediaAreas", mediaAreas as Any), ("privacy", privacy as Any), ("views", views as Any), ("sentReaction", sentReaction as Any)])
case .storyItem(let flags, let id, let date, let fromId, let fwdFrom, let expireDate, let caption, let entities, let media, let mediaAreas, let privacy, let views, let sentReaction):
return ("storyItem", [("flags", flags as Any), ("id", id as Any), ("date", date as Any), ("fromId", fromId as Any), ("fwdFrom", fwdFrom as Any), ("expireDate", expireDate as Any), ("caption", caption as Any), ("entities", entities as Any), ("media", media as Any), ("mediaAreas", mediaAreas as Any), ("privacy", privacy as Any), ("views", views as Any), ("sentReaction", sentReaction as Any)])
case .storyItemDeleted(let id):
return ("storyItemDeleted", [("id", id as Any)])
case .storyItemSkipped(let flags, let id, let date, let expireDate):
@ -1105,52 +1106,57 @@ public extension Api {
_2 = reader.readInt32()
var _3: Int32?
_3 = reader.readInt32()
var _4: Api.StoryFwdHeader?
var _4: Api.Peer?
if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() {
_4 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _5: Api.StoryFwdHeader?
if Int(_1!) & Int(1 << 17) != 0 {if let signature = reader.readInt32() {
_4 = Api.parse(reader, signature: signature) as? Api.StoryFwdHeader
_5 = Api.parse(reader, signature: signature) as? Api.StoryFwdHeader
} }
var _5: Int32?
_5 = reader.readInt32()
var _6: String?
if Int(_1!) & Int(1 << 0) != 0 {_6 = parseString(reader) }
var _7: [Api.MessageEntity]?
var _6: Int32?
_6 = reader.readInt32()
var _7: String?
if Int(_1!) & Int(1 << 0) != 0 {_7 = parseString(reader) }
var _8: [Api.MessageEntity]?
if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() {
_7 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self)
_8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self)
} }
var _8: Api.MessageMedia?
var _9: Api.MessageMedia?
if let signature = reader.readInt32() {
_8 = Api.parse(reader, signature: signature) as? Api.MessageMedia
_9 = Api.parse(reader, signature: signature) as? Api.MessageMedia
}
var _9: [Api.MediaArea]?
var _10: [Api.MediaArea]?
if Int(_1!) & Int(1 << 14) != 0 {if let _ = reader.readInt32() {
_9 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MediaArea.self)
_10 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MediaArea.self)
} }
var _10: [Api.PrivacyRule]?
var _11: [Api.PrivacyRule]?
if Int(_1!) & Int(1 << 2) != 0 {if let _ = reader.readInt32() {
_10 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PrivacyRule.self)
_11 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PrivacyRule.self)
} }
var _11: Api.StoryViews?
var _12: Api.StoryViews?
if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() {
_11 = Api.parse(reader, signature: signature) as? Api.StoryViews
_12 = Api.parse(reader, signature: signature) as? Api.StoryViews
} }
var _12: Api.Reaction?
var _13: Api.Reaction?
if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() {
_12 = Api.parse(reader, signature: signature) as? Api.Reaction
_13 = Api.parse(reader, signature: signature) as? Api.Reaction
} }
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = (Int(_1!) & Int(1 << 17) == 0) || _4 != nil
let _c5 = _5 != nil
let _c6 = (Int(_1!) & Int(1 << 0) == 0) || _6 != nil
let _c7 = (Int(_1!) & Int(1 << 1) == 0) || _7 != nil
let _c8 = _8 != nil
let _c9 = (Int(_1!) & Int(1 << 14) == 0) || _9 != nil
let _c10 = (Int(_1!) & Int(1 << 2) == 0) || _10 != nil
let _c11 = (Int(_1!) & Int(1 << 3) == 0) || _11 != nil
let _c12 = (Int(_1!) & Int(1 << 15) == 0) || _12 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 {
return Api.StoryItem.storyItem(flags: _1!, id: _2!, date: _3!, fwdFrom: _4, expireDate: _5!, caption: _6, entities: _7, media: _8!, mediaAreas: _9, privacy: _10, views: _11, sentReaction: _12)
let _c4 = (Int(_1!) & Int(1 << 18) == 0) || _4 != nil
let _c5 = (Int(_1!) & Int(1 << 17) == 0) || _5 != nil
let _c6 = _6 != nil
let _c7 = (Int(_1!) & Int(1 << 0) == 0) || _7 != nil
let _c8 = (Int(_1!) & Int(1 << 1) == 0) || _8 != nil
let _c9 = _9 != nil
let _c10 = (Int(_1!) & Int(1 << 14) == 0) || _10 != nil
let _c11 = (Int(_1!) & Int(1 << 2) == 0) || _11 != nil
let _c12 = (Int(_1!) & Int(1 << 3) == 0) || _12 != nil
let _c13 = (Int(_1!) & Int(1 << 15) == 0) || _13 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 {
return Api.StoryItem.storyItem(flags: _1!, id: _2!, date: _3!, fromId: _4, fwdFrom: _5, expireDate: _6!, caption: _7, entities: _8, media: _9!, mediaAreas: _10, privacy: _11, views: _12, sentReaction: _13)
}
else {
return nil

View file

@ -4712,7 +4712,8 @@ func replayFinalState(
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: updatedReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
if let entry = CodableEntry(updatedItem) {
updatedPeerEntries[index] = StoryItemsTableEntry(value: entry, id: item.id, expirationTimestamp: item.expirationTimestamp, isCloseFriends: item.isCloseFriends)
@ -4745,7 +4746,8 @@ func replayFinalState(
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: MessageReaction.Reaction(apiReaction: reaction),
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
if let entry = CodableEntry(updatedItem) {
transaction.setStory(id: StoryId(peerId: peerId, id: id), value: entry)

View file

@ -349,7 +349,8 @@ private final class StoryStatsPublicForwardsContextImpl {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
resultForwards.append(.story(EnginePeer(peer), mappedItem))
}

View file

@ -556,7 +556,8 @@ public final class EngineStoryViewListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
),
storyStats: transaction.getPeerStoryStats(peerId: peer.id)
)))
@ -595,7 +596,8 @@ public final class EngineStoryViewListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
if let entry = CodableEntry(updatedItem) {
transaction.setStory(id: StoryId(peerId: account.peerId, id: storyId), value: entry)
@ -634,7 +636,8 @@ public final class EngineStoryViewListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
if let entry = CodableEntry(updatedItem) {
currentItems[i] = StoryItemsTableEntry(value: entry, id: updatedItem.id, expirationTimestamp: updatedItem.expirationTimestamp, isCloseFriends: updatedItem.isCloseFriends)
@ -748,7 +751,8 @@ public final class EngineStoryViewListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
),
storyStats: transaction.getPeerStoryStats(peerId: peer.id)
)))

View file

@ -261,6 +261,7 @@ public enum Stories {
case isMy
case myReaction
case forwardInfo
case authorId
}
public let id: Int32
@ -284,6 +285,7 @@ public enum Stories {
public let isMy: Bool
public let myReaction: MessageReaction.Reaction?
public let forwardInfo: ForwardInfo?
public let authorId: PeerId?
public init(
id: Int32,
@ -306,7 +308,8 @@ public enum Stories {
isEdited: Bool,
isMy: Bool,
myReaction: MessageReaction.Reaction?,
forwardInfo: ForwardInfo?
forwardInfo: ForwardInfo?,
authorId: PeerId?
) {
self.id = id
self.timestamp = timestamp
@ -329,6 +332,7 @@ public enum Stories {
self.isMy = isMy
self.myReaction = myReaction
self.forwardInfo = forwardInfo
self.authorId = authorId
}
public init(from decoder: Decoder) throws {
@ -367,6 +371,7 @@ public enum Stories {
self.isMy = try container.decodeIfPresent(Bool.self, forKey: .isMy) ?? false
self.myReaction = try container.decodeIfPresent(MessageReaction.Reaction.self, forKey: .myReaction)
self.forwardInfo = try container.decodeIfPresent(ForwardInfo.self, forKey: .forwardInfo)
self.authorId = try container.decodeIfPresent(Int64.self, forKey: .authorId).flatMap { PeerId($0) }
}
public func encode(to encoder: Encoder) throws {
@ -407,6 +412,7 @@ public enum Stories {
try container.encode(self.isMy, forKey: .isMy)
try container.encodeIfPresent(self.myReaction, forKey: .myReaction)
try container.encodeIfPresent(self.forwardInfo, forKey: .forwardInfo)
try container.encodeIfPresent(self.authorId?.toInt64(), forKey: .authorId)
}
public static func ==(lhs: Item, rhs: Item) -> Bool {
@ -485,6 +491,9 @@ public enum Stories {
if lhs.forwardInfo != rhs.forwardInfo {
return false
}
if lhs.authorId != rhs.authorId {
return false
}
return true
}
}
@ -1173,7 +1182,7 @@ func _internal_uploadStoryImpl(
for update in updates.allUpdates {
if case let .updateStory(_, story) = update {
switch story {
case let .storyItem(_, idValue, _, _, _, _, _, media, _, _, _, _):
case let .storyItem(_, idValue, _, fromId, _, _, _, _, media, _, _, _, _):
if let parsedStory = Stories.StoredItem(apiStoryItem: story, peerId: toPeerId, transaction: transaction) {
var items = transaction.getStoryItems(peerId: toPeerId)
var updatedItems: [Stories.Item] = []
@ -1199,7 +1208,8 @@ func _internal_uploadStoryImpl(
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: fromId?.peerId
)
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
items.append(StoryItemsTableEntry(value: entry, id: item.id, expirationTimestamp: updatedItem.expirationTimestamp, isCloseFriends: updatedItem.isCloseFriends))
@ -1336,7 +1346,7 @@ func _internal_editStory(account: Account, peerId: PeerId, id: Int32, media: Eng
for update in updates.allUpdates {
if case let .updateStory(_, story) = update {
switch story {
case let .storyItem(_, _, _, _, _, _, _, media, _, _, _, _):
case let .storyItem(_, _, _, _, _, _, _, _, media, _, _, _, _):
let (parsedMedia, _, _, _, _) = textMediaAndExpirationTimerFromApiMedia(media, account.peerId)
if let parsedMedia = parsedMedia, let originalMedia = originalMedia {
applyMediaResourceChanges(from: originalMedia, to: parsedMedia, postbox: account.postbox, force: false)
@ -1381,7 +1391,8 @@ func _internal_editStoryPrivacy(account: Account, id: Int32, privacy: EngineStor
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
)
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
transaction.setStory(id: storyId, value: entry)
@ -1412,7 +1423,8 @@ func _internal_editStoryPrivacy(account: Account, id: Int32, privacy: EngineStor
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
)
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
items[index] = StoryItemsTableEntry(value: entry, id: item.id, expirationTimestamp: updatedItem.expirationTimestamp, isCloseFriends: updatedItem.isCloseFriends)
@ -1606,7 +1618,8 @@ func _internal_updateStoriesArePinned(account: Account, peerId: PeerId, ids: [In
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
)
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
items[index] = StoryItemsTableEntry(value: entry, id: item.id, expirationTimestamp: updatedItem.expirationTimestamp, isCloseFriends: updatedItem.isCloseFriends)
@ -1636,7 +1649,8 @@ func _internal_updateStoriesArePinned(account: Account, peerId: PeerId, ids: [In
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
)
updatedItems.append(updatedItem)
}
@ -1668,7 +1682,7 @@ func _internal_updateStoriesArePinned(account: Account, peerId: PeerId, ids: [In
extension Api.StoryItem {
var id: Int32 {
switch self {
case let .storyItem(_, id, _, _, _, _, _, _, _, _, _, _):
case let .storyItem(_, id, _, _, _, _, _, _, _, _, _, _, _):
return id
case let .storyItemDeleted(id):
return id
@ -1731,7 +1745,7 @@ extension Stories.Item.ForwardInfo {
extension Stories.StoredItem {
init?(apiStoryItem: Api.StoryItem, existingItem: Stories.Item? = nil, peerId: PeerId, transaction: Transaction) {
switch apiStoryItem {
case let .storyItem(flags, id, date, forwardFrom, expireDate, caption, entities, media, mediaAreas, privacy, views, sentReaction):
case let .storyItem(flags, id, date, fromId, forwardFrom, expireDate, caption, entities, media, mediaAreas, privacy, views, sentReaction):
let (parsedMedia, _, _, _, _) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
if let parsedMedia = parsedMedia {
var parsedPrivacy: Stories.Item.Privacy?
@ -1840,7 +1854,8 @@ extension Stories.StoredItem {
isEdited: isEdited,
isMy: mergedIsMy,
myReaction: mergedMyReaction,
forwardInfo: mergedForwardInfo
forwardInfo: mergedForwardInfo,
authorId: fromId?.peerId
)
self = .item(item)
} else {
@ -1916,7 +1931,8 @@ func _internal_getStoryById(accountPeerId: PeerId, postbox: Postbox, network: Ne
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
}
}
@ -2386,7 +2402,8 @@ func _internal_setStoryReaction(account: Account, peerId: EnginePeer.Id, id: Int
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: reaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
updatedItemValue = updatedItem
if let entry = CodableEntry(updatedItem) {
@ -2419,7 +2436,8 @@ func _internal_setStoryReaction(account: Account, peerId: EnginePeer.Id, id: Int
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: reaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
updatedItemValue = updatedItem
if let entry = CodableEntry(updatedItem) {

View file

@ -78,8 +78,9 @@ public final class EngineStoryItem: Equatable {
public let isMy: Bool
public let myReaction: MessageReaction.Reaction?
public let forwardInfo: ForwardInfo?
public let author: EnginePeer?
public init(id: Int32, timestamp: Int32, expirationTimestamp: Int32, media: EngineMedia, alternativeMedia: EngineMedia?, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?, isPinned: Bool, isExpired: Bool, isPublic: Bool, isPending: Bool, isCloseFriends: Bool, isContacts: Bool, isSelectedContacts: Bool, isForwardingDisabled: Bool, isEdited: Bool, isMy: Bool, myReaction: MessageReaction.Reaction?, forwardInfo: ForwardInfo?) {
public init(id: Int32, timestamp: Int32, expirationTimestamp: Int32, media: EngineMedia, alternativeMedia: EngineMedia?, mediaAreas: [MediaArea], text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?, isPinned: Bool, isExpired: Bool, isPublic: Bool, isPending: Bool, isCloseFriends: Bool, isContacts: Bool, isSelectedContacts: Bool, isForwardingDisabled: Bool, isEdited: Bool, isMy: Bool, myReaction: MessageReaction.Reaction?, forwardInfo: ForwardInfo?, author: EnginePeer?) {
self.id = id
self.timestamp = timestamp
self.expirationTimestamp = expirationTimestamp
@ -102,6 +103,7 @@ public final class EngineStoryItem: Equatable {
self.isMy = isMy
self.myReaction = myReaction
self.forwardInfo = forwardInfo
self.author = author
}
public static func ==(lhs: EngineStoryItem, rhs: EngineStoryItem) -> Bool {
@ -171,6 +173,9 @@ public final class EngineStoryItem: Equatable {
if lhs.forwardInfo != rhs.forwardInfo {
return false
}
if lhs.author != rhs.author {
return false
}
return true
}
}
@ -223,7 +228,8 @@ public extension EngineStoryItem {
isEdited: self.isEdited,
isMy: self.isMy,
myReaction: self.myReaction,
forwardInfo: self.forwardInfo?.storedForwardInfo
forwardInfo: self.forwardInfo?.storedForwardInfo,
authorId: self.author?.id
)
}
}
@ -600,7 +606,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
items.append(mappedItem)
@ -745,7 +752,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
storyItems.append(mappedItem)
}
@ -839,6 +847,11 @@ public final class PeerStoryListContext {
peers[peer.id] = peer
}
}
if let peerId = item.authorId {
if let peer = transaction.getPeer(peerId) {
peers[peer.id] = peer
}
}
}
}
default:
@ -907,7 +920,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) },
author: item.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
)
finalUpdatedState = updatedState
}
@ -955,7 +969,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) },
author: item.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
)
finalUpdatedState = updatedState
} else {
@ -1005,7 +1020,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) },
author: item.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
))
updatedState.items.sort(by: { lhs, rhs in
return lhs.timestamp > rhs.timestamp
@ -1051,7 +1067,8 @@ public final class PeerStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, peers: peers) },
author: item.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
))
updatedState.items.sort(by: { lhs, rhs in
return lhs.timestamp > rhs.timestamp
@ -1221,7 +1238,8 @@ public final class PeerExpiringStoryListContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
items.append(.item(mappedItem))
}

View file

@ -1249,7 +1249,8 @@ public extension TelegramEngine {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo
forwardInfo: item.forwardInfo,
authorId: item.authorId
))
if let entry = CodableEntry(updatedItem) {
currentItems[i] = StoryItemsTableEntry(value: entry, id: updatedItem.id, expirationTimestamp: updatedItem.expirationTimestamp, isCloseFriends: updatedItem.isCloseFriends)

View file

@ -19,15 +19,17 @@ final class StoryAuthorInfoComponent: Component {
let strings: PresentationStrings
let peer: EnginePeer?
let forwardInfo: EngineStoryItem.ForwardInfo?
let author: EnginePeer?
let timestamp: Int32
let counters: Counters?
let isEdited: Bool
init(context: AccountContext, strings: PresentationStrings, peer: EnginePeer?, forwardInfo: EngineStoryItem.ForwardInfo?, timestamp: Int32, counters: Counters?, isEdited: Bool) {
init(context: AccountContext, strings: PresentationStrings, peer: EnginePeer?, forwardInfo: EngineStoryItem.ForwardInfo?, author: EnginePeer?, timestamp: Int32, counters: Counters?, isEdited: Bool) {
self.context = context
self.strings = strings
self.peer = peer
self.forwardInfo = forwardInfo
self.author = author
self.timestamp = timestamp
self.counters = counters
self.isEdited = isEdited
@ -46,6 +48,9 @@ final class StoryAuthorInfoComponent: Component {
if lhs.forwardInfo != rhs.forwardInfo {
return false
}
if lhs.author != rhs.author {
return false
}
if lhs.timestamp != rhs.timestamp {
return false
}
@ -121,6 +126,16 @@ final class StoryAuthorInfoComponent: Component {
}
subtitle = combinedString
subtitleTruncationType = .middle
} else if let author = component.author {
let authorName = author.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)
let timeString = stringForStoryActivityTimestamp(strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, preciseTime: true, relativeTimestamp: component.timestamp, relativeTo: timestamp, short: true)
let combinedString = NSMutableAttributedString()
combinedString.append(NSAttributedString(string: authorName, font: Font.medium(11.0), textColor: titleColor))
if timeString.count < 6 {
combinedString.append(NSAttributedString(string: "\(timeString)", font: Font.regular(11.0), textColor: subtitleColor))
}
subtitle = combinedString
subtitleTruncationType = .middle
} else {
var subtitleString = stringForStoryActivityTimestamp(strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, preciseTime: true, relativeTimestamp: component.timestamp, relativeTo: timestamp)
if component.isEdited {
@ -176,7 +191,16 @@ final class StoryAuthorInfoComponent: Component {
self.repostIconView = nil
repostIconView.removeFromSuperview()
}
var authorPeer: EnginePeer?
if let forwardInfo = component.forwardInfo, case let .known(peer, _, _) = forwardInfo {
authorPeer = peer
} else if let author = component.author {
authorPeer = author
}
if let peer = authorPeer {
let avatarNode: AvatarNode
if let current = self.avatarNode {
avatarNode = current

View file

@ -114,6 +114,11 @@ public final class StoryContentContextImpl: StoryContentContext {
forwardInfoStories.updateValue(nil, forKey: storyId)
}
}
if let peerId = itemValue.authorId {
if let peer = transaction.getPeer(peerId) {
peers[peer.id] = peer
}
}
for entity in itemValue.entities {
if case let .CustomEmoji(_, fileId) = entity.type {
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
@ -296,7 +301,8 @@ public final class StoryContentContextImpl: StoryContentContext {
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: forwardInfo
forwardInfo: forwardInfo,
author: item.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
)
}
var totalCount = peerStoryItemsView.items.count
@ -332,7 +338,8 @@ public final class StoryContentContextImpl: StoryContentContext {
isEdited: false,
isMy: true,
myReaction: nil,
forwardInfo: pendingForwardsInfo[item.randomId]
forwardInfo: pendingForwardsInfo[item.randomId],
author: nil
))
totalCount += 1
}
@ -1187,6 +1194,11 @@ public final class SingleStoryContentContextImpl: StoryContentContext {
stories.updateValue(nil, forKey: storyId)
}
}
if let peerId = item.authorId {
if let peer = transaction.getPeer(peerId) {
peers[peer.id] = peer
}
}
for entity in item.entities {
if case let .CustomEmoji(_, fileId) = entity.type {
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
@ -1312,7 +1324,8 @@ public final class SingleStoryContentContextImpl: StoryContentContext {
isEdited: itemValue.isEdited,
isMy: itemValue.isMy,
myReaction: itemValue.myReaction,
forwardInfo: forwardInfo
forwardInfo: forwardInfo,
author: itemValue.authorId.flatMap { peers[$0].flatMap(EnginePeer.init) }
)
let mainItem = StoryContentItem(
@ -2191,7 +2204,8 @@ private func getCachedStory(storyId: StoryId, transaction: Transaction) -> Engin
isEdited: item.isEdited,
isMy: item.isMy,
myReaction: item.myReaction,
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) }
forwardInfo: item.forwardInfo.flatMap { EngineStoryItem.ForwardInfo($0, transaction: transaction) },
author: item.authorId.flatMap { transaction.getPeer($0).flatMap(EnginePeer.init) }
)
} else {
return nil

View file

@ -4018,6 +4018,7 @@ public final class StoryItemSetContainerComponent: Component {
strings: component.strings,
peer: component.slice.peer,
forwardInfo: component.slice.item.storyItem.forwardInfo,
author: component.slice.item.storyItem.author,
timestamp: component.slice.item.storyItem.timestamp,
counters: counters,
isEdited: component.slice.item.storyItem.isEdited
@ -4051,6 +4052,12 @@ public final class StoryItemSetContainerComponent: Component {
} else {
self.navigateToPeer(peer: peer, chat: false)
}
} else if let author = component.slice.item.storyItem.author {
if author.id == component.context.account.peerId {
self.navigateToMyStories()
} else {
self.navigateToPeer(peer: author, chat: false)
}
} else {
if component.slice.peer.id == component.context.account.peerId {
self.navigateToMyStories()