mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
[WIP] Stories
This commit is contained in:
parent
a7fcefca85
commit
e576ce0563
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -647,12 +647,21 @@ func _internal_uploadStory(account: Account, media: EngineStoryInputMedia, text:
|
||||
}
|
||||
|
||||
func _internal_deleteStory(account: Account, id: Int32) -> Signal<Never, NoError> {
|
||||
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<Never, NoError> in
|
||||
return .complete()
|
||||
return account.network.request(Api.functions.stories.deleteStories(id: [id]))
|
||||
|> `catch` { _ -> Signal<[Int32], NoError> in
|
||||
return .single([])
|
||||
}
|
||||
|> mapToSignal { _ -> Signal<Never, NoError> 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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user