mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Start group call bar in HistoryWidget.
This commit is contained in:
@@ -86,9 +86,10 @@ struct PeerUpdate {
|
||||
ChannelLinkedChat = (1 << 27),
|
||||
ChannelLocation = (1 << 28),
|
||||
Slowmode = (1 << 29),
|
||||
GroupCall = (1 << 30),
|
||||
|
||||
// For iteration
|
||||
LastUsedBit = (1 << 29),
|
||||
LastUsedBit = (1 << 30),
|
||||
};
|
||||
using Flags = base::flags<Flag>;
|
||||
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
||||
|
@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_folder.h"
|
||||
#include "data/data_location.h"
|
||||
#include "data/data_histories.h"
|
||||
#include "data/data_group_call.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "history/history.h"
|
||||
#include "main/main_session.h"
|
||||
@@ -671,6 +672,32 @@ void ChannelData::privateErrorReceived() {
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelData::setCall(const MTPInputGroupCall &call) {
|
||||
call.match([&](const MTPDinputGroupCall &data) {
|
||||
if (_call && _call->id() == data.vid().v) {
|
||||
return;
|
||||
} else if (!_call && !data.vid().v) {
|
||||
return;
|
||||
} else if (!data.vid().v) {
|
||||
clearCall();
|
||||
return;
|
||||
}
|
||||
_call = std::make_unique<Data::GroupCall>(
|
||||
this,
|
||||
data.vid().v,
|
||||
data.vaccess_hash().v);
|
||||
session().changes().peerUpdated(this, UpdateFlag::GroupCall);
|
||||
});
|
||||
}
|
||||
|
||||
void ChannelData::clearCall() {
|
||||
if (!_call) {
|
||||
return;
|
||||
}
|
||||
_call = nullptr;
|
||||
session().changes().peerUpdated(this, UpdateFlag::GroupCall);
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
|
||||
void ApplyMigration(
|
||||
@@ -702,6 +729,12 @@ void ApplyChannelUpdate(
|
||||
auto canViewMembers = channel->canViewMembers();
|
||||
auto canEditStickers = channel->canEditStickers();
|
||||
|
||||
if (const auto call = update.vcall()) {
|
||||
channel->setCall(*call);
|
||||
} else {
|
||||
channel->clearCall();
|
||||
}
|
||||
|
||||
channel->setFullFlags(update.vflags().v);
|
||||
channel->setUserpicPhoto(update.vchat_photo());
|
||||
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
||||
|
@@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_pts_waiter.h"
|
||||
#include "data/data_location.h"
|
||||
|
||||
namespace Data {
|
||||
class GroupCall;
|
||||
} // namespace Data
|
||||
|
||||
struct ChannelLocation {
|
||||
QString address;
|
||||
Data::LocationPoint point;
|
||||
@@ -393,6 +397,12 @@ public:
|
||||
[[nodiscard]] QString invitePeekHash() const;
|
||||
void privateErrorReceived();
|
||||
|
||||
[[nodiscard]] Data::GroupCall *call() const {
|
||||
return _call.get();
|
||||
}
|
||||
void setCall(const MTPInputGroupCall &call);
|
||||
void clearCall();
|
||||
|
||||
// Still public data members.
|
||||
uint64 access = 0;
|
||||
|
||||
@@ -439,6 +449,8 @@ private:
|
||||
QString _inviteLink;
|
||||
std::optional<ChannelData*> _linkedChat;
|
||||
|
||||
std::unique_ptr<Data::GroupCall> _call;
|
||||
|
||||
int _slowmodeSeconds = 0;
|
||||
TimeId _slowmodeLastMessage = 0;
|
||||
|
||||
|
115
Telegram/SourceFiles/data/data_group_call.cpp
Normal file
115
Telegram/SourceFiles/data/data_group_call.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#include "data/data_group_call.h"
|
||||
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "apiwrap.h"
|
||||
|
||||
namespace Data {
|
||||
namespace {
|
||||
|
||||
constexpr auto kRequestPerPage = 30;
|
||||
|
||||
} // namespace
|
||||
|
||||
GroupCall::GroupCall(
|
||||
not_null<ChannelData*> channel,
|
||||
uint64 id,
|
||||
uint64 accessHash)
|
||||
: _channel(channel)
|
||||
, _id(id)
|
||||
, _accessHash(accessHash) {
|
||||
}
|
||||
|
||||
uint64 GroupCall::id() const {
|
||||
return _id;
|
||||
}
|
||||
|
||||
MTPInputGroupCall GroupCall::input() const {
|
||||
return MTP_inputGroupCall(MTP_long(_id), MTP_long(_accessHash));
|
||||
}
|
||||
|
||||
auto GroupCall::participants() const
|
||||
-> const std::vector<Participant> & {
|
||||
return _participants;
|
||||
}
|
||||
|
||||
void GroupCall::requestParticipants() {
|
||||
if (_participantsRequestId) {
|
||||
return;
|
||||
} else if (_participants.size() >= _fullCount && _allReceived) {
|
||||
return;
|
||||
}
|
||||
const auto requestFromDate = (_allReceived || _participants.empty())
|
||||
? TimeId(0)
|
||||
: _participants.back().date;
|
||||
auto &api = _channel->session().api();
|
||||
_participantsRequestId = api.request(MTPphone_GetGroupParticipants(
|
||||
input(),
|
||||
MTP_int(requestFromDate),
|
||||
MTP_int(kRequestPerPage)
|
||||
)).done([=](const MTPphone_GroupParticipants &result) {
|
||||
result.match([&](const MTPDphone_groupParticipants &data) {
|
||||
_fullCount = data.vcount().v;
|
||||
_channel->owner().processUsers(data.vusers());
|
||||
for (const auto &p : data.vparticipants().v) {
|
||||
p.match([&](const MTPDgroupCallParticipant &data) {
|
||||
const auto userId = data.vuser_id().v;
|
||||
const auto user = _channel->owner().user(userId);
|
||||
const auto value = Participant{
|
||||
.user = user,
|
||||
.date = data.vdate().v,
|
||||
.source = data.vsource().v,
|
||||
.muted = data.is_muted(),
|
||||
.canSelfUnmute = data.is_can_self_unmute(),
|
||||
.left = data.is_left()
|
||||
};
|
||||
const auto i = ranges::find(
|
||||
_participants,
|
||||
user,
|
||||
&Participant::user);
|
||||
if (i == end(_participants)) {
|
||||
_participants.push_back(value);
|
||||
} else {
|
||||
*i = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!_allReceived
|
||||
&& (data.vparticipants().v.size() < kRequestPerPage)) {
|
||||
_allReceived = true;
|
||||
}
|
||||
if (_allReceived) {
|
||||
_fullCount = _participants.size();
|
||||
}
|
||||
});
|
||||
ranges::sort(_participants, std::greater<>(), &Participant::date);
|
||||
_channel->session().changes().peerUpdated(
|
||||
_channel,
|
||||
PeerUpdate::Flag::GroupCall);
|
||||
}).fail([=](const RPCError &error) {
|
||||
_allReceived = true;
|
||||
_fullCount = _participants.size();
|
||||
_channel->session().changes().peerUpdated(
|
||||
_channel,
|
||||
PeerUpdate::Flag::GroupCall);
|
||||
}).send();
|
||||
}
|
||||
|
||||
int GroupCall::fullCount() const {
|
||||
return _fullCount;
|
||||
}
|
||||
|
||||
bool GroupCall::participantsLoaded() const {
|
||||
return _allReceived;
|
||||
}
|
||||
|
||||
} // namespace Data
|
54
Telegram/SourceFiles/data/data_group_call.h
Normal file
54
Telegram/SourceFiles/data/data_group_call.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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
|
||||
|
||||
class UserData;
|
||||
class ChannelData;
|
||||
|
||||
namespace Data {
|
||||
|
||||
class GroupCall final {
|
||||
public:
|
||||
GroupCall(not_null<ChannelData*> channel, uint64 id, uint64 accessHash);
|
||||
|
||||
[[nodiscard]] uint64 id() const;
|
||||
[[nodiscard]] MTPInputGroupCall input() const;
|
||||
|
||||
struct Participant {
|
||||
not_null<UserData*> user;
|
||||
TimeId date = 0;
|
||||
int source = 0;
|
||||
bool muted = false;
|
||||
bool canSelfUnmute = false;
|
||||
bool left = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto participants() const
|
||||
-> const std::vector<Participant> &;
|
||||
void requestParticipants();
|
||||
[[nodiscard]] bool participantsLoaded() const;
|
||||
|
||||
[[nodiscard]] int fullCount() const;
|
||||
|
||||
private:
|
||||
const not_null<ChannelData*> _channel;
|
||||
const uint64 _id = 0;
|
||||
const uint64 _accessHash = 0;
|
||||
|
||||
int _version = 0;
|
||||
UserId _adminId = 0;
|
||||
uint64 _reflectorId = 0;
|
||||
mtpRequestId _participantsRequestId = 0;
|
||||
|
||||
std::vector<Participant> _participants;
|
||||
int _fullCount = 0;
|
||||
bool _allReceived = false;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Data
|
Reference in New Issue
Block a user