mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +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 {
|
guard let itemNode = self.contentNodes.removeValue(forKey: key) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if animated {
|
||||||
itemNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak itemNode] _ in
|
itemNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak itemNode] _ in
|
||||||
itemNode?.removeFromSupernode()
|
itemNode?.removeFromSupernode()
|
||||||
})
|
})
|
||||||
itemNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false)
|
itemNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false)
|
||||||
|
} else {
|
||||||
|
itemNode.removeFromSupernode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGSize(width: contentWidth, height: contentHeight)
|
return CGSize(width: contentWidth, height: contentHeight)
|
||||||
|
@ -11,7 +11,7 @@ final class MutableStoryItemsView: MutablePostboxView {
|
|||||||
|
|
||||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||||
var updated = false
|
var updated = false
|
||||||
if !transaction.storyStatesEvents.isEmpty {
|
if !transaction.storyItemsEvents.isEmpty {
|
||||||
loop: for event in transaction.storyItemsEvents {
|
loop: for event in transaction.storyItemsEvents {
|
||||||
switch event {
|
switch event {
|
||||||
case .replace(peerId):
|
case .replace(peerId):
|
||||||
|
@ -647,6 +647,14 @@ func _internal_uploadStory(account: Account, media: EngineStoryInputMedia, text:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func _internal_deleteStory(account: Account, id: Int32) -> Signal<Never, NoError> {
|
func _internal_deleteStory(account: Account, id: Int32) -> Signal<Never, NoError> {
|
||||||
|
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 account.network.request(Api.functions.stories.deleteStories(id: [id]))
|
return account.network.request(Api.functions.stories.deleteStories(id: [id]))
|
||||||
|> `catch` { _ -> Signal<[Int32], NoError> in
|
|> `catch` { _ -> Signal<[Int32], NoError> in
|
||||||
return .single([])
|
return .single([])
|
||||||
@ -655,6 +663,7 @@ func _internal_deleteStory(account: Account, id: Int32) -> Signal<Never, NoError
|
|||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func _internal_markStoryAsSeen(account: Account, peerId: PeerId, id: Int32) -> Signal<Never, NoError> {
|
func _internal_markStoryAsSeen(account: Account, peerId: PeerId, id: Int32) -> Signal<Never, NoError> {
|
||||||
return account.postbox.transaction { transaction -> Api.InputUser? in
|
return account.postbox.transaction { transaction -> Api.InputUser? in
|
||||||
@ -676,7 +685,7 @@ func _internal_markStoryAsSeen(account: Account, peerId: PeerId, id: Int32) -> S
|
|||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if "".isEmpty {
|
if "".isEmpty {
|
||||||
return .complete()
|
//return .complete()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -609,13 +609,19 @@ public extension TelegramEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var additionalDataKeys: [PostboxViewKey] = []
|
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)
|
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))
|
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)
|
return PostboxViewKey.basicPeer(peerId)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -642,7 +648,30 @@ public extension TelegramEngine {
|
|||||||
)
|
)
|
||||||
|
|
||||||
var items: [EngineStorySubscriptions.Item] = []
|
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 {
|
guard let peerView = views.views[PostboxViewKey.basicPeer(peerId)] as? BasicPeerView else {
|
||||||
continue
|
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
|
controller: { [weak self] in
|
||||||
return self?.environment?.controller()
|
return self?.environment?.controller()
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
public let presentController: (ViewController) -> Void
|
public let presentController: (ViewController) -> Void
|
||||||
public let close: () -> Void
|
public let close: () -> Void
|
||||||
public let navigate: (NavigationDirection) -> Void
|
public let navigate: (NavigationDirection) -> Void
|
||||||
|
public let delete: () -> Void
|
||||||
public let controller: () -> ViewController?
|
public let controller: () -> ViewController?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
@ -59,6 +60,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
presentController: @escaping (ViewController) -> Void,
|
presentController: @escaping (ViewController) -> Void,
|
||||||
close: @escaping () -> Void,
|
close: @escaping () -> Void,
|
||||||
navigate: @escaping (NavigationDirection) -> Void,
|
navigate: @escaping (NavigationDirection) -> Void,
|
||||||
|
delete: @escaping () -> Void,
|
||||||
controller: @escaping () -> ViewController?
|
controller: @escaping () -> ViewController?
|
||||||
) {
|
) {
|
||||||
self.context = context
|
self.context = context
|
||||||
@ -74,6 +76,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
self.presentController = presentController
|
self.presentController = presentController
|
||||||
self.close = close
|
self.close = close
|
||||||
self.navigate = navigate
|
self.navigate = navigate
|
||||||
|
self.delete = delete
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,8 +816,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
context: component.context,
|
context: component.context,
|
||||||
storyItem: currentItem?.storyItem,
|
storyItem: currentItem?.storyItem,
|
||||||
deleteAction: { [weak self] in
|
deleteAction: { [weak self] in
|
||||||
let _ = self
|
guard let self, let component = self.component else {
|
||||||
/*guard let self, let component = self.component, let focusedItemId = self.focusedItemId else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -829,8 +831,9 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
guard let self, let component = self.component else {
|
guard let self, let component = self.component else {
|
||||||
return
|
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]
|
let item = currentSlice.items[index]
|
||||||
|
|
||||||
if currentSlice.items.count == 1 {
|
if currentSlice.items.count == 1 {
|
||||||
@ -848,7 +851,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
item.delete?()
|
item.delete?()
|
||||||
}
|
}*/
|
||||||
})
|
})
|
||||||
]),
|
]),
|
||||||
ActionSheetItemGroup(items: [
|
ActionSheetItemGroup(items: [
|
||||||
@ -868,7 +871,7 @@ public final class StoryItemSetContainerComponent: Component {
|
|||||||
self.actionSheet = actionSheet
|
self.actionSheet = actionSheet
|
||||||
self.updateIsProgressPaused()
|
self.updateIsProgressPaused()
|
||||||
|
|
||||||
component.presentController(actionSheet)*/
|
component.presentController(actionSheet)
|
||||||
},
|
},
|
||||||
moreAction: { [weak self] sourceView, gesture in
|
moreAction: { [weak self] sourceView, gesture in
|
||||||
guard let self, let component = self.component, let controller = component.controller() else {
|
guard let self, let component = self.component, let controller = component.controller() else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user