Added ephemeral message actions and restrictions to context menus.

This commit is contained in:
23rd
2026-06-11 13:26:08 +03:00
committed by John Preston
parent 88fec5742f
commit 967b0bc875
11 changed files with 222 additions and 51 deletions
+66 -27
View File
@@ -23,6 +23,32 @@ namespace Api {
namespace {
[[nodiscard]] ReportResult ParseReportResult(const MTPReportResult &result) {
return result.match([&](const MTPDreportResultChooseOption &data) {
auto list = ReportResult::Options();
list.reserve(data.voptions().v.size());
for (const auto &tl : data.voptions().v) {
list.emplace_back(ReportResult::Option{
.id = tl.data().voption().v,
.text = qs(tl.data().vtext()),
});
}
return ReportResult{
.options = std::move(list),
.title = qs(data.vtitle()),
};
}, [&](const MTPDreportResultAddComment &data) -> ReportResult {
return {
.commentOption = ReportResult::CommentOption{
.optional = data.is_optional(),
.id = data.voption().v,
}
};
}, [&](const MTPDreportResultReported &data) -> ReportResult {
return { .successful = true };
});
}
MTPreportReason ReasonToTL(const Ui::ReportReason &reason) {
using Reason = Ui::ReportReason;
switch (reason) {
@@ -62,11 +88,6 @@ auto CreateReportMessagesOrStoriesCallback(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer)
-> Fn<void(Data::ReportInput, Fn<void(ReportResult)>)> {
using TLChoose = MTPDreportResultChooseOption;
using TLAddComment = MTPDreportResultAddComment;
using TLReported = MTPDreportResultReported;
using Result = ReportResult;
struct State final {
#ifdef _DEBUG
~State() {
@@ -79,7 +100,7 @@ auto CreateReportMessagesOrStoriesCallback(
return [=](
Data::ReportInput reportInput,
Fn<void(Result)> done) {
Fn<void(ReportResult)> done) {
auto apiIds = QVector<MTPint>();
apiIds.reserve(reportInput.ids.size() + reportInput.stories.size());
for (const auto &id : reportInput.ids) {
@@ -96,27 +117,7 @@ auto CreateReportMessagesOrStoriesCallback(
return;
}
state->requestId = 0;
done(result.match([&](const TLChoose &data) {
const auto t = qs(data.vtitle());
auto list = Result::Options();
list.reserve(data.voptions().v.size());
for (const auto &tl : data.voptions().v) {
list.emplace_back(Result::Option{
.id = tl.data().voption().v,
.text = qs(tl.data().vtext()),
});
}
return Result{ .options = std::move(list), .title = t };
}, [&](const TLAddComment &data) -> Result {
return {
.commentOption = ReportResult::CommentOption{
.optional = data.is_optional(),
.id = data.voption().v,
}
};
}, [&](const TLReported &data) -> Result {
return { .successful = true };
}));
done(ParseReportResult(result));
};
const auto fail = [=](const MTP::Error &error) {
@@ -144,6 +145,44 @@ auto CreateReportMessagesOrStoriesCallback(
};
}
auto CreateReportEphemeralMessageCallback(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer,
int32 ephemeralId)
-> Fn<void(Data::ReportInput, Fn<void(ReportResult)>)> {
struct State final {
mtpRequestId requestId = 0;
};
const auto state = std::make_shared<State>();
return [=](
Data::ReportInput reportInput,
Fn<void(ReportResult)> done) {
const auto received = [=](
const MTPReportResult &result,
mtpRequestId requestId) {
if (state->requestId != requestId) {
return;
}
state->requestId = 0;
done(ParseReportResult(result));
};
const auto fail = [=](const MTP::Error &error) {
state->requestId = 0;
done({ .error = error.type() });
};
state->requestId = peer->session().api().request(
MTPephemeral_ReportMessage(
peer->input(),
MTP_int(ephemeralId),
MTP_bytes(reportInput.optionId),
MTP_string(reportInput.comment))
).done(received).fail(fail).send();
};
}
ReactionReportCapabilities GetReactionReportCapabilities(
not_null<PeerData*> group,
not_null<PeerData*> participant) {