2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 18:57:12 +00:00
tdesktop/Telegram/SourceFiles/data/data_group_call.h

287 lines
8.4 KiB
C
Raw Permalink Normal View History

2020-11-20 22:25:35 +03:00
/*
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;
2020-11-20 22:25:35 +03:00
2020-11-29 18:18:51 +03:00
class ApiWrap;
2021-04-15 17:55:32 +04:00
namespace Calls {
struct ParticipantVideoParams;
2021-04-15 17:55:32 +04:00
} // namespace Calls
namespace Main {
class Session;
} // namespace Main
2025-03-25 00:11:21 +05:00
namespace TdE2E {
struct ParticipantState;
2025-03-25 22:38:13 +05:00
struct UserId;
2025-03-25 00:11:21 +05:00
} // namespace TdE2E
2020-11-20 22:25:35 +03:00
namespace Data {
[[nodiscard]] const std::string &RtmpEndpointId();
struct LastSpokeTimes {
crl::time anything = 0;
crl::time voice = 0;
};
2021-03-08 11:57:00 +04:00
struct GroupCallParticipant {
not_null<PeerData*> peer;
std::shared_ptr<Calls::ParticipantVideoParams> videoParams;
2021-03-08 11:57:00 +04:00
TimeId date = 0;
TimeId lastActive = 0;
uint64 raisedHandRating = 0;
2021-03-08 11:57:00 +04:00
uint32 ssrc = 0;
int volume = 0;
bool sounding : 1 = false;
bool speaking : 1 = false;
bool additionalSounding : 1 = false;
bool additionalSpeaking : 1 = false;
bool muted : 1 = false;
bool mutedByMe : 1 = false;
bool canSelfUnmute : 1 = false;
bool onlyMinLoaded : 1 = false;
bool videoJoined = false;
2021-07-09 12:32:20 +03:00
bool applyVolumeFromMin = true;
[[nodiscard]] const std::string &cameraEndpoint() const;
[[nodiscard]] const std::string &screenEndpoint() const;
[[nodiscard]] bool cameraPaused() const;
[[nodiscard]] bool screenPaused() const;
2021-03-08 11:57:00 +04:00
};
2020-11-20 22:25:35 +03:00
class GroupCall final {
public:
2021-04-12 15:36:19 +04:00
GroupCall(
not_null<PeerData*> peer,
2021-10-25 00:33:53 +03:00
CallId id,
2025-03-24 21:58:06 +04:00
uint64 accessHash,
TimeId scheduleDate,
bool rtmp,
bool conference);
2020-11-24 14:56:46 +03:00
~GroupCall();
2020-11-20 22:25:35 +03:00
[[nodiscard]] Main::Session &session() const;
2021-10-25 00:33:53 +03:00
[[nodiscard]] CallId id() const;
[[nodiscard]] bool loaded() const;
[[nodiscard]] bool rtmp() const;
[[nodiscard]] bool canManage() const;
2022-02-28 13:52:49 +03:00
[[nodiscard]] bool listenersHidden() const;
2025-04-10 09:33:04 +04:00
[[nodiscard]] bool blockchainMayBeEmpty() const;
[[nodiscard]] not_null<PeerData*> peer() const;
2020-11-20 22:25:35 +03:00
[[nodiscard]] MTPInputGroupCall input() const;
2021-03-05 20:59:35 +04:00
[[nodiscard]] QString title() const {
return _title.current();
}
[[nodiscard]] rpl::producer<QString> titleValue() const {
return _title.value();
}
void setTitle(const QString &title) {
_title = title;
}
2021-03-09 13:27:17 +04:00
[[nodiscard]] TimeId recordStartDate() const {
2021-03-09 17:24:32 +04:00
return _recordStartDate.current();
}
[[nodiscard]] rpl::producer<TimeId> recordStartDateValue() const {
return _recordStartDate.value();
}
[[nodiscard]] rpl::producer<TimeId> recordStartDateChanges() const {
return _recordStartDate.changes();
2021-03-09 13:27:17 +04:00
}
[[nodiscard]] TimeId scheduleDate() const {
return _scheduleDate.current();
}
[[nodiscard]] rpl::producer<TimeId> scheduleDateValue() const {
return _scheduleDate.value();
}
[[nodiscard]] rpl::producer<TimeId> scheduleDateChanges() const {
return _scheduleDate.changes();
}
[[nodiscard]] bool scheduleStartSubscribed() const {
return _scheduleStartSubscribed.current();
}
[[nodiscard]] rpl::producer<bool> scheduleStartSubscribedValue() const {
return _scheduleStartSubscribed.value();
}
[[nodiscard]] int unmutedVideoLimit() const {
return _unmutedVideoLimit.current();
}
[[nodiscard]] bool recordVideo() const {
return _recordVideo.current();
}
2020-11-20 22:25:35 +03:00
void setPeer(not_null<PeerData*> peer);
2021-03-08 11:57:00 +04:00
using Participant = GroupCallParticipant;
struct ParticipantUpdate {
std::optional<Participant> was;
std::optional<Participant> now;
};
2020-11-20 22:25:35 +03:00
static constexpr auto kSoundStatusKeptFor = crl::time(1500);
2020-11-20 22:25:35 +03:00
[[nodiscard]] auto participants() const
-> const std::vector<Participant> &;
void requestParticipants();
[[nodiscard]] bool participantsLoaded() const;
[[nodiscard]] PeerData *participantPeerByAudioSsrc(uint32 ssrc) const;
2021-05-11 13:35:04 +04:00
[[nodiscard]] const Participant *participantByPeer(
not_null<PeerData*> peer) const;
[[nodiscard]] const Participant *participantByEndpoint(
const std::string &endpoint) const;
2020-11-20 22:25:35 +03:00
[[nodiscard]] rpl::producer<> participantsReloaded();
[[nodiscard]] auto participantUpdated() const
-> rpl::producer<ParticipantUpdate>;
[[nodiscard]] auto participantSpeaking() const
-> rpl::producer<not_null<Participant*>>;
void setParticipantsWithAccess(base::flat_set<UserId> list);
[[nodiscard]] auto participantsWithAccessCurrent() const
-> const base::flat_set<UserId> &;
[[nodiscard]] auto participantsWithAccessValue() const
-> rpl::producer<base::flat_set<UserId>>;
2025-03-28 23:04:14 +05:00
[[nodiscard]] auto staleParticipantIds() const
-> rpl::producer<base::flat_set<UserId>>;
void setParticipantsLoaded();
void checkStaleParticipants();
void enqueueUpdate(const MTPUpdate &update);
void applyLocalUpdate(
const MTPDupdateGroupCallParticipants &update);
void applyLastSpoke(uint32 ssrc, LastSpokeTimes when, crl::time now);
void applyActiveUpdate(
2021-03-03 19:29:33 +04:00
PeerId participantPeerId,
LastSpokeTimes when,
2021-03-03 19:29:33 +04:00
PeerData *participantPeerLoaded);
2020-11-24 14:56:46 +03:00
2021-03-08 11:57:00 +04:00
void resolveParticipants(const base::flat_set<uint32> &ssrcs);
[[nodiscard]] rpl::producer<
not_null<const base::flat_map<
uint32,
LastSpokeTimes>*>> participantsResolved() const {
return _participantsResolved.events();
}
2021-03-08 11:57:00 +04:00
2020-11-20 22:25:35 +03:00
[[nodiscard]] int fullCount() const;
[[nodiscard]] rpl::producer<int> fullCountValue() const;
2025-04-09 10:28:21 +04:00
[[nodiscard]] QString conferenceInviteLink() const;
2020-11-20 22:25:35 +03:00
void setInCall();
2020-11-24 14:56:46 +03:00
void reload();
void reloadIfStale();
void processFullCall(const MTPphone_GroupCall &call);
2020-11-24 14:56:46 +03:00
2020-11-28 19:18:51 +03:00
void setJoinMutedLocally(bool muted);
[[nodiscard]] bool joinMuted() const;
[[nodiscard]] bool canChangeJoinMuted() const;
[[nodiscard]] bool joinedToTop() const;
2020-11-28 19:18:51 +03:00
2020-11-20 22:25:35 +03:00
private:
2020-11-29 18:18:51 +03:00
enum class ApplySliceSource {
FullReloaded,
2020-11-29 18:18:51 +03:00
SliceLoaded,
UnknownLoaded,
UpdateReceived,
2021-04-15 17:55:32 +04:00
UpdateConstructed,
2020-11-29 18:18:51 +03:00
};
2021-03-18 22:46:52 +04:00
enum class QueuedType : uint8 {
VersionedParticipant,
Participant,
Call,
};
2020-11-29 18:18:51 +03:00
[[nodiscard]] ApiWrap &api() const;
2021-03-19 00:57:16 +04:00
void discard(const MTPDgroupCallDiscarded &data);
[[nodiscard]] bool inCall() const;
void applyParticipantsSlice(
const QVector<MTPGroupCallParticipant> &list,
2020-11-29 18:18:51 +03:00
ApplySliceSource sliceSource);
void requestUnknownParticipants();
void changePeerEmptyCallFlag();
void checkFinishSpeakingByActive();
void applyCallFields(const MTPDgroupCall &data);
2021-03-18 22:46:52 +04:00
void applyEnqueuedUpdate(const MTPUpdate &update);
void setServerParticipantsCount(int count);
void computeParticipantsCount();
2025-04-09 14:18:14 +04:00
void processQueuedUpdates(bool initial = false);
void processFullCallUsersChats(const MTPphone_GroupCall &call);
void processFullCallFields(const MTPphone_GroupCall &call);
[[nodiscard]] bool requestParticipantsAfterReload(
const MTPphone_GroupCall &call) const;
[[nodiscard]] bool processSavedFullCall();
void finishParticipantsSliceRequest();
2021-05-11 13:35:04 +04:00
[[nodiscard]] Participant *findParticipant(not_null<PeerData*> peer);
2020-11-24 14:56:46 +03:00
2021-10-25 00:33:53 +03:00
const CallId _id = 0;
2025-03-24 21:58:06 +04:00
const uint64 _accessHash = 0;
2020-11-20 22:25:35 +03:00
not_null<PeerData*> _peer;
2020-11-20 22:25:35 +03:00
int _version = 0;
mtpRequestId _participantsRequestId = 0;
2020-11-24 14:56:46 +03:00
mtpRequestId _reloadRequestId = 0;
crl::time _reloadLastFinished = 0;
2021-03-05 20:59:35 +04:00
rpl::variable<QString> _title;
2025-04-09 10:28:21 +04:00
QString _conferenceInviteLink;
2020-11-20 22:25:35 +03:00
2021-03-18 22:46:52 +04:00
base::flat_multi_map<
std::pair<int, QueuedType>,
MTPUpdate> _queuedUpdates;
base::Timer _reloadByQueuedUpdatesTimer;
std::optional<MTPphone_GroupCall> _savedFull;
2020-11-20 22:25:35 +03:00
std::vector<Participant> _participants;
base::flat_map<uint32, not_null<PeerData*>> _participantPeerByAudioSsrc;
2021-03-03 19:29:33 +04:00
base::flat_map<not_null<PeerData*>, crl::time> _speakingByActiveFinishes;
base::Timer _speakingByActiveFinishTimer;
2020-11-26 14:04:00 +03:00
QString _nextOffset;
int _serverParticipantsCount = 0;
rpl::variable<int> _fullCount = 0;
rpl::variable<int> _unmutedVideoLimit = 0;
rpl::variable<bool> _recordVideo = 0;
2021-03-09 17:24:32 +04:00
rpl::variable<TimeId> _recordStartDate = 0;
rpl::variable<TimeId> _scheduleDate = 0;
rpl::variable<bool> _scheduleStartSubscribed = false;
base::flat_map<uint32, LastSpokeTimes> _unknownSpokenSsrcs;
2021-03-03 19:29:33 +04:00
base::flat_map<PeerId, LastSpokeTimes> _unknownSpokenPeerIds;
rpl::event_stream<
not_null<const base::flat_map<
uint32,
LastSpokeTimes>*>> _participantsResolved;
2021-03-03 19:29:33 +04:00
mtpRequestId _unknownParticipantPeersRequestId = 0;
2020-11-29 18:18:51 +03:00
rpl::event_stream<ParticipantUpdate> _participantUpdates;
rpl::event_stream<not_null<Participant*>> _participantSpeaking;
rpl::event_stream<> _participantsReloaded;
rpl::variable<base::flat_set<UserId>> _participantsWithAccess;
2025-03-28 23:04:14 +05:00
rpl::event_stream<base::flat_set<UserId>> _staleParticipantIds;
rpl::lifetime _checkStaleLifetime;
bool _creator : 1 = false;
bool _joinMuted : 1 = false;
bool _canChangeJoinMuted : 1 = true;
bool _allParticipantsLoaded : 1 = false;
bool _joinedToTop : 1 = false;
bool _applyingQueuedUpdates : 1 = false;
bool _rtmp : 1 = false;
bool _conference : 1 = false;
bool _listenersHidden : 1 = false;
2020-11-20 22:25:35 +03:00
};
} // namespace Data