/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/timer.h" class PeerData; class ApiWrap; namespace Data { struct LastSpokeTimes { crl::time anything = 0; crl::time voice = 0; }; struct GroupCallParticipant { not_null peer; TimeId date = 0; TimeId lastActive = 0; uint64 raisedHandRating = 0; uint32 ssrc = 0; int volume = 0; bool applyVolumeFromMin = true; bool sounding = false; bool speaking = false; bool muted = false; bool mutedByMe = false; bool canSelfUnmute = false; bool onlyMinLoaded = false; }; class GroupCall final { public: GroupCall(not_null peer, uint64 id, uint64 accessHash); ~GroupCall(); [[nodiscard]] uint64 id() const; [[nodiscard]] not_null peer() const; [[nodiscard]] MTPInputGroupCall input() const; [[nodiscard]] QString title() const { return _title.current(); } [[nodiscard]] rpl::producer titleValue() const { return _title.value(); } void setTitle(const QString &title) { _title = title; } [[nodiscard]] TimeId recordStartDate() const { return _recordStartDate.current(); } [[nodiscard]] rpl::producer recordStartDateValue() const { return _recordStartDate.value(); } [[nodiscard]] rpl::producer recordStartDateChanges() const { return _recordStartDate.changes(); } void setPeer(not_null peer); using Participant = GroupCallParticipant; struct ParticipantUpdate { std::optional was; std::optional now; }; static constexpr auto kSoundStatusKeptFor = crl::time(350); [[nodiscard]] auto participants() const -> const std::vector &; void requestParticipants(); [[nodiscard]] bool participantsLoaded() const; [[nodiscard]] PeerData *participantPeerBySsrc(uint32 ssrc) const; [[nodiscard]] rpl::producer<> participantsSliceAdded(); [[nodiscard]] rpl::producer participantUpdated() const; void applyUpdate(const MTPGroupCall &update); void applyUpdate(const MTPDupdateGroupCallParticipants &update); void applyUpdateChecked( const MTPDupdateGroupCallParticipants &update); void applyLastSpoke(uint32 ssrc, LastSpokeTimes when, crl::time now); void applyActiveUpdate( PeerId participantPeerId, LastSpokeTimes when, PeerData *participantPeerLoaded); void resolveParticipants(const base::flat_set &ssrcs); [[nodiscard]] int fullCount() const; [[nodiscard]] rpl::producer fullCountValue() const; void setInCall(); void reload(); void setJoinMutedLocally(bool muted); [[nodiscard]] bool joinMuted() const; [[nodiscard]] bool canChangeJoinMuted() const; private: enum class ApplySliceSource { SliceLoaded, UnknownLoaded, UpdateReceived, }; [[nodiscard]] ApiWrap &api() const; [[nodiscard]] bool inCall() const; void applyCall(const MTPGroupCall &call, bool force); void applyParticipantsSlice( const QVector &list, ApplySliceSource sliceSource); void requestUnknownParticipants(); void changePeerEmptyCallFlag(); void checkFinishSpeakingByActive(); const uint64 _id = 0; const uint64 _accessHash = 0; not_null _peer; int _version = 0; mtpRequestId _participantsRequestId = 0; mtpRequestId _reloadRequestId = 0; rpl::variable _title; std::vector _participants; base::flat_map> _participantPeerBySsrc; base::flat_map, crl::time> _speakingByActiveFinishes; base::Timer _speakingByActiveFinishTimer; QString _nextOffset; rpl::variable _fullCount = 0; rpl::variable _recordStartDate = 0; base::flat_map _unknownSpokenSsrcs; base::flat_map _unknownSpokenPeerIds; mtpRequestId _unknownParticipantPeersRequestId = 0; rpl::event_stream _participantUpdates; rpl::event_stream<> _participantsSliceAdded; bool _joinMuted = false; bool _canChangeJoinMuted = true; bool _allReceived = false; }; } // namespace Data