Don't send typings to bots and offline users.

This commit is contained in:
John Preston 2020-10-23 17:28:11 +03:00
parent 53ac4c00ad
commit 0690d14f1b
2 changed files with 20 additions and 0 deletions

View file

@ -10,6 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "history/history.h"
#include "data/data_peer.h"
#include "data/data_user.h"
#include "base/unixtime.h"
#include "data/data_peer_values.h"
#include "apiwrap.h"
namespace Api {
@ -98,6 +101,9 @@ bool SendProgressManager::updated(const Key &key, bool doing) {
}
void SendProgressManager::send(const Key &key, int progress) {
if (skipRequest(key)) {
return;
}
using Type = SendProgressType;
const auto action = [&]() -> MTPsendMessageAction {
const auto p = MTP_int(progress);
@ -135,6 +141,18 @@ void SendProgressManager::send(const Key &key, int progress) {
}
}
bool SendProgressManager::skipRequest(const Key &key) const {
const auto user = key.history->peer->asUser();
if (!user) {
return false;
} else if (user->isSelf()) {
return true;
} else if (user->isBot() && !user->isSupport()) {
return true;
}
return !Data::OnlineTextActive(user->onlineTill, base::unixtime::now());
}
void SendProgressManager::done(
const MTPBool &result,
mtpRequestId requestId) {

View file

@ -90,6 +90,8 @@ private:
void send(const Key &key, int progress);
void done(const MTPBool &result, mtpRequestId requestId);
[[nodiscard]] bool skipRequest(const Key &key) const;
const not_null<Main::Session*> _session;
base::flat_map<Key, mtpRequestId> _requests;
base::flat_map<Key, crl::time> _updated;