[WIP] Stories

This commit is contained in:
Ali
2023-06-13 14:18:16 +03:00
parent 7150af3fe1
commit ceda80c3a5
29 changed files with 913 additions and 195 deletions

View File

@@ -85,10 +85,11 @@ public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
public let image: TelegramMediaImage?
public let file: TelegramMediaFile?
public let story: TelegramMediaStory?
public let attributes: [TelegramMediaWebpageAttribute]
public let instantPage: InstantPage?
public init(url: String, displayUrl: String, hash: Int32, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: PixelDimensions?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, attributes: [TelegramMediaWebpageAttribute], instantPage: InstantPage?) {
public init(url: String, displayUrl: String, hash: Int32, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: PixelDimensions?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, story: TelegramMediaStory?, attributes: [TelegramMediaWebpageAttribute], instantPage: InstantPage?) {
self.url = url
self.displayUrl = displayUrl
self.hash = hash
@@ -103,6 +104,7 @@ public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
self.author = author
self.image = image
self.file = file
self.story = story
self.attributes = attributes
self.instantPage = instantPage
}
@@ -141,6 +143,12 @@ public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
self.file = nil
}
if let story = decoder.decodeObjectForKey("stry") as? TelegramMediaStory {
self.story = story
} else {
self.story = nil
}
var effectiveAttributes: [TelegramMediaWebpageAttribute] = []
if let attributes = decoder.decodeObjectArrayWithDecoderForKey("attr") as [TelegramMediaWebpageAttribute]? {
effectiveAttributes.append(contentsOf: attributes)
@@ -218,6 +226,11 @@ public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
} else {
encoder.encodeNil(forKey: "fi")
}
if let story = self.story {
encoder.encodeObject(story, forKey: "stry")
} else {
encoder.encodeNil(forKey: "stry")
}
encoder.encodeObjectArray(self.attributes, forKey: "attr")
@@ -261,6 +274,14 @@ public func ==(lhs: TelegramMediaWebpageLoadedContent, rhs: TelegramMediaWebpage
return false
}
if let lhsStory = lhs.story, let rhsStory = rhs.story {
if !lhsStory.isEqual(to: rhsStory) {
return false
}
} else if (lhs.story == nil) != (rhs.story == nil) {
return false
}
if lhs.attributes.count != rhs.attributes.count {
return false
} else {
@@ -289,6 +310,14 @@ public final class TelegramMediaWebpage: Media, Equatable {
}
public let peerIds: [PeerId] = []
public var storyIds: [StoryId] {
if case let .Loaded(content) = self.content, let story = content.story {
return story.storyIds
} else {
return []
}
}
public let webpageId: MediaId
public let content: TelegramMediaWebpageContent