2020-07-06 09:58:18 +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 "api/api_common.h"
|
|
|
|
#include "base/timer.h"
|
|
|
|
|
|
|
|
class History;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
|
|
|
enum class SendProgressType {
|
|
|
|
Typing,
|
|
|
|
RecordVideo,
|
|
|
|
UploadVideo,
|
|
|
|
RecordVoice,
|
|
|
|
UploadVoice,
|
|
|
|
RecordRound,
|
|
|
|
UploadRound,
|
|
|
|
UploadPhoto,
|
|
|
|
UploadFile,
|
|
|
|
ChooseLocation,
|
|
|
|
ChooseContact,
|
|
|
|
PlayGame,
|
2020-11-30 15:51:04 +00:00
|
|
|
Speaking,
|
2020-07-06 09:58:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SendProgress {
|
|
|
|
SendProgress(
|
|
|
|
SendProgressType type,
|
|
|
|
crl::time until,
|
|
|
|
int progress = 0)
|
|
|
|
: type(type)
|
|
|
|
, until(until)
|
|
|
|
, progress(progress) {
|
|
|
|
}
|
|
|
|
SendProgressType type = SendProgressType::Typing;
|
|
|
|
crl::time until = 0;
|
|
|
|
int progress = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SendProgressManager final {
|
|
|
|
public:
|
|
|
|
SendProgressManager(not_null<Main::Session*> session);
|
|
|
|
|
|
|
|
void update(
|
|
|
|
not_null<History*> history,
|
|
|
|
SendProgressType type,
|
2020-09-18 11:50:47 +00:00
|
|
|
int progress = 0);
|
|
|
|
void update(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId topMsgId,
|
|
|
|
SendProgressType type,
|
|
|
|
int progress = 0);
|
|
|
|
void cancel(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId topMsgId,
|
|
|
|
SendProgressType type);
|
2020-07-06 09:58:18 +00:00
|
|
|
void cancel(
|
|
|
|
not_null<History*> history,
|
|
|
|
SendProgressType type);
|
|
|
|
void cancelTyping(not_null<History*> history);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Key {
|
|
|
|
not_null<History*> history;
|
2020-09-18 11:50:47 +00:00
|
|
|
MsgId topMsgId = 0;
|
2020-07-06 09:58:18 +00:00
|
|
|
SendProgressType type = SendProgressType();
|
|
|
|
|
|
|
|
inline bool operator<(const Key &other) const {
|
|
|
|
return (history < other.history)
|
2020-09-18 11:50:47 +00:00
|
|
|
|| (history == other.history && topMsgId < other.topMsgId)
|
|
|
|
|| (history == other.history
|
|
|
|
&& topMsgId == other.topMsgId
|
|
|
|
&& type < other.type);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-18 11:50:47 +00:00
|
|
|
bool updated(const Key &key, bool doing);
|
|
|
|
|
|
|
|
void send(const Key &key, int progress);
|
2020-07-06 09:58:18 +00:00
|
|
|
void done(const MTPBool &result, mtpRequestId requestId);
|
|
|
|
|
2020-10-23 14:28:11 +00:00
|
|
|
[[nodiscard]] bool skipRequest(const Key &key) const;
|
|
|
|
|
2020-07-06 09:58:18 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
base::flat_map<Key, mtpRequestId> _requests;
|
2020-09-18 11:50:47 +00:00
|
|
|
base::flat_map<Key, crl::time> _updated;
|
2020-07-06 09:58:18 +00:00
|
|
|
base::Timer _stopTypingTimer;
|
|
|
|
History *_stopTypingHistory = nullptr;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Api
|