Conference updates

This commit is contained in:
Isaac
2025-04-04 14:04:52 +04:00
parent e03a9d818e
commit e8b7f53c84
6 changed files with 297 additions and 70 deletions

View File

@@ -241,6 +241,53 @@ func _internal_getCurrentGroupCall(account: Account, reference: InternalGroupCal
}
}
func _internal_getCurrentGroupCallInfo(account: Account, reference: InternalGroupCallReference) -> Signal<(participants: [PeerId], duration: Int32?)?, NoError> {
let accountPeerId = account.peerId
let inputCall: Api.InputGroupCall
switch reference {
case let .id(id, accessHash):
inputCall = .inputGroupCall(id: id, accessHash: accessHash)
case let .link(slug):
inputCall = .inputGroupCallSlug(slug: slug)
case let .message(id):
if id.peerId.namespace != Namespaces.Peer.CloudUser {
return .single(nil)
}
if id.namespace != Namespaces.Message.Cloud {
return .single(nil)
}
inputCall = .inputGroupCallInviteMessage(msgId: id.id)
}
return account.network.request(Api.functions.phone.getGroupCall(call: inputCall, limit: 4))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.phone.GroupCall?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<(participants: [PeerId], duration: Int32?)?, NoError> in
guard let result else {
return .single(nil)
}
switch result {
case let .groupCall(call, participants, _, chats, users):
return account.postbox.transaction { transaction -> (participants: [PeerId], duration: Int32?)? in
if case let .groupCallDiscarded(_, _, duration) = call {
return ([], duration)
}
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
let parsedParticipants = participants.compactMap { GroupCallParticipantsContext.Participant($0, transaction: transaction) }
return (
parsedParticipants.map(\.peer.id),
nil
)
}
}
}
}
public enum CreateGroupCallError {
case generic
case anonymousNotAllowed
@@ -3050,3 +3097,59 @@ func _internal_sendConferenceCallBroadcast(account: Account, callId: Int64, acce
return .complete()
}
}
func _internal_refreshInlineGroupCall(account: Account, messageId: MessageId) -> Signal<Never, NoError> {
return _internal_getCurrentGroupCallInfo(account: account, reference: .message(id: messageId))
|> mapToSignal { result -> Signal<Never, NoError> in
return account.postbox.transaction { transaction -> Void in
transaction.updateMessage(messageId, update: { currentMessage in
var storeForwardInfo: StoreMessageForwardInfo?
if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature, psaType: forwardInfo.psaType, flags: forwardInfo.flags)
}
var updatedMedia = currentMessage.media
for i in 0 ..< updatedMedia.count {
if let action = updatedMedia[i] as? TelegramMediaAction, case let .conferenceCall(conferenceCall) = action.action {
var otherParticipants: [PeerId] = []
var duration: Int32? = conferenceCall.duration
if let result {
for id in result.participants {
if id != account.peerId {
otherParticipants.append(id)
}
}
duration = result.duration
} else {
duration = nil
}
updatedMedia[i] = TelegramMediaAction(action: .conferenceCall(TelegramMediaActionType.ConferenceCall(
callId: conferenceCall.callId,
duration: duration,
flags: conferenceCall.flags,
otherParticipants: otherParticipants
)))
}
}
return .update(StoreMessage(
id: currentMessage.id,
globallyUniqueId: currentMessage.globallyUniqueId,
groupingKey: currentMessage.groupingKey,
threadId: currentMessage.threadId,
timestamp: currentMessage.timestamp,
flags: StoreMessageFlags(currentMessage.flags),
tags: currentMessage.tags,
globalTags: currentMessage.globalTags,
localTags: currentMessage.localTags,
forwardInfo: storeForwardInfo,
authorId: currentMessage.author?.id,
text: currentMessage.text,
attributes: currentMessage.attributes,
media: updatedMedia
))
})
}
|> ignoreValues
}
}