Update API

This commit is contained in:
Isaac 2025-05-17 00:34:35 +08:00
parent 830c38f4bb
commit f681453bd0
13 changed files with 43 additions and 80 deletions

View File

@ -1297,15 +1297,7 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate {
if let data = view.cachedData as? CachedUserData {
return data.sendPaidMessageStars
} else if let channel = peerViewMainPeer(view) as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId {
if let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
return mainChannel.sendPaidMessageStars
} else {
return nil
}
} else {
return channel.sendPaidMessageStars
}
return channel.sendPaidMessageStars
} else {
return nil
}

View File

@ -1266,13 +1266,7 @@ public final class ShareController: ViewController {
requiresStars[peerId] = cachedData.sendPaidMessageStars
}
} else if let channel = peer as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId {
if let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
requiresStars[peerId] = mainChannel.sendPaidMessageStars
}
} else {
requiresStars[peerId] = channel.sendPaidMessageStars
}
requiresStars[peerId] = channel.sendPaidMessageStars
}
}
}
@ -1926,13 +1920,7 @@ public final class ShareController: ViewController {
requiresStars[peerId] = cachedData.sendPaidMessageStars
}
} else if let channel = peer as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId {
if let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
requiresStars[peerId] = mainChannel.sendPaidMessageStars
}
} else {
requiresStars[peerId] = channel.sendPaidMessageStars
}
requiresStars[peerId] = channel.sendPaidMessageStars
}
}
}
@ -2530,9 +2518,6 @@ public final class ShareController: ViewController {
possiblePremiumRequiredPeers.insert(user.id)
} else if let channel = peer as? TelegramChannel, let _ = channel.sendPaidMessageStars {
possiblePremiumRequiredPeers.insert(channel.id)
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = entryData.renderedPeer.peers[linkedMonoforumId] as? TelegramChannel, mainChannel.sendPaidMessageStars != nil {
possiblePremiumRequiredPeers.insert(channel.id)
}
}
}
default:
@ -2565,11 +2550,7 @@ public final class ShareController: ViewController {
requiresPremiumForMessaging[id] = data.flags.contains(.premiumRequired)
requiresStars[id] = data.sendPaidMessageStars?.value
} else if let view = views.views[.basicPeer(id)] as? PeerView, let channel = peerViewMainPeer(view) as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
requiresStars[id] = mainChannel.sendPaidMessageStars?.value
} else {
requiresStars[id] = channel.sendPaidMessageStars?.value
}
requiresStars[id] = channel.sendPaidMessageStars?.value
} else {
requiresPremiumForMessaging[id] = false
}

View File

@ -1291,11 +1291,7 @@ final class ShareControllerNode: ViewControllerTracingNode, ASScrollViewDelegate
requiresStars[peerId] = cachedData.sendPaidMessageStars?.value
}
} else if let channel = peer as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
requiresStars[peerId] = mainChannel.sendPaidMessageStars?.value
} else {
requiresStars[peerId] = channel.sendPaidMessageStars?.value
}
requiresStars[peerId] = channel.sendPaidMessageStars?.value
}
}
}

View File

