2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-24 11:17:10 +00:00
tdesktop/Telegram/SourceFiles/data/data_group_call.h

130 lines
3.4 KiB
C
Raw 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;
2020-11-20 22:25:35 +03:00
namespace Data {
struct LastSpokeTimes {
crl::time anything = 0;
crl::time voice = 0;
};
2020-11-20 22:25:35 +03:00
class GroupCall final {
public:
GroupCall(not_null<PeerData*> peer, uint64 id, uint64 accessHash);
2020-11-24 14:56:46 +03:00
~GroupCall();
2020-11-20 22:25:35 +03:00
[[nodiscard]] uint64 id() const;
[[nodiscard]] not_null<PeerData*> peer() const;
2020-11-20 22:25:35 +03:00
[[nodiscard]] MTPInputGroupCall input() const;
void setPeer(not_null<PeerData*> peer);
2020-11-20 22:25:35 +03:00
struct Participant {
2021-03-03 19:29:33 +04:00
not_null<PeerData*> peer;
2020-11-20 22:25:35 +03:00
TimeId date = 0;
TimeId lastActive = 0;
uint32 ssrc = 0;
int volume = 0;
bool applyVolumeFromMin = true;
bool sounding = false;
bool speaking = false;
2020-11-20 22:25:35 +03:00
bool muted = false;
bool mutedByMe = false;
2020-11-20 22:25:35 +03:00
bool canSelfUnmute = false;
bool onlyMinLoaded = false;
2020-11-20 22:25:35 +03:00
};
struct ParticipantUpdate {
std::optional<Participant> was;
std::optional<Participant> now;
};
2020-11-20 22:25:35 +03:00
static constexpr auto kSoundStatusKeptFor = crl::time(350);
2020-11-20 22:25:35 +03:00
[[nodiscard]] auto participants() const
-> const std::vector<Participant> &;
void requestParticipants();
[[nodiscard]] bool participantsLoaded() const;
[[nodiscard]] rpl::producer<> participantsSliceAdded();
[[nodiscard]] rpl::producer<ParticipantUpdate> participantUpdated() const;
2020-11-24 14:56:46 +03:00
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(
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
2020-11-20 22:25:35 +03:00
[[nodiscard]] int fullCount() const;
[[nodiscard]] rpl::producer<int> fullCountValue() const;
2020-11-20 22:25:35 +03:00
void setInCall();
2020-11-24 14:56:46 +03:00
void reload();
2020-11-28 19:18:51 +03:00
void setJoinMutedLocally(bool muted);
[[nodiscard]] bool joinMuted() const;
[[nodiscard]] bool canChangeJoinMuted() const;
2020-11-20 22:25:35 +03:00
private:
2020-11-29 18:18:51 +03:00
enum class ApplySliceSource {
SliceLoaded,
UnknownLoaded,
UpdateReceived,
};
[[nodiscard]] ApiWrap &api() const;
[[nodiscard]] bool inCall() const;
2020-11-24 14:56:46 +03:00
void applyCall(const MTPGroupCall &call, bool force);
void applyParticipantsSlice(
const QVector<MTPGroupCallParticipant> &list,
2020-11-29 18:18:51 +03:00
ApplySliceSource sliceSource);
void requestUnknownParticipants();
void changePeerEmptyCallFlag();
void checkFinishSpeakingByActive();
2021-03-05 15:36:07 +04:00
[[nodiscard]] PeerData *participantPeerBySsrc(uint32 ssrc) const;
2020-11-24 14:56:46 +03:00
2020-11-20 22:25:35 +03:00
const uint64 _id = 0;
const uint64 _accessHash = 0;
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;
2020-11-20 22:25:35 +03:00
std::vector<Participant> _participants;
2021-03-03 19:29:33 +04:00
base::flat_map<uint32, not_null<PeerData*>> _participantPeerBySsrc;
base::flat_map<not_null<PeerData*>, crl::time> _speakingByActiveFinishes;
base::Timer _speakingByActiveFinishTimer;
2020-11-26 14:04:00 +03:00
QString _nextOffset;
rpl::variable<int> _fullCount = 0;
base::flat_map<uint32, LastSpokeTimes> _unknownSpokenSsrcs;
2021-03-03 19:29:33 +04:00
base::flat_map<PeerId, LastSpokeTimes> _unknownSpokenPeerIds;
mtpRequestId _unknownParticipantPeersRequestId = 0;
2020-11-29 18:18:51 +03:00
rpl::event_stream<ParticipantUpdate> _participantUpdates;
rpl::event_stream<> _participantsSliceAdded;
2020-11-28 19:18:51 +03:00
bool _joinMuted = false;
bool _canChangeJoinMuted = true;
2020-11-20 22:25:35 +03:00
bool _allReceived = false;
};
} // namespace Data