2017-09-26 13:53:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-26 13:53:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-26 13:53:51 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data/data_peer.h"
|
2023-01-10 18:56:20 +00:00
|
|
|
#include "data/data_chat_participant_status.h"
|
2017-09-26 13:53:51 +00:00
|
|
|
|
2021-11-09 12:10:51 +00:00
|
|
|
enum class ImageRoundRadius;
|
|
|
|
|
2022-01-10 14:22:43 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2017-09-26 13:53:51 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2021-12-29 13:06:08 +00:00
|
|
|
struct Reaction;
|
2022-10-25 07:20:22 +00:00
|
|
|
class ForumTopic;
|
2024-01-15 07:36:17 +00:00
|
|
|
class LastseenStatus;
|
2021-12-29 13:06:08 +00:00
|
|
|
|
2017-09-27 12:04:19 +00:00
|
|
|
template <typename ChangeType, typename Error, typename Generator>
|
2017-09-26 13:53:51 +00:00
|
|
|
inline auto FlagsValueWithMask(
|
2017-09-27 12:04:19 +00:00
|
|
|
rpl::producer<ChangeType, Error, Generator> &&value,
|
2017-09-26 13:53:51 +00:00
|
|
|
typename ChangeType::Type mask) {
|
2017-12-22 07:05:20 +00:00
|
|
|
return std::move(
|
|
|
|
value
|
|
|
|
) | rpl::filter([mask](const ChangeType &change) {
|
|
|
|
return change.diff & mask;
|
|
|
|
}) | rpl::map([mask](const ChangeType &change) {
|
|
|
|
return change.value & mask;
|
|
|
|
});
|
2017-09-26 13:53:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 12:04:19 +00:00
|
|
|
template <typename ChangeType, typename Error, typename Generator>
|
2017-09-26 13:53:51 +00:00
|
|
|
inline auto SingleFlagValue(
|
2017-09-27 12:04:19 +00:00
|
|
|
rpl::producer<ChangeType, Error, Generator> &&value,
|
2017-09-26 13:53:51 +00:00
|
|
|
typename ChangeType::Enum flag) {
|
2017-12-22 07:05:20 +00:00
|
|
|
return FlagsValueWithMask(
|
|
|
|
std::move(value),
|
|
|
|
flag
|
2018-04-07 08:47:08 +00:00
|
|
|
) | rpl::map([](typename ChangeType::Type value) {
|
2017-12-22 07:05:20 +00:00
|
|
|
return !!value;
|
|
|
|
});
|
2017-09-26 13:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename ChangeType = typename PeerType::Flags::Change>
|
|
|
|
inline auto PeerFlagsValue(PeerType *peer) {
|
|
|
|
Expects(peer != nullptr);
|
2023-01-10 18:56:20 +00:00
|
|
|
|
2017-09-26 13:53:51 +00:00
|
|
|
return peer->flagsValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename ChangeType = typename PeerType::Flags::Change>
|
|
|
|
inline auto PeerFlagsValue(
|
|
|
|
PeerType *peer,
|
|
|
|
typename PeerType::Flags::Type mask) {
|
|
|
|
return FlagsValueWithMask(PeerFlagsValue(peer), mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename ChangeType = typename PeerType::Flags::Change>
|
|
|
|
inline auto PeerFlagValue(
|
|
|
|
PeerType *peer,
|
|
|
|
typename PeerType::Flags::Enum flag) {
|
|
|
|
return SingleFlagValue(PeerFlagsValue(peer), flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename = typename PeerType::FullFlags::Change>
|
|
|
|
inline auto PeerFullFlagsValue(PeerType *peer) {
|
|
|
|
Expects(peer != nullptr);
|
2020-10-22 07:53:56 +00:00
|
|
|
|
2017-10-22 17:06:57 +00:00
|
|
|
return peer->fullFlagsValue();
|
2017-09-26 13:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename = typename PeerType::FullFlags::Change>
|
|
|
|
inline auto PeerFullFlagsValue(
|
|
|
|
PeerType *peer,
|
|
|
|
typename PeerType::FullFlags::Type mask) {
|
|
|
|
return FlagsValueWithMask(PeerFullFlagsValue(peer), mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename PeerType,
|
|
|
|
typename = typename PeerType::FullFlags::Change>
|
|
|
|
inline auto PeerFullFlagValue(
|
|
|
|
PeerType *peer,
|
|
|
|
typename PeerType::FullFlags::Enum flag) {
|
|
|
|
return SingleFlagValue(PeerFullFlagsValue(peer), flag);
|
|
|
|
}
|
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
|
|
|
|
not_null<Data::Thread*> thread,
|
|
|
|
ChatRestrictions rights,
|
|
|
|
bool forbidInForums = true);
|
|
|
|
[[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
|
2022-10-25 07:20:22 +00:00
|
|
|
not_null<PeerData*> peer,
|
2023-01-10 18:56:20 +00:00
|
|
|
ChatRestrictions rights,
|
|
|
|
bool forbidInForums = true);
|
|
|
|
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendValue(
|
|
|
|
not_null<Thread*> thread,
|
|
|
|
ChatRestriction right,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOfValue(thread, right, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
ChatRestriction right,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOfValue(peer, right, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
|
|
|
|
not_null<Thread*> thread,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendValue(thread, ChatRestriction::SendOther, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendValue(peer, ChatRestriction::SendOther, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
|
|
|
|
not_null<Thread*> thread,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOfValue(thread, AllSendRestrictions(), forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOfValue(peer, AllSendRestrictions(), forbidInForums);
|
|
|
|
}
|
|
|
|
|
2022-05-18 13:37:24 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> CanPinMessagesValue(
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] rpl::producer<bool> CanManageGroupCallValue(
|
|
|
|
not_null<PeerData*> peer);
|
2022-05-20 15:28:50 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> PeerPremiumValue(not_null<PeerData*> peer);
|
2022-05-18 13:37:24 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> AmPremiumValue(
|
|
|
|
not_null<Main::Session*> session);
|
2017-09-26 13:53:51 +00:00
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
[[nodiscard]] TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now);
|
2024-01-15 07:36:17 +00:00
|
|
|
[[nodiscard]] crl::time OnlineChangeTimeout(
|
|
|
|
LastseenStatus status,
|
|
|
|
TimeId now);
|
2022-05-18 13:37:24 +00:00
|
|
|
[[nodiscard]] crl::time OnlineChangeTimeout(
|
|
|
|
not_null<UserData*> user,
|
|
|
|
TimeId now);
|
2024-01-15 07:36:17 +00:00
|
|
|
[[nodiscard]] QString OnlineText(LastseenStatus status, TimeId now);
|
2019-06-17 14:37:29 +00:00
|
|
|
[[nodiscard]] QString OnlineText(not_null<UserData*> user, TimeId now);
|
|
|
|
[[nodiscard]] QString OnlineTextFull(not_null<UserData*> user, TimeId now);
|
|
|
|
[[nodiscard]] bool OnlineTextActive(not_null<UserData*> user, TimeId now);
|
2022-10-24 07:22:26 +00:00
|
|
|
[[nodiscard]] bool IsUserOnline(not_null<UserData*> user, TimeId now = 0);
|
2020-12-02 10:52:19 +00:00
|
|
|
[[nodiscard]] bool ChannelHasActiveCall(not_null<ChannelData*> channel);
|
2017-12-17 08:13:26 +00:00
|
|
|
|
2021-11-09 12:10:51 +00:00
|
|
|
[[nodiscard]] rpl::producer<QImage> PeerUserpicImageValue(
|
|
|
|
not_null<PeerData*> peer,
|
2023-01-05 10:48:46 +00:00
|
|
|
int size,
|
|
|
|
std::optional<int> radius = {});
|
2021-11-09 12:10:51 +00:00
|
|
|
|
2022-08-22 09:15:34 +00:00
|
|
|
[[nodiscard]] const AllowedReactions &PeerAllowedReactions(
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] rpl::producer<AllowedReactions> PeerAllowedReactionsValue(
|
2022-01-10 14:22:43 +00:00
|
|
|
not_null<PeerData*> peer);
|
|
|
|
|
2022-08-17 18:03:57 +00:00
|
|
|
[[nodiscard]] int UniqueReactionsLimit(not_null<PeerData*> peer);
|
2022-01-10 14:22:43 +00:00
|
|
|
[[nodiscard]] rpl::producer<int> UniqueReactionsLimitValue(
|
2022-08-19 12:08:11 +00:00
|
|
|
not_null<PeerData*> peer);
|
2021-12-29 13:06:08 +00:00
|
|
|
|
2017-09-26 13:53:51 +00:00
|
|
|
} // namespace Data
|