/* 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, ChooseSticker, PlayGame, Speaking, }; 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 session); void update( not_null history, SendProgressType type, int progress = 0); void update( not_null history, MsgId topMsgId, SendProgressType type, int progress = 0); void cancel( not_null history, MsgId topMsgId, SendProgressType type); void cancel( not_null history, SendProgressType type); void cancelTyping(not_null history); private: struct Key { not_null history; MsgId topMsgId = 0; SendProgressType type = SendProgressType(); inline bool operator<(const Key &other) const { return (history < other.history) || (history == other.history && topMsgId < other.topMsgId) || (history == other.history && topMsgId == other.topMsgId && type < other.type); } }; bool updated(const Key &key, bool doing); void send(const Key &key, int progress); void done(const MTPBool &result, mtpRequestId requestId); [[nodiscard]] bool skipRequest(const Key &key) const; const not_null _session; base::flat_map _requests; base::flat_map _updated; base::Timer _stopTypingTimer; History *_stopTypingHistory = nullptr; }; } // namespace Api