Update API scheme on layer 136.

This commit is contained in:
John Preston 2021-12-22 11:56:02 +00:00
parent 6f2bb43505
commit 118072db77
5 changed files with 42 additions and 10 deletions

View file

@ -921,6 +921,7 @@ channelAdminLogEventActionChangeHistoryTTL#6e941a38 prev_value:int new_value:int
channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatInvite approved_by:long = ChannelAdminLogEventAction;
channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction;
channelAdminLogEventActionChangeAvailableReactions#9cf7f76a prev_value:Vector<string> new_value:Vector<string> = ChannelAdminLogEventAction;
channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent;
@ -1306,13 +1307,13 @@ auth.loggedOut#c3a2835f flags:# future_auth_token:flags.0?bytes = auth.LoggedOut
reactionCount#6fb250d1 flags:# chosen:flags.0?true reaction:string count:int = ReactionCount;
messageReactions#87b6e36 flags:# min:flags.0?true results:Vector<ReactionCount> recent_reactons:flags.1?Vector<MessageUserReaction> = MessageReactions;
messageReactions#87b6e36 flags:# min:flags.0?true can_see_list:flags.2?true results:Vector<ReactionCount> recent_reactons:flags.1?Vector<MessageUserReaction> = MessageReactions;
messageUserReaction#932844fa user_id:long reaction:string = MessageUserReaction;
messages.messageReactionsList#a366923c flags:# count:int reactions:Vector<MessageUserReaction> users:Vector<User> next_offset:flags.0?string = messages.MessageReactionsList;
availableReaction#64222f31 reaction:string title:string static_icon:Document select_animation:Document activate_animation:Document effect_animation:Document = AvailableReaction;
availableReaction#21d7c4b flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document = AvailableReaction;
messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions;
messages.availableReactions#768e3aad hash:int reactions:Vector<AvailableReaction> = messages.AvailableReactions;
@ -1600,6 +1601,7 @@ messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector<int> = Updates;
messages.getMessageReactionsList#e0ee6b77 flags:# peer:InputPeer id:int reaction:flags.0?string offset:flags.1?string limit:int = messages.MessageReactionsList;
messages.setChatAvailableReactions#14050ea6 peer:InputPeer available_reactions:Vector<string> = Updates;
messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions;
messages.setDefaultReaction#d960c4d4 reaction:string = Bool;
updates.getState#edd4882a = updates.State;
updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;

View file

@ -1058,7 +1058,8 @@ void Controller::fillManageSection() {
_navigation->parentController()->show(Box(
EditAllowedReactionsBox,
!_peer->isBroadcast(),
session->data().reactions().list(),
session->data().reactions().list(
Data::Reactions::Type::Active),
session->data().reactions().list(_peer),
done));
},

View file

@ -40,8 +40,12 @@ void Reactions::refresh() {
request();
}
const std::vector<Reaction> &Reactions::list() const {
return _available;
const std::vector<Reaction> &Reactions::list(Type type) const {
switch (type) {
case Type::Active: return _active;
case Type::All: return _available;
}
Unexpected("Type in Reactions::list.");
}
std::vector<Reaction> Reactions::list(not_null<PeerData*> peer) const {
@ -50,7 +54,7 @@ std::vector<Reaction> Reactions::list(not_null<PeerData*> peer) const {
} else if (const auto channel = peer->asChannel()) {
return filtered(channel->allowedReactions());
} else {
return list();
return list(Type::Active);
}
}
@ -95,7 +99,7 @@ void Reactions::resolveImages() {
continue;
}
const auto i = ranges::find(_available, emoji, &Reaction::emoji);
const auto document = (i != end(list()))
const auto document = (i != end(_available))
? i->staticIcon.get()
: nullptr;
if (document) {
@ -173,7 +177,7 @@ std::vector<Reaction> Reactions::Filtered(
std::vector<Reaction> Reactions::filtered(
const std::vector<QString> &emoji) const {
return Filtered(list(), emoji);
return Filtered(list(Type::Active), emoji);
}
std::vector<QString> Reactions::ParseAllowed(
@ -188,6 +192,9 @@ std::vector<QString> Reactions::ParseAllowed(
void Reactions::request() {
auto &api = _owner->session().api();
if (_requestId) {
return;
}
_requestId = api.request(MTPmessages_GetAvailableReactions(
MTP_int(_hash)
)).done([=](const MTPmessages_AvailableReactions &result) {
@ -196,11 +203,16 @@ void Reactions::request() {
_hash = data.vhash().v;
const auto &list = data.vreactions().v;
_active.clear();
_available.clear();
_available.reserve(data.vreactions().v.size());
_active.reserve(list.size());
_available.reserve(list.size());
for (const auto &reaction : list) {
if (const auto parsed = parse(reaction)) {
_available.push_back(*parsed);
if (parsed->active) {
_active.push_back(*parsed);
}
}
}
if (_waitingForList) {
@ -228,12 +240,15 @@ std::optional<Reaction> Reactions::parse(const MTPAvailableReaction &entry) {
.emoji = emoji,
.title = qs(data.vtitle()),
.staticIcon = _owner->processDocument(data.vstatic_icon()),
.appearAnimation = _owner->processDocument(
data.vappear_animation()),
.selectAnimation = _owner->processDocument(
data.vselect_animation()),
.activateAnimation = _owner->processDocument(
data.vactivate_animation()),
.activateEffects = _owner->processDocument(
data.veffect_animation()),
.active = !data.is_inactive(),
})
: std::nullopt;
});

View file

@ -16,9 +16,11 @@ struct Reaction {
QString emoji;
QString title;
not_null<DocumentData*> staticIcon;
not_null<DocumentData*> appearAnimation;
not_null<DocumentData*> selectAnimation;
not_null<DocumentData*> activateAnimation;
not_null<DocumentData*> activateEffects;
bool active = false;
};
class Reactions final {
@ -27,7 +29,11 @@ public:
void refresh();
[[nodiscard]] const std::vector<Reaction> &list() const;
enum class Type {
Active,
All,
};
[[nodiscard]] const std::vector<Reaction> &list(Type type) const;
[[nodiscard]] std::vector<Reaction> list(not_null<PeerData*> peer) const;
[[nodiscard]] static std::vector<Reaction> Filtered(
@ -69,6 +75,7 @@ private:
const not_null<Session*> _owner;
std::vector<Reaction> _active;
std::vector<Reaction> _available;
rpl::event_stream<> _updated;

View file

@ -652,6 +652,7 @@ void GenerateItems(
MTPDchannelAdminLogEventActionParticipantJoinByRequest;
using LogNoForwards = MTPDchannelAdminLogEventActionToggleNoForwards;
using LogActionSendMessage = MTPDchannelAdminLogEventActionSendMessage;
using LogEventActionChangeAvailableReactions = MTPDchannelAdminLogEventActionChangeAvailableReactions;
const auto session = &history->session();
const auto id = event.vid().v;
@ -1370,6 +1371,10 @@ void GenerateItems(
ExtractSentDate(data.vmessage()));
};
const auto createChangeAvailableReactions = [&](const LogEventActionChangeAvailableReactions &data) {
// #TODO reactions
};
action.match([&](const LogTitle &data) {
createChangeTitle(data);
}, [&](const LogAbout &data) {
@ -1440,6 +1445,8 @@ void GenerateItems(
createToggleNoForwards(data);
}, [&](const LogActionSendMessage &data) {
createSendMessage(data);
}, [&](const LogEventActionChangeAvailableReactions &data) {
createChangeAvailableReactions(data);
});
}