From 508b3a1853dd4e70d4837489c6dc8fc20a28a15f Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 10 Apr 2021 00:47:17 +0300 Subject: [PATCH] Voice Chat Fixes --- .../Sources/PresentationGroupCall.swift | 29 ++++++++++++------- .../TelegramCore/Sources/GroupCalls.swift | 21 ++++++++------ .../Sources/PresenceStrings.swift | 4 +-- .../Sources/ServiceMessageStrings.swift | 4 +-- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index 38aece12cf..7cf4247d70 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -80,7 +80,8 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext { scheduleTimestamp: call.scheduleTimestamp, subscribedToScheduled: call.subscribedToScheduled, recordingStartTimestamp: nil, - sortAscending: true + sortAscending: true, + defaultParticipantsAreMuted: nil ), topParticipants: [], participantCount: 0, @@ -122,7 +123,7 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext { } return GroupCallPanelData( 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, participantCount: state.totalCount, activeSpeakers: activeSpeakers, @@ -1105,7 +1106,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { nextParticipantsFetchOffset: nil, adminIds: Set(), 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, recordingStartTimestamp: nil, title: self.stateValue.title, @@ -1149,6 +1150,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { loadMoreToken: state.nextParticipantsFetchOffset ) + strongSelf.stateValue.adminIds = adminIds + let canManageCall = state.isCreator || strongSelf.stateValue.adminIds.contains(strongSelf.accountContext.account.peerId) + var participants: [GroupCallParticipantsContext.Participant] = [] var topParticipants: [GroupCallParticipantsContext.Participant] = [] if let (myPeer, cachedData) = myPeerAndCachedData { @@ -1169,7 +1173,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { hasRaiseHand: strongSelf.temporaryHasRaiseHand, activityTimestamp: strongSelf.temporaryActivityTimestamp, 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, about: about )) @@ -1184,17 +1188,18 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { } strongSelf.membersValue = members - strongSelf.stateValue.adminIds = adminIds 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.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 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 { strongSelf.summaryInfoState.set(.single(SummaryInfoState(info: GroupCallInfo( id: callInfo.id, @@ -1206,7 +1211,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { scheduleTimestamp: state.scheduleTimestamp, subscribedToScheduled: false, recordingStartTimestamp: state.recordingStartTimestamp, - sortAscending: state.sortAscending + sortAscending: state.sortAscending, + defaultParticipantsAreMuted: state.defaultParticipantsAreMuted )))) strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState( @@ -1880,7 +1886,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { scheduleTimestamp: state.scheduleTimestamp, subscribedToScheduled: false, recordingStartTimestamp: state.recordingStartTimestamp, - sortAscending: state.sortAscending + sortAscending: state.sortAscending, + defaultParticipantsAreMuted: state.defaultParticipantsAreMuted )))) strongSelf.summaryParticipantsState.set(.single(SummaryParticipantsState( diff --git a/submodules/TelegramCore/Sources/GroupCalls.swift b/submodules/TelegramCore/Sources/GroupCalls.swift index 301b45c904..da4916ec20 100644 --- a/submodules/TelegramCore/Sources/GroupCalls.swift +++ b/submodules/TelegramCore/Sources/GroupCalls.swift @@ -15,6 +15,7 @@ public struct GroupCallInfo: Equatable { public var subscribedToScheduled: Bool public var recordingStartTimestamp: Int32? public var sortAscending: Bool + public var defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted? public init( id: Int64, @@ -26,7 +27,8 @@ public struct GroupCallInfo: Equatable { scheduleTimestamp: Int32?, subscribedToScheduled: Bool, recordingStartTimestamp: Int32?, - sortAscending: Bool + sortAscending: Bool, + defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted? ) { self.id = id self.accessHash = accessHash @@ -38,6 +40,7 @@ public struct GroupCallInfo: Equatable { self.subscribedToScheduled = subscribedToScheduled self.recordingStartTimestamp = recordingStartTimestamp self.sortAscending = sortAscending + self.defaultParticipantsAreMuted = defaultParticipantsAreMuted } } @@ -67,7 +70,8 @@ extension GroupCallInfo { scheduleTimestamp: scheduleDate, subscribedToScheduled: (flags & (1 << 8)) != 0, 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: return nil @@ -92,7 +96,6 @@ public func getCurrentGroupCall(account: Account, callId: Int64, accessHash: Int return nil } - var peers: [Peer] = [] 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 { - let sortAscendingValue: Signal<(Bool, Int32?, Bool), GetGroupCallParticipantsError> + let sortAscendingValue: Signal<(Bool, Int32?, Bool, GroupCallParticipantsContext.State.DefaultParticipantsAreMuted?), GetGroupCallParticipantsError> if let sortAscending = sortAscending { - sortAscendingValue = .single((sortAscending, nil, false)) + sortAscendingValue = .single((sortAscending, nil, false, nil)) } else { sortAscendingValue = getCurrentGroupCall(account: account, callId: callId, accessHash: accessHash) |> mapError { _ -> GetGroupCallParticipantsError in 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 { 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 nextParticipantsFetchOffset: String? - let (sortAscendingValue, scheduleTimestamp, subscribedToScheduled) = sortAscendingAndScheduleTimestamp + let (sortAscendingValue, scheduleTimestamp, subscribedToScheduled, defaultParticipantsAreMuted) = sortAscendingAndScheduleTimestamp switch result { case let .groupParticipants(count, participants, nextOffset, chats, users, apiVersion): @@ -494,7 +497,7 @@ public func getGroupCallParticipants(account: Account, callId: Int64, accessHash nextParticipantsFetchOffset: nextParticipantsFetchOffset, adminIds: Set(), isCreator: false, - defaultParticipantsAreMuted: GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: false, canChange: false), + defaultParticipantsAreMuted: defaultParticipantsAreMuted ?? GroupCallParticipantsContext.State.DefaultParticipantsAreMuted(isMuted: false, canChange: false), sortAscending: sortAscendingValue, recordingStartTimestamp: nil, title: nil, diff --git a/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift b/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift index a5d034c976..532e5df540 100644 --- a/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift @@ -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 timeinfo: tm = tm() localtime_r(&t, &timeinfo) @@ -178,7 +178,7 @@ public func humanReadableStringForTimestamp(strings: PresentationStrings, dateTi } 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 if dayDifference == 0 { day = .today diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 614bece326..008d2d066a 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -448,11 +448,11 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor) case let .groupPhoneCall(_, _, scheduleDate, duration): if let scheduleDate = scheduleDate { - let timeString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate) 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) } else { + let timeString = humanReadableStringForTimestamp(strings: strings, dateTimeFormat: dateTimeFormat, timestamp: scheduleDate) let attributePeerIds: [(Int, PeerId?)] = [(0, message.author?.id)] let titleString = strings.Notification_VoiceChatScheduled(authorName, timeString) attributedString = addAttributesToStringWithRanges(titleString, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: attributePeerIds))