tdesktop/Telegram/SourceFiles/support/support_helper.h

112 lines
2.8 KiB
C
Raw Normal View History

/*
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 "base/timer.h"
#include "support/support_templates.h"
2018-11-20 13:34:07 +00:00
#include "mtproto/sender.h"
class History;
2019-07-24 11:45:24 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Support {
struct UserInfo {
QString author;
TimeId date = 0;
TextWithEntities text;
};
inline bool operator==(const UserInfo &a, const UserInfo &b) {
return (a.author == b.author)
&& (a.date == b.date)
&& (a.text == b.text);
}
inline bool operator!=(const UserInfo &a, const UserInfo &b) {
return !(a == b);
}
2018-11-20 13:34:07 +00:00
class Helper : private MTP::Sender {
public:
2019-07-24 11:45:24 +00:00
explicit Helper(not_null<Main::Session*> session);
2019-07-24 11:45:24 +00:00
static std::unique_ptr<Helper> Create(not_null<Main::Session*> session);
2019-01-03 12:36:01 +00:00
void registerWindow(not_null<Window::SessionController*> controller);
void cloudDraftChanged(not_null<History*> history);
void chatOccupiedUpdated(not_null<History*> history);
2018-11-20 13:34:07 +00:00
bool isOccupiedByMe(History *history) const;
bool isOccupiedBySomeone(History *history) const;
void refreshInfo(not_null<UserData*> user);
rpl::producer<UserInfo> infoValue(not_null<UserData*> user) const;
rpl::producer<QString> infoLabelValue(not_null<UserData*> user) const;
rpl::producer<TextWithEntities> infoTextValue(
not_null<UserData*> user) const;
UserInfo infoCurrent(not_null<UserData*> user) const;
void editInfo(not_null<UserData*> user);
Templates &templates();
private:
struct SavingInfo {
TextWithEntities data;
mtpRequestId requestId = 0;
};
void checkOccupiedChats();
void updateOccupiedHistory(
not_null<Window::SessionController*> controller,
History *history);
2018-11-20 13:34:07 +00:00
void setSupportName(const QString &name);
void occupyIfNotYet();
void occupyInDraft();
void reoccupy();
void applyInfo(
not_null<UserData*> user,
const MTPhelp_UserInfo &result);
void showEditInfoBox(not_null<UserData*> user);
void saveInfo(
not_null<UserData*> user,
TextWithEntities text,
Fn<void(bool success)> done);
2019-07-24 11:45:24 +00:00
not_null<Main::Session*> _session;
Templates _templates;
2018-11-20 13:34:07 +00:00
QString _supportName;
QString _supportNameNormalized;
History *_occupiedHistory = nullptr;
base::Timer _reoccupyTimer;
base::Timer _checkOccupiedTimer;
base::flat_map<not_null<History*>, TimeId> _occupiedChats;
base::flat_map<not_null<UserData*>, UserInfo> _userInformation;
base::flat_set<not_null<UserData*>> _userInfoEditPending;
base::flat_map<not_null<UserData*>, SavingInfo> _userInfoSaving;
rpl::lifetime _lifetime;
};
2018-11-20 13:34:07 +00:00
QString ChatOccupiedString(not_null<History*> history);
QString InterpretSendPath(const QString &path);
} // namespace Support