Voice Chat Fixes

This commit is contained in:
Ilya Laktyushin 2021-04-10 00:47:17 +03:00
parent 18e66ecea2
commit 508b3a1853
4 changed files with 34 additions and 24 deletions

View File

@ -80,7 +80,8 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext {
scheduleTimestamp: call.scheduleTimestamp, scheduleTimestamp: call.scheduleTimestamp,
subscribedToScheduled: call.subscribedToScheduled, subscribedToScheduled: call.subscribedToScheduled,
recordingStartTimestamp: nil, recordingStartTimestamp: nil,
sortAscending: true sortAscending: true,
defaultParticipantsAreMuted: nil
), ),
topParticipants: [], topParticipants: [],
participantCount: 0, participantCount: 0,
@ -122,7 +123,7 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext {
} }
return GroupCallPanelData( return GroupCallPanelData(
peerId: peerId, peerId: peerId,
info: GroupCallInfo(id: call.id, accessHash: call.accessHash, participantCount: state.totalCount, clientParams: nil, streamDcId: nil, title: state.title, scheduleTimestamp: state.scheduleTimestamp, subscribedToScheduled: state.subscribedToScheduled, recordingStartTimestamp: nil, sortAscending: state.sortAscending), info: GroupCallInfo(id: call.id, accessHash: call.accessHash, participantCount: state.totalCount, clientParams: nil, streamDcId: nil, title: state.title, scheduleTimestamp: state.scheduleTimestamp, subscribedToScheduled: state.subscribedToScheduled, recordingStartTimestamp: nil, sortAscending: state.sortAscending, defaultParticipantsAreMuted: state.defaultParticipantsAreMuted),
topParticipants: topParticipants, topParticipants: topParticipants,
participantCount: state.totalCount, participantCount: state.totalCount,
activeSpeakers: activeSpeakers, activeSpeakers: activeSpeakers,
@ -1105,7 +1106,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
nextParticipantsFetchOffset: nil, nextParticipantsFetchOffset: nil,
adminIds: Set(), adminIds: Set(),
isCreator: false, isCreator: false,
defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: self.stateValue.defaultParticipantMuteState == .muted, canChange: true), defaultParticipantsAreMuted: callInfo.defaultParticipantsAreMuted ?? GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: self.stateValue.defaultParticipantMuteState == .muted, canChange: true),
sortAscending: true, sortAscending: true,
recordingStartTimestamp: nil, recordingStartTimestamp: nil,
title: self.stateValue.title, title: self.stateValue.title,
@ -1149,6 +1150,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
loadMoreToken: state.nextParticipantsFetchOffset loadMoreToken: state.nextParticipantsFetchOffset
) )
strongSelf.stateValue.adminIds = adminIds
let canManageCall = state.isCreator || strongSelf.stateValue.adminIds.contains(strongSelf.accountContext.account.peerId)
var participants: [GroupCallParticipantsContext.Participant] = [] var participants: [GroupCallParticipantsContext.Participant] = []
var topParticipants: [GroupCallParticipantsContext.Participant] = [] var topParticipants: [GroupCallParticipantsContext.Participant] = []
if let (myPeer, cachedData) = myPeerAndCachedData { if let (myPeer, cachedData) = myPeerAndCachedData {
@ -1169,7 +1173,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
hasRaiseHand: strongSelf.temporaryHasRaiseHand, hasRaiseHand: strongSelf.temporaryHasRaiseHand,
activityTimestamp: strongSelf.temporaryActivityTimestamp, activityTimestamp: strongSelf.temporaryActivityTimestamp,
activityRank: strongSelf.temporaryActivityRank, activityRank: strongSelf.temporaryActivityRank,
muteState: strongSelf.temporaryMuteState ?? GroupCallParticipantsContext.Participant.MuteState(canUnmute: true, mutedByYou: false), muteState: strongSelf.temporaryMuteState ?? GroupCallParticipantsContext.Participant.MuteState(canUnmute: canManageCall || !state.defaultParticipantsAreMuted.isMuted, mutedByYou: false),
volume: nil, volume: nil,
about: about about: about
)) ))
@ -1184,17 +1188,18 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
} }
strongSelf.membersValue = members strongSelf.membersValue = members
strongSelf.stateValue.adminIds = adminIds
strongSelf.stateValue.canManageCall = state.isCreator || adminIds.contains(strongSelf.accountContext.account.peerId) strongSelf.stateValue.canManageCall = state.isCreator || adminIds.contains(strongSelf.accountContext.account.peerId)
if (state.isCreator || strongSelf.stateValue.adminIds.contains(strongSelf.accountContext.account.peerId)) && state.defaultParticipantsAreMuted.canChange { strongSelf.stateValue.defaultParticipantMuteState = state.defaultParticipantsAreMuted.isMuted ? .muted : .unmuted
strongSelf.stateValue.defaultParticipantMuteState = state.defaultParticipantsAreMuted.isMuted ? .muted : .unmuted
}
strongSelf.stateValue.recordingStartTimestamp = state.recordingStartTimestamp strongSelf.stateValue.recordingStartTimestamp = state.recordingStartTimestamp
strongSelf.stateValue.title = state.title strongSelf.stateValue.title = state.title
strongSelf.stateValue.muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canManageCall || !state.defaultParticipantsAreMuted.isMuted, mutedByYou: false)
print("mutestate: \(strongSelf.stateValue.muteState?.canUnmute)")
strongSelf.stateValue.scheduleTimestamp = strongSelf.isScheduledStarted ? nil : state.scheduleTimestamp strongSelf.stateValue.scheduleTimestamp = strongSelf.isScheduledStarted ? nil : state.scheduleTimestamp
if state.scheduleTimestamp == nil && !strongSelf.isScheduledStarted { if state.scheduleTimestamp == nil && !strongSelf.isScheduledStarted {
strongSelf.updateSessionState(internalState: .active(GroupCallInfo(id: callInfo.id, accessHash: callInfo.accessHash, participantCount: state.totalCount, clientParams: callInfo.clientParams, streamDcId: callInfo.streamDcId, title: state.title, scheduleTimestamp: nil, subscribedToScheduled: false, recordingStartTimestamp: nil, sortAscending: true)), audioSessionControl: strongSelf.audioSessionControl) strongSelf.updateSessionState(internalState: .active(GroupCallInfo(id: callInfo.id, accessHash: callInfo.accessHash, participantCount: state.totalCount, clientParams: callInfo.clientParams, streamDcId: callInfo.streamDcId, title: state.title, scheduleTimestamp: nil, subscribedToScheduled: false, recordingStartTimestamp: nil, sortAscending: true, defaultParticipantsAreMuted: callInfo.defaultParticipantsAreMuted ?? state.defaultParticipantsAreMuted)), audioSessionControl: strongSelf.audioSessionControl)
} else { } else {
strongSelf.summaryInfoState.set(.single(SummaryInfoState(info: GroupCallInfo( strongSelf.summaryInfoState.set(.single(SummaryInfoState(info: GroupCallInfo(
id: callInfo.id, id: callInfo.id,
@ -1206,7 +1211,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
scheduleTimestamp: state.scheduleTimestamp, scheduleTimestamp: state.scheduleTimestamp,
subscribedToScheduled: false, subscribedToScheduled: false,
recordingStartTimestamp: state.recordingStartTimestamp, recordingStartTimestamp: state.recordingStartTimestamp,
sortAscending: state.sortAscending sortAscending: state.sortAscending,
defaultParticipantsAreMuted: state.defaultParticipantsAreMuted
)))) ))))
strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState( strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState(
@ -1880,7 +1886,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
scheduleTimestamp: state.scheduleTimestamp, scheduleTimestamp: state.scheduleTimestamp,
subscribedToScheduled: false, subscribedToScheduled: false,
recordingStartTimestamp: state.recordingStartTimestamp, recordingStartTimestamp: state.recordingStartTimestamp,
sortAscending: state.sortAscending sortAscending: state.sortAscending,
defaultParticipantsAreMuted: state.defaultParticipantsAreMuted
)))) ))))
strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState( strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState(

View File

@ -15,6 +15,7 @@ public struct GroupCallInfo: Equatable {
public var subscribedToScheduled: Bool public var subscribedToScheduled: Bool
public var recordingStartTimestamp: Int32? public var recordingStartTimestamp: Int32?
public var sortAscending: Bool public var sortAscending: Bool
public var defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted?
public init( public init(
id: Int64, id: Int64,
@ -26,7 +27,8 @@ public struct GroupCallInfo: Equatable {
scheduleTimestamp: Int32?, scheduleTimestamp: Int32?,
subscribedToScheduled: Bool, subscribedToScheduled: Bool,
recordingStartTimestamp: Int32?, recordingStartTimestamp: Int32?,
sortAscending: Bool sortAscending: Bool,
defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted?
) { ) {
self.id = id self.id = id
self.accessHash = accessHash self.accessHash = accessHash
@ -38,6 +40,7 @@ public struct GroupCallInfo: Equatable {
self.subscribedToScheduled = subscribedToScheduled self.subscribedToScheduled = subscribedToScheduled
self.recordingStartTimestamp = recordingStartTimestamp self.recordingStartTimestamp = recordingStartTimestamp
self.sortAscending = sortAscending self.sortAscending = sortAscending
self.defaultParticipantsAreMuted = defaultParticipantsAreMuted
} }
} }
@ -67,7 +70,8 @@ extension GroupCallInfo {
scheduleTimestamp: scheduleDate, scheduleTimestamp: scheduleDate,
subscribedToScheduled: (flags & (1 << 8)) != 0, subscribedToScheduled: (flags & (1 << 8)) != 0,
recordingStartTimestamp: recordStartDate, recordingStartTimestamp: recordStartDate,
sortAscending: (flags & (1 << 6)) != 0 sortAscending: (flags & (1 << 6)) != 0,
defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: (flags & (1 << 1)) != 0, canChange: (flags & (1 << 2)) != 0)
) )
case .groupCallDiscarded: case .groupCallDiscarded:
return nil return nil
@ -92,7 +96,6 @@ public func getCurrentGroupCall(account: Account, callId: Int64, accessHash: Int
return nil return nil
} }
var peers: [Peer] = [] var peers: [Peer] = []
var peerPresences: [PeerId: PeerPresence] = [:] var peerPresences: [PeerId: PeerPresence] = [:]
@ -380,19 +383,19 @@ public enum GetGroupCallParticipantsError {
} }
public func getGroupCallParticipants(account: Account, callId: Int64, accessHash: Int64, offset: String, ssrcs: [UInt32], limit: Int32, sortAscending: Bool?) -> Signal<GroupCallParticipantsContext.State, GetGroupCallParticipantsError> { public func getGroupCallParticipants(account: Account, callId: Int64, accessHash: Int64, offset: String, ssrcs: [UInt32], limit: Int32, sortAscending: Bool?) -> Signal<GroupCallParticipantsContext.State, GetGroupCallParticipantsError> {
let sortAscendingValue: Signal<(Bool, Int32?, Bool), GetGroupCallParticipantsError> let sortAscendingValue: Signal<(Bool, Int32?, Bool, GroupCallParticipantsContext.State.DefaultParticipantsAreMuted?), GetGroupCallParticipantsError>
if let sortAscending = sortAscending { if let sortAscending = sortAscending {
sortAscendingValue = .single((sortAscending, nil, false)) sortAscendingValue = .single((sortAscending, nil, false, nil))
} else { } else {
sortAscendingValue = getCurrentGroupCall(account: account, callId: callId, accessHash: accessHash) sortAscendingValue = getCurrentGroupCall(account: account, callId: callId, accessHash: accessHash)
|> mapError { _ -> GetGroupCallParticipantsError in |> mapError { _ -> GetGroupCallParticipantsError in
return .generic return .generic
} }
|> mapToSignal { result -> Signal<(Bool, Int32?, Bool), GetGroupCallParticipantsError> in |> mapToSignal { result -> Signal<(Bool, Int32?, Bool, GroupCallParticipantsContext.State.DefaultParticipantsAreMuted?), GetGroupCallParticipantsError> in
guard let result = result else { guard let result = result else {
return .fail(.generic) return .fail(.generic)
} }
return .single((result.info.sortAscending, result.info.scheduleTimestamp, result.info.subscribedToScheduled)) return .single((result.info.sortAscending, result.info.scheduleTimestamp, result.info.subscribedToScheduled, result.info.defaultParticipantsAreMuted))
} }
} }
@ -410,7 +413,7 @@ public func getGroupCallParticipants(account: Account, callId: Int64, accessHash
let version: Int32 let version: Int32
let nextParticipantsFetchOffset: String? let nextParticipantsFetchOffset: String?
let (sortAscendingValue, scheduleTimestamp, subscribedToScheduled) = sortAscendingAndScheduleTimestamp let (sortAscendingValue, scheduleTimestamp, subscribedToScheduled, defaultParticipantsAreMuted) = sortAscendingAndScheduleTimestamp
switch result { switch result {
case let .groupParticipants(count, participants, nextOffset, chats, users, apiVersion): case let .groupParticipants(count, participants, nextOffset, chats, users, apiVersion):
@ -494,7 +497,7 @@ public func getGroupCallParticipants(account: Account, callId: Int64, accessHash
nextParticipantsFetchOffset: nextParticipantsFetchOffset, nextParticipantsFetchOffset: nextParticipantsFetchOffset,
adminIds: Set(), adminIds: Set(),
isCreator: false, isCreator: false,
defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: false, canChange: false), defaultParticipantsAreMuted: defaultParticipantsAreMuted ?? GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: false, canChange: false),
sortAscending: sortAscendingValue, sortAscending: sortAscendingValue,
recordingStartTimestamp: nil, recordingStartTimestamp: nil,
title: nil, title: nil,

View File

@ -157,7 +157,7 @@ public struct HumanReadableStringFormat {
} }
} }
public func humanReadableStringForTimestamp(strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, timestamp: Int32, alwaysShowTime: Bool = false, format: HumanReadableStringFormat? = nil) -> String { public func humanReadableStringForTimestamp(strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, timestamp: Int32, alwaysShowTime: Bool = false, allowYesterday: Bool = true, format: HumanReadableStringFormat? = nil) -> String {
var t: time_t = time_t(timestamp) var t: time_t = time_t(timestamp)
var timeinfo: tm = tm() var timeinfo: tm = tm()
localtime_r(&t, &timeinfo) localtime_r(&t, &timeinfo)
@ -178,7 +178,7 @@ public func humanReadableStringForTimestamp(strings: PresentationStrings, dateTi
} }
let dayDifference = timeinfo.tm_yday - timeinfoNow.tm_yday let dayDifference = timeinfo.tm_yday - timeinfoNow.tm_yday
if dayDifference == 0 || dayDifference == -1 || dayDifference == 1 { if dayDifference == 0 || (dayDifference == -1 && allowYesterday) || dayDifference == 1 {
let day: RelativeTimestampFormatDay let day: RelativeTimestampFormatDay
if dayDifference == 0 { if dayDifference == 0 {
day = .today day = .today

View File

@ -448,11 +448,11 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor) attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor)
case let .groupPhoneCall(_, _, scheduleDate, duration): case let .groupPhoneCall(_, _, scheduleDate, duration):
if let scheduleDate = scheduleDate { if let scheduleDate = scheduleDate {
let timeString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate)
if message.author?.id.namespace == Namespaces.Peer.CloudChannel { if message.author?.id.namespace == Namespaces.Peer.CloudChannel {
let titleString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate, format: HumanReadableStringFormat(dateFormatString: { strings.Notification_VoiceChatScheduledChannel($0).0 }, tomorrowFormatString: { strings.Notification_VoiceChatScheduledTomorrowChannel($0).0 }, todayFormatString: { strings.Notification_VoiceChatScheduledTodayChannel($0).0 }, yesterdayFormatString: { $0 })) let titleString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate, alwaysShowTime: true, allowYesterday: false, format: HumanReadableStringFormat(dateFormatString: { strings.Notification_VoiceChatScheduledChannel($0).0 }, tomorrowFormatString: { strings.Notification_VoiceChatScheduledTomorrowChannel($0).0 }, todayFormatString: { strings.Notification_VoiceChatScheduledTodayChannel($0).0 }, yesterdayFormatString: { $0 }))
attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor) attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor)
} else { } else {
let timeString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate)
let attributePeerIds: [(Int, PeerId?)] = [(0, message.author?.id)] let attributePeerIds: [(Int, PeerId?)] = [(0, message.author?.id)]
let titleString = strings.Notification_VoiceChatScheduled(authorName, timeString) let titleString = strings.Notification_VoiceChatScheduled(authorName, timeString)
attributedString = addAttributesToStringWithRanges(titleString, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: attributePeerIds)) attributedString = addAttributesToStringWithRanges(titleString, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: attributePeerIds))