1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*
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"
#include "data/data_forum_topic.h"
#include "data/data_changes.h"
#include "data/data_peer.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_unread_things.h"
#include "main/main_session.h"
namespace Data {
Thread::~Thread() = default;
not_null<Thread*> Thread::migrateToOrMe() const {
const auto history = asHistory();
return history ? history->migrateToOrMe() : const_cast<Thread*>(this);
}
MsgId Thread::topicRootId() const {
if (const auto topic = asTopic()) {
return topic->rootId();
}
return MsgId();
}
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();
}
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() {
if (!peer()->isSelf()) {
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;
}
}
void Thread::setUnreadMarkFlag(bool unread) {
if (unread) {
_flags |= Flag::UnreadMark;
} else {
_flags &= ~Flag::UnreadMark;
}
}
[[nodiscard]] bool Thread::hasPinnedMessages() const {
return (_flags & Flag::HasPinnedMessages);
}
void Thread::setHasPinnedMessages(bool has) {
if (hasPinnedMessages() == has) {
return;
} else if (has) {
_flags |= Flag::HasPinnedMessages;
} else {
_flags &= ~Flag::HasPinnedMessages;
}
session().changes().entryUpdated(
this,
EntryUpdate::Flag::HasPinnedMessages);
}
} // namespace Data
|