mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-27 10:32:37 +00:00
Avoid empty participant list in voice chats
This commit is contained in:
parent
72d0a221cd
commit
0e44390a0f
@ -742,9 +742,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
if let initialCall = initialCall, let temporaryParticipantsContext = (self.accountContext.cachedGroupCallContexts as? AccountGroupCallContextCacheImpl)?.impl.syncWith({ impl in
|
if let initialCall = initialCall, let temporaryParticipantsContext = (self.accountContext.cachedGroupCallContexts as? AccountGroupCallContextCacheImpl)?.impl.syncWith({ impl in
|
||||||
impl.get(account: accountContext.account, peerId: peerId, call: CachedChannelData.ActiveCall(id: initialCall.id, accessHash: initialCall.accessHash, title: initialCall.title))
|
impl.get(account: accountContext.account, peerId: peerId, call: CachedChannelData.ActiveCall(id: initialCall.id, accessHash: initialCall.accessHash, title: initialCall.title))
|
||||||
}) {
|
}) {
|
||||||
if let participantsContext = temporaryParticipantsContext.context.participantsContext, let immediateState = participantsContext.immediateState {
|
self.switchToTemporaryParticipantsContext(sourceContext: temporaryParticipantsContext.context.participantsContext, oldMyPeerId: self.joinAsPeerId)
|
||||||
self.switchToTemporaryParticipantsContext(sourceContext: participantsContext, initialState: immediateState, oldMyPeerId: self.joinAsPeerId)
|
} else {
|
||||||
}
|
self.switchToTemporaryParticipantsContext(sourceContext: nil, oldMyPeerId: self.joinAsPeerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.removedChannelMembersDisposable = (accountContext.peerChannelMemberCategoriesContextsManager.removedChannelMembers
|
self.removedChannelMembersDisposable = (accountContext.peerChannelMemberCategoriesContextsManager.removedChannelMembers
|
||||||
@ -817,7 +817,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
self.removedChannelMembersDisposable?.dispose()
|
self.removedChannelMembersDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func switchToTemporaryParticipantsContext(sourceContext: GroupCallParticipantsContext, initialState: GroupCallParticipantsContext.State, oldMyPeerId: PeerId) {
|
private func switchToTemporaryParticipantsContext(sourceContext: GroupCallParticipantsContext?, oldMyPeerId: PeerId) {
|
||||||
let myPeerId = self.joinAsPeerId
|
let myPeerId = self.joinAsPeerId
|
||||||
let myPeer = self.accountContext.account.postbox.transaction { transaction -> (Peer, CachedPeerData?)? in
|
let myPeer = self.accountContext.account.postbox.transaction { transaction -> (Peer, CachedPeerData?)? in
|
||||||
if let peer = transaction.getPeer(myPeerId) {
|
if let peer = transaction.getPeer(myPeerId) {
|
||||||
@ -826,102 +826,166 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let temporaryParticipantsContext = GroupCallParticipantsContext(account: self.account, peerId: self.peerId, myPeerId: myPeerId, id: sourceContext.id, accessHash: sourceContext.accessHash, state: initialState)
|
if let sourceContext = sourceContext, let initialState = sourceContext.immediateState {
|
||||||
self.temporaryParticipantsContext = temporaryParticipantsContext
|
let temporaryParticipantsContext = GroupCallParticipantsContext(account: self.account, peerId: self.peerId, myPeerId: myPeerId, id: sourceContext.id, accessHash: sourceContext.accessHash, state: initialState)
|
||||||
self.participantsContextStateDisposable.set((combineLatest(queue: .mainQueue(),
|
self.temporaryParticipantsContext = temporaryParticipantsContext
|
||||||
myPeer,
|
self.participantsContextStateDisposable.set((combineLatest(queue: .mainQueue(),
|
||||||
temporaryParticipantsContext.state,
|
myPeer,
|
||||||
temporaryParticipantsContext.activeSpeakers
|
temporaryParticipantsContext.state,
|
||||||
)
|
temporaryParticipantsContext.activeSpeakers
|
||||||
|> take(1)).start(next: { [weak self] myPeerAndCachedData, state, activeSpeakers in
|
|
||||||
guard let strongSelf = self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var topParticipants: [GroupCallParticipantsContext.Participant] = []
|
|
||||||
|
|
||||||
var members = PresentationGroupCallMembers(
|
|
||||||
participants: [],
|
|
||||||
speakingParticipants: [],
|
|
||||||
totalCount: 0,
|
|
||||||
loadMoreToken: nil
|
|
||||||
)
|
)
|
||||||
|
|> take(1)).start(next: { [weak self] myPeerAndCachedData, state, activeSpeakers in
|
||||||
var updatedInvitedPeers = strongSelf.invitedPeersValue
|
guard let strongSelf = self else {
|
||||||
var didUpdateInvitedPeers = false
|
return
|
||||||
|
}
|
||||||
var participants = state.participants
|
|
||||||
|
var topParticipants: [GroupCallParticipantsContext.Participant] = []
|
||||||
if oldMyPeerId != myPeerId {
|
|
||||||
for i in 0 ..< participants.count {
|
var members = PresentationGroupCallMembers(
|
||||||
if participants[i].peer.id == oldMyPeerId {
|
participants: [],
|
||||||
participants.remove(at: i)
|
speakingParticipants: [],
|
||||||
break
|
totalCount: 0,
|
||||||
|
loadMoreToken: nil
|
||||||
|
)
|
||||||
|
|
||||||
|
var updatedInvitedPeers = strongSelf.invitedPeersValue
|
||||||
|
var didUpdateInvitedPeers = false
|
||||||
|
|
||||||
|
var participants = state.participants
|
||||||
|
|
||||||
|
if oldMyPeerId != myPeerId {
|
||||||
|
for i in 0 ..< participants.count {
|
||||||
|
if participants[i].peer.id == oldMyPeerId {
|
||||||
|
participants.remove(at: i)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if !participants.contains(where: { $0.peer.id == myPeerId }) {
|
||||||
if !participants.contains(where: { $0.peer.id == myPeerId }) {
|
if let (myPeer, cachedData) = myPeerAndCachedData {
|
||||||
if let (myPeer, cachedData) = myPeerAndCachedData {
|
let about: String?
|
||||||
let about: String?
|
if let cachedData = cachedData as? CachedUserData {
|
||||||
if let cachedData = cachedData as? CachedUserData {
|
about = cachedData.about
|
||||||
about = cachedData.about
|
} else if let cachedData = cachedData as? CachedUserData {
|
||||||
} else if let cachedData = cachedData as? CachedUserData {
|
about = cachedData.about
|
||||||
about = cachedData.about
|
} else {
|
||||||
} else {
|
about = nil
|
||||||
about = nil
|
}
|
||||||
|
participants.append(GroupCallParticipantsContext.Participant(
|
||||||
|
peer: myPeer,
|
||||||
|
ssrc: nil,
|
||||||
|
jsonParams: nil,
|
||||||
|
joinTimestamp: strongSelf.temporaryJoinTimestamp,
|
||||||
|
raiseHandRating: nil,
|
||||||
|
hasRaiseHand: false,
|
||||||
|
activityTimestamp: strongSelf.temporaryActivityTimestamp,
|
||||||
|
activityRank: strongSelf.temporaryActivityRank,
|
||||||
|
muteState: GroupCallParticipantsContext.Participant.MuteState(canUnmute: true, mutedByYou: false),
|
||||||
|
volume: nil,
|
||||||
|
about: about
|
||||||
|
))
|
||||||
|
participants.sort()
|
||||||
}
|
}
|
||||||
participants.append(GroupCallParticipantsContext.Participant(
|
|
||||||
peer: myPeer,
|
|
||||||
ssrc: nil,
|
|
||||||
jsonParams: nil,
|
|
||||||
joinTimestamp: strongSelf.temporaryJoinTimestamp,
|
|
||||||
raiseHandRating: nil,
|
|
||||||
hasRaiseHand: false,
|
|
||||||
activityTimestamp: strongSelf.temporaryActivityTimestamp,
|
|
||||||
activityRank: strongSelf.temporaryActivityRank,
|
|
||||||
muteState: GroupCallParticipantsContext.Participant.MuteState(canUnmute: true, mutedByYou: false),
|
|
||||||
volume: nil,
|
|
||||||
about: about
|
|
||||||
))
|
|
||||||
participants.sort()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
for participant in participants {
|
||||||
for participant in participants {
|
members.participants.append(participant)
|
||||||
members.participants.append(participant)
|
|
||||||
|
if topParticipants.count < 3 {
|
||||||
if topParticipants.count < 3 {
|
topParticipants.append(participant)
|
||||||
topParticipants.append(participant)
|
}
|
||||||
|
|
||||||
|
if let index = updatedInvitedPeers.firstIndex(of: participant.peer.id) {
|
||||||
|
updatedInvitedPeers.remove(at: index)
|
||||||
|
didUpdateInvitedPeers = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let index = updatedInvitedPeers.firstIndex(of: participant.peer.id) {
|
members.totalCount = state.totalCount
|
||||||
updatedInvitedPeers.remove(at: index)
|
members.loadMoreToken = state.nextParticipantsFetchOffset
|
||||||
didUpdateInvitedPeers = true
|
|
||||||
|
strongSelf.membersValue = members
|
||||||
|
|
||||||
|
var stateValue = strongSelf.stateValue
|
||||||
|
stateValue.myPeerId = strongSelf.joinAsPeerId
|
||||||
|
stateValue.adminIds = state.adminIds
|
||||||
|
|
||||||
|
strongSelf.stateValue = stateValue
|
||||||
|
|
||||||
|
strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState(
|
||||||
|
participantCount: state.totalCount,
|
||||||
|
topParticipants: topParticipants,
|
||||||
|
activeSpeakers: activeSpeakers
|
||||||
|
)))
|
||||||
|
|
||||||
|
if didUpdateInvitedPeers {
|
||||||
|
strongSelf.invitedPeersValue = updatedInvitedPeers
|
||||||
}
|
}
|
||||||
}
|
}))
|
||||||
|
} else {
|
||||||
members.totalCount = state.totalCount
|
self.temporaryParticipantsContext = nil
|
||||||
members.loadMoreToken = state.nextParticipantsFetchOffset
|
self.participantsContextStateDisposable.set((myPeer
|
||||||
|
|> deliverOnMainQueue
|
||||||
strongSelf.membersValue = members
|
|> take(1)).start(next: { [weak self] myPeerAndCachedData in
|
||||||
|
guard let strongSelf = self else {
|
||||||
var stateValue = strongSelf.stateValue
|
return
|
||||||
stateValue.myPeerId = strongSelf.joinAsPeerId
|
}
|
||||||
stateValue.adminIds = state.adminIds
|
|
||||||
|
var topParticipants: [GroupCallParticipantsContext.Participant] = []
|
||||||
strongSelf.stateValue = stateValue
|
|
||||||
|
var members = PresentationGroupCallMembers(
|
||||||
strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState(
|
participants: [],
|
||||||
participantCount: state.totalCount,
|
speakingParticipants: [],
|
||||||
topParticipants: topParticipants,
|
totalCount: 0,
|
||||||
activeSpeakers: activeSpeakers
|
loadMoreToken: nil
|
||||||
)))
|
)
|
||||||
|
|
||||||
if didUpdateInvitedPeers {
|
var participants: [GroupCallParticipantsContext.Participant] = []
|
||||||
strongSelf.invitedPeersValue = updatedInvitedPeers
|
|
||||||
}
|
if !participants.contains(where: { $0.peer.id == myPeerId }) {
|
||||||
}))
|
if let (myPeer, cachedData) = myPeerAndCachedData {
|
||||||
|
let about: String?
|
||||||
|
if let cachedData = cachedData as? CachedUserData {
|
||||||
|
about = cachedData.about
|
||||||
|
} else if let cachedData = cachedData as? CachedUserData {
|
||||||
|
about = cachedData.about
|
||||||
|
} else {
|
||||||
|
about = nil
|
||||||
|
}
|
||||||
|
participants.append(GroupCallParticipantsContext.Participant(
|
||||||
|
peer: myPeer,
|
||||||
|
ssrc: nil,
|
||||||
|
jsonParams: nil,
|
||||||
|
joinTimestamp: strongSelf.temporaryJoinTimestamp,
|
||||||
|
raiseHandRating: nil,
|
||||||
|
hasRaiseHand: false,
|
||||||
|
activityTimestamp: strongSelf.temporaryActivityTimestamp,
|
||||||
|
activityRank: strongSelf.temporaryActivityRank,
|
||||||
|
muteState: GroupCallParticipantsContext.Participant.MuteState(canUnmute: true, mutedByYou: false),
|
||||||
|
volume: nil,
|
||||||
|
about: about
|
||||||
|
))
|
||||||
|
participants.sort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for participant in participants {
|
||||||
|
members.participants.append(participant)
|
||||||
|
|
||||||
|
if topParticipants.count < 3 {
|
||||||
|
topParticipants.append(participant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strongSelf.membersValue = members
|
||||||
|
|
||||||
|
var stateValue = strongSelf.stateValue
|
||||||
|
stateValue.myPeerId = strongSelf.joinAsPeerId
|
||||||
|
|
||||||
|
strongSelf.stateValue = stateValue
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateSessionState(internalState: InternalState, audioSessionControl: ManagedAudioSessionControl?) {
|
private func updateSessionState(internalState: InternalState, audioSessionControl: ManagedAudioSessionControl?) {
|
||||||
@ -1671,7 +1735,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
strongSelf.temporaryActivityRank = participant.activityRank
|
strongSelf.temporaryActivityRank = participant.activityRank
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strongSelf.switchToTemporaryParticipantsContext(sourceContext: participantsContext, initialState: immediateState, oldMyPeerId: previousPeerId)
|
strongSelf.switchToTemporaryParticipantsContext(sourceContext: participantsContext, oldMyPeerId: previousPeerId)
|
||||||
} else {
|
} else {
|
||||||
strongSelf.stateValue.myPeerId = peerId
|
strongSelf.stateValue.myPeerId = peerId
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user