2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Support voice chats in legacy groups, with migration.

This commit is contained in:
John Preston
2020-12-14 16:52:18 +04:00
parent cd3b989e70
commit 1b624d67b8
30 changed files with 584 additions and 389 deletions

View File

@@ -237,18 +237,16 @@ Updates::Updates(not_null<Main::Session*> session)
using namespace rpl::mappers;
base::ObservableViewer(
api().fullPeerUpdated()
) | rpl::map([=](not_null<PeerData*> peer) {
return peer->asChannel();
}) | rpl::filter(
_1 != nullptr
) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
if (const auto users = _pendingSpeakingCallMembers.take(channel)) {
if (const auto call = channel->call()) {
) | rpl::filter([](not_null<PeerData*> peer) {
return peer->isChat() || peer->isMegagroup();
}) | rpl::start_with_next([=](not_null<PeerData*> peer) {
if (const auto users = _pendingSpeakingCallMembers.take(peer)) {
if (const auto call = peer->groupCall()) {
for (const auto [userId, when] : *users) {
call->applyActiveUpdate(
userId,
when,
channel->owner().userLoaded(userId));
peer->owner().userLoaded(userId));
}
}
}
@@ -911,6 +909,52 @@ bool Updates::isQuitPrevent() {
updateOnline();
return true;
}
void Updates::handleSendActionUpdate(
PeerId peerId,
MsgId rootId,
UserId userId,
const MTPSendMessageAction &action) {
const auto history = session().data().historyLoaded(peerId);
if (!history) {
return;
}
const auto peer = history->peer;
const auto user = (userId == session().userId())
? session().user().get()
: session().data().userLoaded(userId);
const auto isSpeakingInCall = (action.type()
== mtpc_speakingInGroupCallAction);
if (isSpeakingInCall) {
const auto call = peer->groupCall();
const auto now = crl::now();
if (call) {
call->applyActiveUpdate(userId, now, user);
} else {
const auto chat = peer->asChat();
const auto channel = peer->asChannel();
const auto active = chat
? (chat->flags() & MTPDchat::Flag::f_call_active)
: (channel->flags() & MTPDchannel::Flag::f_call_active);
if (active) {
_pendingSpeakingCallMembers.emplace(
channel).first->second[userId] = now;
session().api().requestFullPeer(channel);
}
}
}
if (!user || user->isSelf()) {
return;
}
const auto when = requestingDifference()
? 0
: base::unixtime::now();
session().data().registerSendAction(
history,
rootId,
user,
action,
when);
}
void Updates::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
switch (updates.type()) {
@@ -1601,75 +1645,29 @@ void Updates::feedUpdate(const MTPUpdate &update) {
case mtpc_updateUserTyping: {
auto &d = update.c_updateUserTyping();
const auto userId = peerFromUser(d.vuser_id());
const auto history = session().data().historyLoaded(userId);
const auto user = session().data().userLoaded(d.vuser_id().v);
if (history && user) {
const auto when = requestingDifference() ? 0 : base::unixtime::now();
session().data().registerSendAction(
history,
MsgId(),
user,
d.vaction(),
when);
}
handleSendActionUpdate(
peerFromUser(d.vuser_id()),
0,
d.vuser_id().v,
d.vaction());
} break;
case mtpc_updateChatUserTyping: {
auto &d = update.c_updateChatUserTyping();
const auto history = session().data().historyLoaded(
peerFromChat(d.vchat_id()));
const auto user = (d.vuser_id().v == session().userId())
? nullptr
: session().data().userLoaded(d.vuser_id().v);
if (history && user) {
const auto when = requestingDifference() ? 0 : base::unixtime::now();
session().data().registerSendAction(
history,
MsgId(),
user,
d.vaction(),
when);
}
handleSendActionUpdate(
peerFromChat(d.vchat_id()),
0,
d.vuser_id().v,
d.vaction());
} break;
case mtpc_updateChannelUserTyping: {
const auto &d = update.c_updateChannelUserTyping();
const auto history = session().data().historyLoaded(
peerFromChannel(d.vchannel_id()));
if (history) {
const auto userId = d.vuser_id().v;
const auto user = (userId == session().userId())
? session().user().get()
: session().data().userLoaded(userId);
const auto isSpeakingInCall = (d.vaction().type()
== mtpc_speakingInGroupCallAction);
if (isSpeakingInCall) {
const auto channel = history->peer->asChannel();
const auto call = channel->call();
const auto now = crl::now();
if (call) {
call->applyActiveUpdate(userId, now, user);
} else if (channel->flags()
& MTPDchannel::Flag::f_call_active) {
_pendingSpeakingCallMembers.emplace(
channel).first->second[userId] = now;
session().api().requestFullPeer(channel);
}
}
if (user && !user->isSelf()) {
const auto when = requestingDifference()
? 0
: base::unixtime::now();
const auto rootId = d.vtop_msg_id().value_or_empty();
session().data().registerSendAction(
history,
rootId,
user,
d.vaction(),
when);
}
}
handleSendActionUpdate(
peerFromChannel(d.vchannel_id()),
d.vtop_msg_id().value_or_empty(),
d.vuser_id().v,
d.vaction());
} break;
case mtpc_updateChatParticipants: {

View File

@@ -122,6 +122,12 @@ private:
base::flat_map<not_null<ChannelData*>, crl::time> &whenMap,
crl::time &curTime);
void handleSendActionUpdate(
PeerId peerId,
MsgId rootId,
UserId userId,
const MTPSendMessageAction &action);
const not_null<Main::Session*> _session;
int32 _updatesDate = 0;
@@ -161,7 +167,7 @@ private:
base::flat_map<int, ActiveChatTracker> _activeChats;
base::flat_map<
not_null<ChannelData*>,
not_null<PeerData*>,
base::flat_map<UserId, crl::time>> _pendingSpeakingCallMembers;
mtpRequestId _onlineRequest = 0;