@ -3607,12 +3607,13 @@ public extension Api.functions.channels {
}
}
public extension Api.functions.channels {
static func toggleForum(channel: Api.InputChannel, enabled: Api.Bool) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
static func toggleForum(channel: Api.InputChannel, enabled: Api.Bool, tabs: Api.Bool) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer()
buffer.appendInt32(-1540781271)
buffer.appendInt32(1073174324)
channel.serialize(buffer, true)
enabled.serialize(buffer, true)
return (FunctionDescription(name: "channels.toggleForum", parameters: [("channel", String(describing: channel)), ("enabled", String(describing: enabled))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
tabs.serialize(buffer, true)
return (FunctionDescription(name: "channels.toggleForum", parameters: [("channel", String(describing: channel)), ("enabled", String(describing: enabled)), ("tabs", String(describing: tabs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer)
var result: Api.Updates?
if let signature = reader.readInt32() {

View File

@ -507,7 +507,7 @@ func _internal_setForumChannelPinnedTopics(account: Account, id: EnginePeer.Id,
}
}
func _internal_setChannelForumMode(postbox: Postbox, network: Network, stateManager: AccountStateManager, peerId: PeerId, isForum: Bool) -> Signal<Never, NoError> {
func _internal_setChannelForumMode(postbox: Postbox, network: Network, stateManager: AccountStateManager, peerId: PeerId, isForum: Bool, displayForumAsTabs: Bool) -> Signal<Never, NoError> {
return postbox.transaction { transaction -> Api.InputChannel? in
return transaction.getPeer(peerId).flatMap(apiInputChannel)
}
@ -515,7 +515,7 @@ func _internal_setChannelForumMode(postbox: Postbox, network: Network, stateMana
guard let inputChannel = inputChannel else {
return .complete()
}
return network.request(Api.functions.channels.toggleForum(channel: inputChannel, enabled: isForum ? .boolTrue : .boolFalse))
return network.request(Api.functions.channels.toggleForum(channel: inputChannel, enabled: isForum ? .boolTrue : .boolFalse, tabs: displayForumAsTabs ? .boolTrue : .boolFalse))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
return .single(nil)

View File

@ -413,11 +413,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal<
} else if let channel = peer as? TelegramChannel {
if channel.flags.contains(.isCreator) || channel.adminRights != nil {
} else {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = transaction.getPeer(linkedMonoforumId) as? TelegramChannel {
sendPaidMessageStars = mainChannel.sendPaidMessageStars
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
}
sendPaidMessageStars = channel.sendPaidMessageStars
}
}

View File

@ -83,10 +83,17 @@ func _internal_updateChannelPaidMessagesStars(account: Account, peerId: PeerId,
}
let channel = channel
.withUpdatedInfo(.broadcast(TelegramChannelBroadcastInfo(flags: infoFlags)))
.withUpdatedSendPaidMessageStars(stars)
transaction.updatePeersInternal([channel], update: { _, channel in
return channel
})
if let linkedMonoforumId = channel.linkedMonoforumId, let monoforumChannel = transaction.getPeer(linkedMonoforumId) as? TelegramChannel {
let monoforumChannel = monoforumChannel
.withUpdatedSendPaidMessageStars(stars)
transaction.updatePeersInternal([monoforumChannel], update: { _, channel in
return monoforumChannel
})
}
}
return account.network.request(Api.functions.channels.updatePaidMessagesPrice(flags: flags, channel: inputChannel, sendPaidMessagesStars: stars?.value ?? 0))

View File

@ -385,11 +385,7 @@ public extension TelegramEngine.EngineData.Item {
if let cachedPeerData = view.cachedData as? CachedUserData {
return cachedPeerData.sendPaidMessageStars
} else if let channel = peerViewMainPeer(view) as? TelegramChannel {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = view.peers[linkedMonoforumId] as? TelegramChannel {
return mainChannel.sendPaidMessageStars
} else {
return channel.sendPaidMessageStars
}
return channel.sendPaidMessageStars
} else {
return nil
}
@ -417,15 +413,7 @@ public extension TelegramEngine.EngineData.Item {
preconditionFailure()
}
if let channel = peerViewMainPeer(view) as? TelegramChannel {
if case let .broadcast(info) = channel.info {
if info.flags.contains(.hasMonoforum) {
return channel.sendPaidMessageStars ?? StarsAmount(value: 0, nanos: 0)
} else {
return nil
}
} else {
return nil
}
return channel.sendPaidMessageStars
} else {
return nil
}

View File

@ -76,7 +76,7 @@ private func createChannel(postbox: Postbox, network: Network, stateManager: Acc
|> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .fail(.generic))
|> mapToSignal { peerId -> Signal<PeerId, CreateChannelError> in
if title.contains("*forum") {
return _internal_setChannelForumMode(postbox: postbox, network: network, stateManager: stateManager, peerId: peerId, isForum: true)
return _internal_setChannelForumMode(postbox: postbox, network: network, stateManager: stateManager, peerId: peerId, isForum: true, displayForumAsTabs: true)
|> castError(CreateChannelError.self)
|> map { _ -> PeerId in
}

View File

@ -1233,8 +1233,8 @@ public extension TelegramEngine {
|> ignoreValues
}
public func setChannelForumMode(id: EnginePeer.Id, isForum: Bool) -> Signal<Never, NoError> {
return _internal_setChannelForumMode(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, peerId: id, isForum: isForum)
public func setChannelForumMode(id: EnginePeer.Id, isForum: Bool, displayForumAsTabs: Bool) -> Signal<Never, NoError> {
return _internal_setChannelForumMode(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, peerId: id, isForum: isForum, displayForumAsTabs: displayForumAsTabs)
}
public func createForumChannelTopic(id: EnginePeer.Id, title: String, iconColor: Int32, iconFileId: Int64?) -> Signal<Int64, CreateForumChannelTopicError> {

View File

@ -9243,7 +9243,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
if isEnabled {
let context = self.context
let signal: Signal<EnginePeer.Id?, NoError> = self.context.engine.peers.convertGroupToSupergroup(peerId: self.peerId, additionalProcessing: { upgradedPeerId -> Signal<Never, NoError> in
return context.engine.peers.setChannelForumMode(id: upgradedPeerId, isForum: isEnabled)
return context.engine.peers.setChannelForumMode(id: upgradedPeerId, isForum: isEnabled, displayForumAsTabs: false)
})
|> map(Optional.init)
|> `catch` { [weak self] error -> Signal<PeerId?, NoError> in
@ -9273,7 +9273,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
return
}
let _ = (self.context.engine.peers.setChannelForumMode(id: resultPeerId, isForum: isEnabled)
let _ = (self.context.engine.peers.setChannelForumMode(id: resultPeerId, isForum: isEnabled, displayForumAsTabs: false)
|> deliverOnMainQueue).startStandalone(completed: { [weak self] in
guard let self, let controller = self.controller else {
return
@ -9286,7 +9286,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
})
}
} else {
let _ = self.context.engine.peers.setChannelForumMode(id: self.peerId, isForum: isEnabled).startStandalone()
let _ = self.context.engine.peers.setChannelForumMode(id: self.peerId, isForum: isEnabled, displayForumAsTabs: false).startStandalone()
}
}

View File

@ -501,11 +501,21 @@ public final class PostSuggestionsSettingsScreen: ViewControllerComponentContain
let configuration = StarsSubscriptionConfiguration.with(appConfiguration: context.currentAppConfiguration.with({ $0 }))
let (peer, initialPrice) = await context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId),
TelegramEngine.EngineData.Item.Peer.SendMessageToChannelPrice(id: peerId)
let peer = await context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
).get()
let initialPrice: StarsAmount?
if case let .channel(channel) = peer, case let .broadcast(info) = channel.info, info.flags.contains(.hasMonoforum), let linkedMonoforumId = channel.linkedMonoforumId {
initialPrice = await context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.SendMessageToChannelPrice(id: linkedMonoforumId)
).get() ?? StarsAmount(value: 20, nanos: 0)
} else {
initialPrice = await context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.SendMessageToChannelPrice(id: peerId)
).get()
}
super.init(context: context, component: PostSuggestionsSettingsScreenComponent(
context: context,
usdWithdrawRate: configuration.usdWithdrawRate,

View File

@ -725,11 +725,7 @@ extension ChatControllerImpl {
if let channel = peerView.peers[peerView.peerId] as? TelegramChannel {
if channel.flags.contains(.isCreator) || channel.adminRights != nil {
} else {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = peerView.peers[linkedMonoforumId] as? TelegramChannel {
sendPaidMessageStars = mainChannel.sendPaidMessageStars
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
}
sendPaidMessageStars = channel.sendPaidMessageStars
}
}
}
@ -1364,11 +1360,7 @@ extension ChatControllerImpl {
if let channel = peerView.peers[peerView.peerId] as? TelegramChannel {
if channel.flags.contains(.isCreator) || channel.adminRights != nil {
} else {
if channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = peerView.peers[linkedMonoforumId] as? TelegramChannel {
sendPaidMessageStars = mainChannel.sendPaidMessageStars
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
}
sendPaidMessageStars = channel.sendPaidMessageStars
}
}
}