mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Implement custom reactions in stories.
This commit is contained in:
@@ -226,8 +226,9 @@ struct StoryUpdate {
|
||||
NewAdded = (1U << 2),
|
||||
ViewsAdded = (1U << 3),
|
||||
MarkRead = (1U << 4),
|
||||
Reaction = (1U << 5),
|
||||
|
||||
LastUsedBit = (1U << 4),
|
||||
LastUsedBit = (1U << 5),
|
||||
};
|
||||
using Flags = base::flags<Flag>;
|
||||
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
||||
|
@@ -381,7 +381,7 @@ void Reactions::preloadImageFor(const ReactionId &id) {
|
||||
loadImage(set, document, !i->centerIcon);
|
||||
} else if (!_waitingForList) {
|
||||
_waitingForList = true;
|
||||
refreshRecent();
|
||||
refreshDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -870,6 +870,21 @@ void Stories::activateStealthMode(Fn<void()> done) {
|
||||
}).send();
|
||||
}
|
||||
|
||||
void Stories::sendReaction(FullStoryId id, Data::ReactionId reaction) {
|
||||
if (const auto maybeStory = lookup(id)) {
|
||||
const auto story = *maybeStory;
|
||||
story->setReactionId(reaction);
|
||||
|
||||
const auto api = &session().api();
|
||||
api->request(MTPstories_SendReaction(
|
||||
MTP_flags(0),
|
||||
story->peer()->asUser()->inputUser,
|
||||
MTP_int(id.story),
|
||||
ReactionToMTP(reaction)
|
||||
)).send();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<HistoryItem> Stories::resolveItem(not_null<Story*> story) {
|
||||
auto &items = _items[story->peer()->id];
|
||||
auto i = items.find(story->id());
|
||||
|
@@ -240,6 +240,8 @@ public:
|
||||
[[nodiscard]] rpl::producer<StealthMode> stealthModeValue() const;
|
||||
void activateStealthMode(Fn<void()> done = nullptr);
|
||||
|
||||
void sendReaction(FullStoryId id, Data::ReactionId reaction);
|
||||
|
||||
private:
|
||||
struct Saved {
|
||||
StoriesIds ids;
|
||||
|
@@ -376,6 +376,17 @@ const TextWithEntities &Story::caption() const {
|
||||
return unsupported() ? empty : _caption;
|
||||
}
|
||||
|
||||
Data::ReactionId Story::sentReactionId() const {
|
||||
return _sentReactionId;
|
||||
}
|
||||
|
||||
void Story::setReactionId(Data::ReactionId id) {
|
||||
if (_sentReactionId != id) {
|
||||
_sentReactionId = id;
|
||||
session().changes().storyUpdated(this, UpdateFlag::Reaction);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<not_null<PeerData*>> &Story::recentViewers() const {
|
||||
return _recentViewers;
|
||||
}
|
||||
@@ -458,6 +469,9 @@ void Story::applyFields(
|
||||
bool initial) {
|
||||
_lastUpdateTime = now;
|
||||
|
||||
const auto reaction = data.vsent_reaction()
|
||||
? Data::ReactionFromMTP(*data.vsent_reaction())
|
||||
: Data::ReactionId();
|
||||
const auto pinned = data.is_pinned();
|
||||
const auto edited = data.is_edited();
|
||||
const auto privacy = data.is_public()
|
||||
@@ -512,6 +526,7 @@ void Story::applyFields(
|
||||
|| (_views.reactions != reactions)
|
||||
|| (_recentViewers != viewers);
|
||||
const auto locationsChanged = (_locations != locations);
|
||||
const auto reactionChanged = (_sentReactionId != reaction);
|
||||
|
||||
_privacyPublic = (privacy == StoryPrivacy::Public);
|
||||
_privacyCloseFriends = (privacy == StoryPrivacy::CloseFriends);
|
||||
@@ -536,15 +551,19 @@ void Story::applyFields(
|
||||
if (locationsChanged) {
|
||||
_locations = std::move(locations);
|
||||
}
|
||||
if (reactionChanged) {
|
||||
_sentReactionId = reaction;
|
||||
}
|
||||
|
||||
const auto changed = editedChanged
|
||||
|| captionChanged
|
||||
|| mediaChanged
|
||||
|| locationsChanged;
|
||||
if (!initial && (changed || viewsChanged)) {
|
||||
if (!initial && (changed || viewsChanged || reactionChanged)) {
|
||||
_peer->session().changes().storyUpdated(this, UpdateFlag()
|
||||
| (changed ? UpdateFlag::Edited : UpdateFlag())
|
||||
| (viewsChanged ? UpdateFlag::ViewsAdded : UpdateFlag()));
|
||||
| (viewsChanged ? UpdateFlag::ViewsAdded : UpdateFlag())
|
||||
| (reactionChanged ? UpdateFlag::Reaction : UpdateFlag()));
|
||||
}
|
||||
if (!initial && (captionChanged || mediaChanged)) {
|
||||
if (const auto item = _peer->owner().stories().lookupItem(this)) {
|
||||
|
@@ -146,6 +146,9 @@ public:
|
||||
void setCaption(TextWithEntities &&caption);
|
||||
[[nodiscard]] const TextWithEntities &caption() const;
|
||||
|
||||
[[nodiscard]] Data::ReactionId sentReactionId() const;
|
||||
void setReactionId(Data::ReactionId id);
|
||||
|
||||
[[nodiscard]] auto recentViewers() const
|
||||
-> const std::vector<not_null<PeerData*>> &;
|
||||
[[nodiscard]] const StoryViews &viewsList() const;
|
||||
@@ -170,6 +173,7 @@ private:
|
||||
|
||||
const StoryId _id = 0;
|
||||
const not_null<PeerData*> _peer;
|
||||
Data::ReactionId _sentReactionId;
|
||||
StoryMedia _media;
|
||||
TextWithEntities _caption;
|
||||
std::vector<not_null<PeerData*>> _recentViewers;
|
||||
|
Reference in New Issue
Block a user