mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 11:00:07 +00:00
33 lines
1020 B
Swift
33 lines
1020 B
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
#endif
|
|
|
|
public enum TogglePeerChatPinnedResult {
|
|
case done
|
|
case limitExceeded
|
|
}
|
|
|
|
public func togglePeerChatPinned(postbox: Postbox, peerId: PeerId) -> Signal<TogglePeerChatPinnedResult, NoError> {
|
|
return postbox.modify { modifier -> TogglePeerChatPinnedResult in
|
|
var peerIds = modifier.getPinnedPeerIds()
|
|
let sameKind = peerIds.filter { ($0.namespace == Namespaces.Peer.SecretChat) == (peerId.namespace == Namespaces.Peer.SecretChat) }
|
|
if sameKind.count + 1 > 5 {
|
|
return .limitExceeded
|
|
} else {
|
|
if let index = peerIds.index(of: peerId) {
|
|
peerIds.remove(at: index)
|
|
} else {
|
|
peerIds.insert(peerId, at: 0)
|
|
}
|
|
modifier.setPinnedPeerIds(peerIds)
|
|
addSynchronizePinnedChatsOperation(modifier: modifier)
|
|
return .done
|
|
}
|
|
}
|
|
}
|