diff --git a/submodules/AnimatedAvatarSetNode/Sources/AnimatedAvatarSetNode.swift b/submodules/AnimatedAvatarSetNode/Sources/AnimatedAvatarSetNode.swift index 8b582a1484..4ad78d07e6 100644 --- a/submodules/AnimatedAvatarSetNode/Sources/AnimatedAvatarSetNode.swift +++ b/submodules/AnimatedAvatarSetNode/Sources/AnimatedAvatarSetNode.swift @@ -277,10 +277,14 @@ public final class AnimatedAvatarSetNode: ASDisplayNode { guard let itemNode = self.contentNodes.removeValue(forKey: key) else { continue } - itemNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak itemNode] _ in - itemNode?.removeFromSupernode() - }) - itemNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false) + if animated { + itemNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak itemNode] _ in + itemNode?.removeFromSupernode() + }) + itemNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false) + } else { + itemNode.removeFromSupernode() + } } return CGSize(width: contentWidth, height: contentHeight) diff --git a/submodules/Postbox/Sources/StoryItemsView.swift b/submodules/Postbox/Sources/StoryItemsView.swift index e121ed3327..00066ec43c 100644 --- a/submodules/Postbox/Sources/StoryItemsView.swift +++ b/submodules/Postbox/Sources/StoryItemsView.swift @@ -11,7 +11,7 @@ final class MutableStoryItemsView: MutablePostboxView { func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false - if !transaction.storyStatesEvents.isEmpty { + if !transaction.storyItemsEvents.isEmpty { loop: for event in transaction.storyItemsEvents { switch event { case .replace(peerId): diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift index 5616f6e264..a734865783 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift @@ -647,12 +647,21 @@ func _internal_uploadStory(account: Account, media: EngineStoryInputMedia, text: } func _internal_deleteStory(account: Account, id: Int32) -> Signal { - return account.network.request(Api.functions.stories.deleteStories(id: [id])) - |> `catch` { _ -> Signal<[Int32], NoError> in - return .single([]) + return account.postbox.transaction { transaction -> Void in + var items = transaction.getStoryItems(peerId: account.peerId) + if let index = items.firstIndex(where: { $0.id == id }) { + items.remove(at: index) + transaction.setStoryItems(peerId: account.peerId, items: items) + } } |> mapToSignal { _ -> Signal in - return .complete() + return account.network.request(Api.functions.stories.deleteStories(id: [id])) + |> `catch` { _ -> Signal<[Int32], NoError> in + return .single([]) + } + |> mapToSignal { _ -> Signal in + return .complete() + } } } @@ -676,7 +685,7 @@ func _internal_markStoryAsSeen(account: Account, peerId: PeerId, id: Int32) -> S #if DEBUG if "".isEmpty { - return .complete() + //return .complete() } #endif diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 16daa8c10c..53c7eba5e8 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -609,13 +609,19 @@ public extension TelegramEngine { } var additionalDataKeys: [PostboxViewKey] = [] - additionalDataKeys.append(contentsOf: storySubscriptionsView.peerIds.map { peerId -> PostboxViewKey in + + additionalDataKeys.append(PostboxViewKey.storyItems(peerId: self.account.peerId)) + additionalDataKeys.append(PostboxViewKey.storiesState(key: .peer(self.account.peerId))) + + let subscriptionPeerIds = storySubscriptionsView.peerIds.filter { $0 != self.account.peerId } + + additionalDataKeys.append(contentsOf: subscriptionPeerIds.map { peerId -> PostboxViewKey in return PostboxViewKey.storyItems(peerId: peerId) }) - additionalDataKeys.append(contentsOf: storySubscriptionsView.peerIds.map { peerId -> PostboxViewKey in + additionalDataKeys.append(contentsOf: subscriptionPeerIds.map { peerId -> PostboxViewKey in return PostboxViewKey.storiesState(key: .peer(peerId)) }) - additionalDataKeys.append(contentsOf: storySubscriptionsView.peerIds.map { peerId -> PostboxViewKey in + additionalDataKeys.append(contentsOf: subscriptionPeerIds.map { peerId -> PostboxViewKey in return PostboxViewKey.basicPeer(peerId) }) @@ -642,7 +648,30 @@ public extension TelegramEngine { ) var items: [EngineStorySubscriptions.Item] = [] - for peerId in storySubscriptionsView.peerIds { + + do { + let peerId = self.account.peerId + + if let itemsView = views.views[PostboxViewKey.storyItems(peerId: peerId)] as? StoryItemsView, let stateView = views.views[PostboxViewKey.storiesState(key: .peer(peerId))] as? StoryStatesView { + if let lastEntry = itemsView.items.last?.value.get(Stories.StoredItem.self) { + let peerState: Stories.PeerState? = stateView.value?.get(Stories.PeerState.self) + var hasUnseen = false + if let peerState = peerState { + hasUnseen = peerState.maxReadId < lastEntry.id + } + + let item = EngineStorySubscriptions.Item( + peer: EnginePeer(accountPeer), + hasUnseen: hasUnseen, + storyCount: itemsView.items.count, + lastTimestamp: lastEntry.timestamp + ) + accountItem = item + } + } + } + + for peerId in subscriptionPeerIds { guard let peerView = views.views[PostboxViewKey.basicPeer(peerId)] as? BasicPeerView else { continue } diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift index 2809bbe8bf..ac84987c48 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift @@ -589,6 +589,22 @@ private final class StoryContainerScreenComponent: Component { } } }, + delete: { [weak self] in + guard let self else { + return + } + if let stateValue = component.content.stateValue, let slice = stateValue.slice { + if slice.nextItemId != nil { + component.content.navigate(navigation: .item(.next)) + } else if slice.previousItemId != nil { + component.content.navigate(navigation: .item(.previous)) + } else if let environment = self.environment { + environment.controller()?.dismiss() + } + + let _ = component.context.engine.messages.deleteStory(id: slice.item.storyItem.id).start() + } + }, controller: { [weak self] in return self?.environment?.controller() } diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index 97813816a6..0782369527 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -43,6 +43,7 @@ public final class StoryItemSetContainerComponent: Component { public let presentController: (ViewController) -> Void public let close: () -> Void public let navigate: (NavigationDirection) -> Void + public let delete: () -> Void public let controller: () -> ViewController? public init( @@ -59,6 +60,7 @@ public final class StoryItemSetContainerComponent: Component { presentController: @escaping (ViewController) -> Void, close: @escaping () -> Void, navigate: @escaping (NavigationDirection) -> Void, + delete: @escaping () -> Void, controller: @escaping () -> ViewController? ) { self.context = context @@ -74,6 +76,7 @@ public final class StoryItemSetContainerComponent: Component { self.presentController = presentController self.close = close self.navigate = navigate + self.delete = delete self.controller = controller } @@ -813,8 +816,7 @@ public final class StoryItemSetContainerComponent: Component { context: component.context, storyItem: currentItem?.storyItem, deleteAction: { [weak self] in - let _ = self - /*guard let self, let component = self.component, let focusedItemId = self.focusedItemId else { + guard let self, let component = self.component else { return } @@ -829,8 +831,9 @@ public final class StoryItemSetContainerComponent: Component { guard let self, let component = self.component else { return } + component.delete() - if let currentSlice = self.currentSlice, let index = currentSlice.items.firstIndex(where: { $0.id == focusedItemId }) { + /*if let currentSlice = self.currentSlice, let index = currentSlice.items.firstIndex(where: { $0.id == focusedItemId }) { let item = currentSlice.items[index] if currentSlice.items.count == 1 { @@ -848,7 +851,7 @@ public final class StoryItemSetContainerComponent: Component { } item.delete?() - } + }*/ }) ]), ActionSheetItemGroup(items: [ @@ -868,7 +871,7 @@ public final class StoryItemSetContainerComponent: Component { self.actionSheet = actionSheet self.updateIsProgressPaused() - component.presentController(actionSheet)*/ + component.presentController(actionSheet) }, moreAction: { [weak self] sourceView, gesture in guard let self, let component = self.component, let controller = component.controller() else {