tdesktop/Telegram/SourceFiles/data/data_group_call.h

121 lines
3.2 KiB
C
Raw Normal View History

2020-11-20 19:25:35 +00: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"
2020-11-20 19:25:35 +00:00
class UserData;
class ChannelData;
2020-11-29 15:18:51 +00:00
class ApiWrap;
2020-11-20 19:25:35 +00:00
namespace Data {
class GroupCall final {
public:
GroupCall(not_null<ChannelData*> channel, uint64 id, uint64 accessHash);
2020-11-24 11:56:46 +00:00
~GroupCall();
2020-11-20 19:25:35 +00:00
[[nodiscard]] uint64 id() const;
2020-11-24 11:56:46 +00:00
[[nodiscard]] not_null<ChannelData*> channel() const;
2020-11-20 19:25:35 +00:00
[[nodiscard]] MTPInputGroupCall input() const;
struct Participant {
not_null<UserData*> user;
TimeId date = 0;
TimeId lastActive = 0;
uint32 ssrc = 0;
bool speaking = false;
2020-11-20 19:25:35 +00:00
bool muted = false;
bool canSelfUnmute = false;
};
struct ParticipantUpdate {
std::optional<Participant> was;
std::optional<Participant> now;
};
2020-11-20 19:25:35 +00:00
2020-12-01 11:59:09 +00:00
static constexpr auto kSpeakStatusKeptFor = crl::time(350);
2020-11-20 19:25:35 +00:00
[[nodiscard]] auto participants() const
-> const std::vector<Participant> &;
void requestParticipants();
[[nodiscard]] bool participantsLoaded() const;
[[nodiscard]] UserData *userBySsrc(uint32 ssrc) const;
2020-11-20 19:25:35 +00:00
[[nodiscard]] rpl::producer<> participantsSliceAdded();
[[nodiscard]] rpl::producer<ParticipantUpdate> participantUpdated() const;
2020-11-24 11:56:46 +00:00
void applyUpdate(const MTPGroupCall &update);
void applyUpdate(const MTPDupdateGroupCallParticipants &update);
void applyUpdateChecked(
const MTPDupdateGroupCallParticipants &update);
void applyLastSpoke(uint32 ssrc, crl::time when, crl::time now);
void applyActiveUpdate(
UserId userId,
crl::time when,
UserData *userLoaded);
2020-11-24 11:56:46 +00:00
2020-11-20 19:25:35 +00:00
[[nodiscard]] int fullCount() const;
[[nodiscard]] rpl::producer<int> fullCountValue() const;
2020-11-20 19:25:35 +00:00
void setInCall();
2020-11-24 11:56:46 +00:00
void reload();
2020-11-28 16:18:51 +00:00
void setJoinMutedLocally(bool muted);
[[nodiscard]] bool joinMuted() const;
[[nodiscard]] bool canChangeJoinMuted() const;
2020-11-20 19:25:35 +00:00
private:
2020-11-29 15:18:51 +00:00
enum class ApplySliceSource {
SliceLoaded,
UnknownLoaded,
UpdateReceived,
};
[[nodiscard]] ApiWrap &api() const;
[[nodiscard]] bool inCall() const;
2020-11-24 11:56:46 +00:00
void applyCall(const MTPGroupCall &call, bool force);
void applyParticipantsSlice(
const QVector<MTPGroupCallParticipant> &list,
2020-11-29 15:18:51 +00:00
ApplySliceSource sliceSource);
void applyParticipantsMutes(
const MTPDupdateGroupCallParticipants &update);
void requestUnknownParticipants();
void changeChannelEmptyCallFlag();
void checkFinishSpeakingByActive();
2020-11-24 11:56:46 +00:00
2020-11-20 19:25:35 +00:00
const not_null<ChannelData*> _channel;
const uint64 _id = 0;
const uint64 _accessHash = 0;
int _version = 0;
mtpRequestId _participantsRequestId = 0;
2020-11-24 11:56:46 +00:00
mtpRequestId _reloadRequestId = 0;
2020-11-20 19:25:35 +00:00
std::vector<Participant> _participants;
base::flat_map<uint32, not_null<UserData*>> _userBySsrc;
base::flat_map<not_null<UserData*>, crl::time> _speakingByActiveFinishes;
base::Timer _speakingByActiveFinishTimer;
2020-11-26 11:04:00 +00:00
QString _nextOffset;
rpl::variable<int> _fullCount = 0;
base::flat_map<uint32, crl::time> _unknownSpokenSsrcs;
base::flat_map<UserId, crl::time> _unknownSpokenUids;
mtpRequestId _unknownUsersRequestId = 0;
2020-11-29 15:18:51 +00:00
rpl::event_stream<ParticipantUpdate> _participantUpdates;
rpl::event_stream<> _participantsSliceAdded;
2020-11-28 16:18:51 +00:00
bool _joinMuted = false;
bool _canChangeJoinMuted = true;
2020-11-20 19:25:35 +00:00
bool _allReceived = false;
};
} // namespace Data