2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Show emoji statuses in channels.

This commit is contained in:
John Preston
2023-12-16 22:43:35 +00:00
parent 6aaf841a73
commit 805a5d73b6
12 changed files with 81 additions and 67 deletions

View File

@@ -104,19 +104,19 @@ rpl::producer<> EmojiStatuses::defaultUpdates() const {
}
void EmojiStatuses::registerAutomaticClear(
not_null<UserData*> user,
not_null<PeerData*> peer,
TimeId until) {
if (!until) {
_clearing.remove(user);
_clearing.remove(peer);
if (_clearing.empty()) {
_clearingTimer.cancel();
}
} else if (auto &already = _clearing[user]; already != until) {
} else if (auto &already = _clearing[peer]; already != until) {
already = until;
const auto i = ranges::min_element(_clearing, {}, [](auto &&pair) {
return pair.second;
});
if (i->first == user) {
if (i->first == peer) {
const auto now = base::unixtime::now();
if (now < until) {
processClearingIn(until - now);

View File

@@ -51,7 +51,7 @@ public:
void set(DocumentId id, TimeId until = 0);
[[nodiscard]] bool setting() const;
void registerAutomaticClear(not_null<UserData*> user, TimeId until);
void registerAutomaticClear(not_null<PeerData*> peer, TimeId until);
using Groups = std::vector<Ui::EmojiGroup>;
[[nodiscard]] rpl::producer<Groups> emojiGroupsValue() const;
@@ -102,7 +102,7 @@ private:
mtpRequestId _sentRequestId = 0;
base::flat_map<not_null<UserData*>, TimeId> _clearing;
base::flat_map<not_null<PeerData*>, TimeId> _clearing;
base::Timer _clearingTimer;
GroupsType _emojiGroups;

View File

@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_chat_participant_status.h"
#include "data/data_channel.h"
#include "data/data_changes.h"
#include "data/data_emoji_statuses.h"
#include "data/data_message_reaction_id.h"
#include "data/data_photo.h"
#include "data/data_folder.h"
@@ -926,6 +927,24 @@ bool PeerData::changeBackgroundEmojiId(DocumentId id) {
_backgroundEmojiId = id;
return true;
}
void PeerData::setEmojiStatus(const MTPEmojiStatus &status) {
const auto parsed = Data::ParseEmojiStatus(status);
setEmojiStatus(parsed.id, parsed.until);
}
void PeerData::setEmojiStatus(DocumentId emojiStatusId, TimeId until) {
if (_emojiStatusId != emojiStatusId) {
_emojiStatusId = emojiStatusId;
session().changes().peerUpdated(this, UpdateFlag::EmojiStatus);
}
owner().emojiStatuses().registerAutomaticClear(this, until);
}
DocumentId PeerData::emojiStatusId() const {
return _emojiStatusId;
}
bool PeerData::isSelf() const {
if (const auto user = asUser()) {
return (user->flags() & UserDataFlag::Self);

View File

@@ -178,6 +178,10 @@ public:
[[nodiscard]] DocumentId backgroundEmojiId() const;
bool changeBackgroundEmojiId(DocumentId id);
void setEmojiStatus(const MTPEmojiStatus &status);
void setEmojiStatus(DocumentId emojiStatusId, TimeId until = 0);
[[nodiscard]] DocumentId emojiStatusId() const;
[[nodiscard]] bool isUser() const {
return peerIsUser(id);
}
@@ -466,6 +470,7 @@ private:
base::flat_set<QString> _nameWords; // for filtering
base::flat_set<QChar> _nameFirstLetters;
DocumentId _emojiStatusId = 0;
uint64 _backgroundEmojiId = 0;
crl::time _lastFullUpdate = 0;

View File

@@ -854,6 +854,11 @@ not_null<PeerData*> Session::processChat(const MTPChat &data) {
channel->setDefaultRestrictions(ChatRestrictions());
}
if (const auto &status = data.vemoji_status()) {
channel->setEmojiStatus(*status);
} else {
channel->setEmojiStatus(0);
}
if (minimal) {
if (channel->input.type() == mtpc_inputPeerEmpty
|| channel->inputChannel.type() == mtpc_inputChannelEmpty) {

View File

@@ -15,7 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_peer_bot_command.h"
#include "data/data_photo.h"
#include "data/data_stories.h"
#include "data/data_emoji_statuses.h"
#include "data/data_wall_paper.h"
#include "data/notify/data_notify_settings.h"
#include "history/history.h"
@@ -73,23 +72,6 @@ void UserData::setPhoto(const MTPUserProfilePhoto &photo) {
});
}
void UserData::setEmojiStatus(const MTPEmojiStatus &status) {
const auto parsed = Data::ParseEmojiStatus(status);
setEmojiStatus(parsed.id, parsed.until);
}
void UserData::setEmojiStatus(DocumentId emojiStatusId, TimeId until) {
if (_emojiStatusId != emojiStatusId) {
_emojiStatusId = emojiStatusId;
session().changes().peerUpdated(this, UpdateFlag::EmojiStatus);
}
owner().emojiStatuses().registerAutomaticClear(this, until);
}
DocumentId UserData::emojiStatusId() const {
return _emojiStatusId;
}
auto UserData::unavailableReasons() const
-> const std::vector<Data::UnavailableReason> & {
return _unavailableReasons;

View File

@@ -76,7 +76,6 @@ public:
UserData(not_null<Data::Session*> owner, PeerId id);
void setPhoto(const MTPUserProfilePhoto &photo);
void setEmojiStatus(const MTPEmojiStatus &status);
void setName(
const QString &newFirstName,
@@ -85,9 +84,6 @@ public:
const QString &newUsername);
void setUsernames(const Data::Usernames &newUsernames);
void setEmojiStatus(DocumentId emojiStatusId, TimeId until = 0);
[[nodiscard]] DocumentId emojiStatusId() const;
void setUsername(const QString &username);
void setPhone(const QString &newPhone);
void setBotInfoVersion(int version);
@@ -199,8 +195,6 @@ private:
static constexpr auto kInaccessibleAccessHashOld
= 0xFFFFFFFFFFFFFFFFULL;
DocumentId _emojiStatusId = 0;
};
namespace Data {