mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -124,6 +124,7 @@ public enum Stories {
|
||||
case isPinned
|
||||
case isExpired
|
||||
case isPublic
|
||||
case isCloseFriends
|
||||
}
|
||||
|
||||
public let id: Int32
|
||||
@@ -137,6 +138,7 @@ public enum Stories {
|
||||
public let isPinned: Bool
|
||||
public let isExpired: Bool
|
||||
public let isPublic: Bool
|
||||
public let isCloseFriends: Bool
|
||||
|
||||
public init(
|
||||
id: Int32,
|
||||
@@ -149,7 +151,8 @@ public enum Stories {
|
||||
privacy: Privacy?,
|
||||
isPinned: Bool,
|
||||
isExpired: Bool,
|
||||
isPublic: Bool
|
||||
isPublic: Bool,
|
||||
isCloseFriends: Bool
|
||||
) {
|
||||
self.id = id
|
||||
self.timestamp = timestamp
|
||||
@@ -162,6 +165,7 @@ public enum Stories {
|
||||
self.isPinned = isPinned
|
||||
self.isExpired = isExpired
|
||||
self.isPublic = isPublic
|
||||
self.isCloseFriends = isCloseFriends
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@@ -184,6 +188,7 @@ public enum Stories {
|
||||
self.isPinned = try container.decodeIfPresent(Bool.self, forKey: .isPinned) ?? false
|
||||
self.isExpired = try container.decodeIfPresent(Bool.self, forKey: .isExpired) ?? false
|
||||
self.isPublic = try container.decodeIfPresent(Bool.self, forKey: .isPublic) ?? false
|
||||
self.isCloseFriends = try container.decodeIfPresent(Bool.self, forKey: .isCloseFriends) ?? false
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@@ -207,6 +212,7 @@ public enum Stories {
|
||||
try container.encode(self.isPinned, forKey: .isPinned)
|
||||
try container.encode(self.isExpired, forKey: .isExpired)
|
||||
try container.encode(self.isPublic, forKey: .isPublic)
|
||||
try container.encode(self.isCloseFriends, forKey: .isCloseFriends)
|
||||
}
|
||||
|
||||
public static func ==(lhs: Item, rhs: Item) -> Bool {
|
||||
@@ -251,6 +257,9 @@ public enum Stories {
|
||||
if lhs.isPublic != rhs.isPublic {
|
||||
return false
|
||||
}
|
||||
if lhs.isCloseFriends != rhs.isCloseFriends {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -456,6 +465,7 @@ public final class EngineStorySubscriptions: Equatable {
|
||||
public final class Item: Equatable {
|
||||
public let peer: EnginePeer
|
||||
public let hasUnseen: Bool
|
||||
public let hasUnseenCloseFriends: Bool
|
||||
public let storyCount: Int
|
||||
public let unseenCount: Int
|
||||
public let lastTimestamp: Int32
|
||||
@@ -463,12 +473,14 @@ public final class EngineStorySubscriptions: Equatable {
|
||||
public init(
|
||||
peer: EnginePeer,
|
||||
hasUnseen: Bool,
|
||||
hasUnseenCloseFriends: Bool,
|
||||
storyCount: Int,
|
||||
unseenCount: Int,
|
||||
lastTimestamp: Int32
|
||||
) {
|
||||
self.peer = peer
|
||||
self.hasUnseen = hasUnseen
|
||||
self.hasUnseenCloseFriends = hasUnseenCloseFriends
|
||||
self.storyCount = storyCount
|
||||
self.unseenCount = unseenCount
|
||||
self.lastTimestamp = lastTimestamp
|
||||
@@ -484,6 +496,9 @@ public final class EngineStorySubscriptions: Equatable {
|
||||
if lhs.hasUnseen != rhs.hasUnseen {
|
||||
return false
|
||||
}
|
||||
if lhs.hasUnseenCloseFriends != rhs.hasUnseenCloseFriends {
|
||||
return false
|
||||
}
|
||||
if lhs.storyCount != rhs.storyCount {
|
||||
return false
|
||||
}
|
||||
@@ -807,7 +822,8 @@ func _internal_uploadStoryImpl(postbox: Postbox, network: Network, accountPeerId
|
||||
privacy: Stories.Item.Privacy(base: privacy.base, additionallyIncludePeers: privacy.additionallyIncludePeers),
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
|
||||
items.append(StoryItemsTableEntry(value: entry, id: item.id))
|
||||
@@ -954,7 +970,8 @@ func _internal_editStoryPrivacy(account: Account, id: Int32, privacy: EngineStor
|
||||
privacy: Stories.Item.Privacy(base: privacy.base, additionallyIncludePeers: privacy.additionallyIncludePeers),
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
|
||||
transaction.setStory(id: storyId, value: entry)
|
||||
@@ -975,7 +992,8 @@ func _internal_editStoryPrivacy(account: Account, id: Int32, privacy: EngineStor
|
||||
privacy: Stories.Item.Privacy(base: privacy.base, additionallyIncludePeers: privacy.additionallyIncludePeers),
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
|
||||
items[index] = StoryItemsTableEntry(value: entry, id: item.id)
|
||||
@@ -1105,7 +1123,8 @@ func _internal_updateStoriesArePinned(account: Account, ids: [Int32: EngineStory
|
||||
privacy: item.privacy,
|
||||
isPinned: isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
if let entry = CodableEntry(Stories.StoredItem.item(updatedItem)) {
|
||||
items[index] = StoryItemsTableEntry(value: entry, id: item.id)
|
||||
@@ -1125,7 +1144,8 @@ func _internal_updateStoriesArePinned(account: Account, ids: [Int32: EngineStory
|
||||
privacy: item.privacy,
|
||||
isPinned: isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
updatedItems.append(updatedItem)
|
||||
}
|
||||
@@ -1220,6 +1240,7 @@ extension Stories.StoredItem {
|
||||
let isPinned = (flags & (1 << 5)) != 0
|
||||
let isExpired = (flags & (1 << 6)) != 0
|
||||
let isPublic = (flags & (1 << 7)) != 0
|
||||
let isCloseFriends = (flags & (1 << 8)) != 0
|
||||
|
||||
let item = Stories.Item(
|
||||
id: id,
|
||||
@@ -1232,7 +1253,8 @@ extension Stories.StoredItem {
|
||||
privacy: parsedPrivacy,
|
||||
isPinned: isPinned,
|
||||
isExpired: isExpired,
|
||||
isPublic: isPublic
|
||||
isPublic: isPublic,
|
||||
isCloseFriends: isCloseFriends
|
||||
)
|
||||
self = .item(item)
|
||||
} else {
|
||||
|
||||
@@ -43,8 +43,9 @@ public final class EngineStoryItem: Equatable {
|
||||
public let isExpired: Bool
|
||||
public let isPublic: Bool
|
||||
public let isPending: Bool
|
||||
public let isCloseFriends: Bool
|
||||
|
||||
public init(id: Int32, timestamp: Int32, expirationTimestamp: Int32, media: EngineMedia, text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?, isPinned: Bool, isExpired: Bool, isPublic: Bool, isPending: Bool) {
|
||||
public init(id: Int32, timestamp: Int32, expirationTimestamp: Int32, media: EngineMedia, text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?, isPinned: Bool, isExpired: Bool, isPublic: Bool, isPending: Bool, isCloseFriends: Bool) {
|
||||
self.id = id
|
||||
self.timestamp = timestamp
|
||||
self.expirationTimestamp = expirationTimestamp
|
||||
@@ -57,6 +58,7 @@ public final class EngineStoryItem: Equatable {
|
||||
self.isExpired = isExpired
|
||||
self.isPublic = isPublic
|
||||
self.isPending = isPending
|
||||
self.isCloseFriends = isCloseFriends
|
||||
}
|
||||
|
||||
public static func ==(lhs: EngineStoryItem, rhs: EngineStoryItem) -> Bool {
|
||||
@@ -96,6 +98,9 @@ public final class EngineStoryItem: Equatable {
|
||||
if lhs.isPending != rhs.isPending {
|
||||
return false
|
||||
}
|
||||
if lhs.isCloseFriends != rhs.isCloseFriends {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -123,7 +128,8 @@ extension EngineStoryItem {
|
||||
},
|
||||
isPinned: self.isPinned,
|
||||
isExpired: self.isExpired,
|
||||
isPublic: self.isPublic
|
||||
isPublic: self.isPublic,
|
||||
isCloseFriends: self.isCloseFriends
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -480,7 +486,8 @@ public final class PeerStoryListContext {
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic,
|
||||
isPending: false
|
||||
isPending: false,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
items.append(mappedItem)
|
||||
}
|
||||
@@ -585,7 +592,8 @@ public final class PeerStoryListContext {
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic,
|
||||
isPending: false
|
||||
isPending: false,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
storyItems.append(mappedItem)
|
||||
}
|
||||
@@ -717,7 +725,8 @@ public final class PeerStoryListContext {
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic,
|
||||
isPending: false
|
||||
isPending: false,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
finalUpdatedState = updatedState
|
||||
}
|
||||
@@ -754,7 +763,8 @@ public final class PeerStoryListContext {
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic,
|
||||
isPending: false
|
||||
isPending: false,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
))
|
||||
updatedState.items.sort(by: { lhs, rhs in
|
||||
return lhs.timestamp > rhs.timestamp
|
||||
@@ -900,7 +910,8 @@ public final class PeerExpiringStoryListContext {
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic,
|
||||
isPending: false
|
||||
isPending: false,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
)
|
||||
items.append(.item(mappedItem))
|
||||
}
|
||||
@@ -1035,6 +1046,15 @@ public final class PeerExpiringStoryListContext {
|
||||
return timestamp
|
||||
}
|
||||
}
|
||||
|
||||
public var isCloseFriends: Bool {
|
||||
switch self {
|
||||
case let .item(item):
|
||||
return item.isCloseFriends
|
||||
case .placeholder:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class State: Equatable {
|
||||
@@ -1046,6 +1066,10 @@ public final class PeerExpiringStoryListContext {
|
||||
return self.items.contains(where: { $0.id > self.maxReadId })
|
||||
}
|
||||
|
||||
public var hasUnseenCloseFriends: Bool {
|
||||
return self.items.contains(where: { $0.id > self.maxReadId && $0.isCloseFriends })
|
||||
}
|
||||
|
||||
public init(items: [Item], isCached: Bool, maxReadId: Int32) {
|
||||
self.items = items
|
||||
self.isCached = isCached
|
||||
|
||||
@@ -679,6 +679,7 @@ public extension TelegramEngine {
|
||||
var accountItem: EngineStorySubscriptions.Item = EngineStorySubscriptions.Item(
|
||||
peer: EnginePeer(accountPeer),
|
||||
hasUnseen: false,
|
||||
hasUnseenCloseFriends: false,
|
||||
storyCount: 0,
|
||||
unseenCount: 0,
|
||||
lastTimestamp: 0
|
||||
@@ -693,6 +694,7 @@ public extension TelegramEngine {
|
||||
if let lastEntry = itemsView.items.last?.value.get(Stories.StoredItem.self) {
|
||||
let peerState: Stories.PeerState? = stateView.value?.get(Stories.PeerState.self)
|
||||
var hasUnseen = false
|
||||
var hasUnseenCloseFriends = false
|
||||
var unseenCount = 0
|
||||
if let peerState = peerState {
|
||||
hasUnseen = peerState.maxReadId < lastEntry.id
|
||||
@@ -700,6 +702,12 @@ public extension TelegramEngine {
|
||||
for item in itemsView.items {
|
||||
if item.id > peerState.maxReadId {
|
||||
unseenCount += 1
|
||||
|
||||
if case let .item(item) = item.value.get(Stories.StoredItem.self) {
|
||||
if item.isCloseFriends {
|
||||
hasUnseenCloseFriends = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -707,6 +715,7 @@ public extension TelegramEngine {
|
||||
let item = EngineStorySubscriptions.Item(
|
||||
peer: EnginePeer(accountPeer),
|
||||
hasUnseen: hasUnseen,
|
||||
hasUnseenCloseFriends: hasUnseenCloseFriends,
|
||||
storyCount: itemsView.items.count,
|
||||
unseenCount: unseenCount,
|
||||
lastTimestamp: lastEntry.timestamp
|
||||
@@ -735,6 +744,7 @@ public extension TelegramEngine {
|
||||
|
||||
let peerState: Stories.PeerState? = stateView.value?.get(Stories.PeerState.self)
|
||||
var hasUnseen = false
|
||||
var hasUnseenCloseFriends = false
|
||||
var unseenCount = 0
|
||||
if let peerState = peerState {
|
||||
hasUnseen = peerState.maxReadId < lastEntry.id
|
||||
@@ -742,6 +752,12 @@ public extension TelegramEngine {
|
||||
for item in itemsView.items {
|
||||
if item.id > peerState.maxReadId {
|
||||
unseenCount += 1
|
||||
|
||||
if case let .item(item) = item.value.get(Stories.StoredItem.self) {
|
||||
if item.isCloseFriends {
|
||||
hasUnseenCloseFriends = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -749,6 +765,7 @@ public extension TelegramEngine {
|
||||
let item = EngineStorySubscriptions.Item(
|
||||
peer: EnginePeer(peer),
|
||||
hasUnseen: hasUnseen,
|
||||
hasUnseenCloseFriends: hasUnseenCloseFriends,
|
||||
storyCount: itemsView.items.count,
|
||||
unseenCount: unseenCount,
|
||||
lastTimestamp: lastEntry.timestamp
|
||||
@@ -935,7 +952,8 @@ public extension TelegramEngine {
|
||||
privacy: item.privacy,
|
||||
isPinned: item.isPinned,
|
||||
isExpired: item.isExpired,
|
||||
isPublic: item.isPublic
|
||||
isPublic: item.isPublic,
|
||||
isCloseFriends: item.isCloseFriends
|
||||
))
|
||||
if let entry = CodableEntry(updatedItem) {
|
||||
currentItems[i] = StoryItemsTableEntry(value: entry, id: updatedItem.id)
|
||||
|
||||
Reference in New Issue
Block a user