2022-10-13 10:32:03 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_thread.h"
|
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
#include "data/data_forum_topic.h"
|
|
|
|
#include "data/data_peer.h"
|
2022-10-13 10:32:03 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "history/history_unread_things.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
Thread::~Thread() = default;
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
MsgId Thread::topicRootId() const {
|
|
|
|
if (const auto topic = asTopic()) {
|
|
|
|
return topic->rootId();
|
|
|
|
}
|
|
|
|
return MsgId();
|
|
|
|
}
|
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
not_null<PeerData*> Thread::peer() const {
|
|
|
|
return owningHistory()->peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerNotifySettings &Thread::notify() {
|
|
|
|
const auto topic = asTopic();
|
|
|
|
return topic ? topic->notify() : peer()->notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PeerNotifySettings &Thread::notify() const {
|
|
|
|
return const_cast<Thread*>(this)->notify();
|
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
void Thread::setUnreadThingsKnown() {
|
|
|
|
_flags |= Flag::UnreadThingsKnown;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryUnreadThings::Proxy Thread::unreadMentions() {
|
|
|
|
return {
|
|
|
|
this,
|
|
|
|
_unreadThings,
|
|
|
|
HistoryUnreadThings::Type::Mentions,
|
|
|
|
!!(_flags & Flag::UnreadThingsKnown),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryUnreadThings::ConstProxy Thread::unreadMentions() const {
|
|
|
|
return {
|
|
|
|
_unreadThings ? &_unreadThings->mentions : nullptr,
|
|
|
|
!!(_flags & Flag::UnreadThingsKnown),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryUnreadThings::Proxy Thread::unreadReactions() {
|
|
|
|
return {
|
|
|
|
this,
|
|
|
|
_unreadThings,
|
|
|
|
HistoryUnreadThings::Type::Reactions,
|
|
|
|
!!(_flags & Flag::UnreadThingsKnown),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryUnreadThings::ConstProxy Thread::unreadReactions() const {
|
|
|
|
return {
|
|
|
|
_unreadThings ? &_unreadThings->reactions : nullptr,
|
|
|
|
!!(_flags & Flag::UnreadThingsKnown),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<MsgId> &Thread::unreadMentionsIds() const {
|
|
|
|
if (!_unreadThings) {
|
|
|
|
static const auto Result = base::flat_set<MsgId>();
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
return _unreadThings->mentions.ids();
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<MsgId> &Thread::unreadReactionsIds() const {
|
|
|
|
if (!_unreadThings) {
|
|
|
|
static const auto Result = base::flat_set<MsgId>();
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
return _unreadThings->reactions.ids();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::clearNotifications() {
|
|
|
|
_notifications.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::clearIncomingNotifications() {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (!peer()->isSelf()) {
|
2022-10-13 10:32:03 +00:00
|
|
|
const auto proj = [](ItemNotification notification) {
|
|
|
|
return notification.item->out();
|
|
|
|
};
|
|
|
|
_notifications.erase(
|
|
|
|
ranges::remove(_notifications, false, proj),
|
|
|
|
end(_notifications));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::removeNotification(not_null<HistoryItem*> item) {
|
|
|
|
_notifications.erase(
|
|
|
|
ranges::remove(_notifications, item, &ItemNotification::item),
|
|
|
|
end(_notifications));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<ItemNotification> Thread::currentNotification() const {
|
|
|
|
return empty(_notifications)
|
|
|
|
? std::nullopt
|
|
|
|
: std::make_optional(_notifications.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::hasNotification() const {
|
|
|
|
return !empty(_notifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::skipNotification() {
|
|
|
|
if (!empty(_notifications)) {
|
|
|
|
_notifications.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::pushNotification(ItemNotification notification) {
|
|
|
|
_notifications.push_back(notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::popNotification(ItemNotification notification) {
|
|
|
|
if (!empty(_notifications) && (_notifications.back() == notification)) {
|
|
|
|
_notifications.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::setMuted(bool muted) {
|
|
|
|
if (muted) {
|
|
|
|
_flags |= Flag::Muted;
|
|
|
|
} else {
|
|
|
|
_flags &= ~Flag::Muted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
void Thread::setUnreadMarkFlag(bool unread) {
|
2022-10-13 10:32:03 +00:00
|
|
|
if (unread) {
|
|
|
|
_flags |= Flag::UnreadMark;
|
|
|
|
} else {
|
|
|
|
_flags &= ~Flag::UnreadMark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Data
|