mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Track my tags usages.
This commit is contained in:
parent
9aacff8b54
commit
e667436a98
2 changed files with 61 additions and 0 deletions
|
@ -378,6 +378,56 @@ void Reactions::setFavorite(const ReactionId &id) {
|
||||||
applyFavorite(id);
|
applyFavorite(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Reactions::incrementMyTag(const ReactionId &id) {
|
||||||
|
auto i = ranges::find(_myTagsInfo, id, &MyTagInfo::id);
|
||||||
|
if (i == end(_myTagsInfo)) {
|
||||||
|
_myTagsInfo.push_back({ .id = id, .count = 0 });
|
||||||
|
i = end(_myTagsInfo) - 1;
|
||||||
|
}
|
||||||
|
++i->count;
|
||||||
|
while (i != begin(_myTagsInfo)) {
|
||||||
|
auto j = i - 1;
|
||||||
|
if (j->count >= i->count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::swap(*i, *j);
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
scheduleMyTagsUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reactions::decrementMyTag(const ReactionId &id) {
|
||||||
|
auto i = ranges::find(_myTagsInfo, id, &MyTagInfo::id);
|
||||||
|
if (i->count <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
--i->count;
|
||||||
|
while (i + 1 != end(_myTagsInfo)) {
|
||||||
|
auto j = i + 1;
|
||||||
|
if (j->count <= i->count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::swap(*i, *j);
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
scheduleMyTagsUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reactions::scheduleMyTagsUpdate() {
|
||||||
|
_myTagsUpdateScheduled = true;
|
||||||
|
crl::on_main(&session(), [=] {
|
||||||
|
if (!_myTagsUpdateScheduled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_myTagsUpdateScheduled = false;
|
||||||
|
_myTagsIds = _myTagsInfo | ranges::views::transform(
|
||||||
|
&MyTagInfo::id
|
||||||
|
) | ranges::to_vector;
|
||||||
|
_myTags = resolveByIds(_myTagsIds, _unresolvedMyTags);
|
||||||
|
_myTagsUpdated.fire({});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
DocumentData *Reactions::chooseGenericAnimation(
|
DocumentData *Reactions::chooseGenericAnimation(
|
||||||
not_null<DocumentData*> custom) const {
|
not_null<DocumentData*> custom) const {
|
||||||
const auto sticker = custom->sticker();
|
const auto sticker = custom->sticker();
|
||||||
|
@ -1155,6 +1205,10 @@ void MessageReactions::add(const ReactionId &id, bool addToRecent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto my = 0;
|
auto my = 0;
|
||||||
|
const auto tags = _item->reactionsAreTags();
|
||||||
|
if (tags) {
|
||||||
|
history->owner().reactions().incrementMyTag(id);
|
||||||
|
}
|
||||||
_list.erase(ranges::remove_if(_list, [&](MessageReaction &one) {
|
_list.erase(ranges::remove_if(_list, [&](MessageReaction &one) {
|
||||||
const auto removing = one.my && (my == myLimit || ++my == myLimit);
|
const auto removing = one.my && (my == myLimit || ++my == myLimit);
|
||||||
if (!removing) {
|
if (!removing) {
|
||||||
|
@ -1176,6 +1230,9 @@ void MessageReactions::add(const ReactionId &id, bool addToRecent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tags) {
|
||||||
|
history->owner().reactions().decrementMyTag(one.id);
|
||||||
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}), end(_list));
|
}), end(_list));
|
||||||
const auto peer = history->peer;
|
const auto peer = history->peer;
|
||||||
|
|
|
@ -93,6 +93,8 @@ public:
|
||||||
[[nodiscard]] ReactionId favoriteId() const;
|
[[nodiscard]] ReactionId favoriteId() const;
|
||||||
[[nodiscard]] const Reaction *favorite() const;
|
[[nodiscard]] const Reaction *favorite() const;
|
||||||
void setFavorite(const ReactionId &id);
|
void setFavorite(const ReactionId &id);
|
||||||
|
void incrementMyTag(const ReactionId &id);
|
||||||
|
void decrementMyTag(const ReactionId &id);
|
||||||
[[nodiscard]] DocumentData *chooseGenericAnimation(
|
[[nodiscard]] DocumentData *chooseGenericAnimation(
|
||||||
not_null<DocumentData*> custom) const;
|
not_null<DocumentData*> custom) const;
|
||||||
|
|
||||||
|
@ -165,6 +167,7 @@ private:
|
||||||
base::flat_set<ReactionId> &unresolved);
|
base::flat_set<ReactionId> &unresolved);
|
||||||
void resolve(const ReactionId &id);
|
void resolve(const ReactionId &id);
|
||||||
void applyFavorite(const ReactionId &id);
|
void applyFavorite(const ReactionId &id);
|
||||||
|
void scheduleMyTagsUpdate();
|
||||||
|
|
||||||
[[nodiscard]] std::optional<Reaction> parse(
|
[[nodiscard]] std::optional<Reaction> parse(
|
||||||
const MTPAvailableReaction &entry);
|
const MTPAvailableReaction &entry);
|
||||||
|
@ -234,6 +237,7 @@ private:
|
||||||
|
|
||||||
mtpRequestId _myTagsRequestId = 0;
|
mtpRequestId _myTagsRequestId = 0;
|
||||||
bool _myTagsRequestScheduled = false;
|
bool _myTagsRequestScheduled = false;
|
||||||
|
bool _myTagsUpdateScheduled = false;
|
||||||
uint64 _myTagsHash = 0;
|
uint64 _myTagsHash = 0;
|
||||||
|
|
||||||
mtpRequestId _tagsRequestId = 0;
|
mtpRequestId _tagsRequestId = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue