2022-09-20 18:12:30 +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_forum_topic.h"
|
|
|
|
|
|
|
|
#include "data/data_channel.h"
|
2022-10-07 13:56:07 +00:00
|
|
|
#include "data/data_changes.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "data/data_forum.h"
|
2022-10-06 15:11:26 +00:00
|
|
|
#include "data/data_histories.h"
|
2022-10-07 11:46:27 +00:00
|
|
|
#include "data/data_replies_list.h"
|
2022-10-17 16:29:48 +00:00
|
|
|
#include "data/data_send_action.h"
|
2022-10-12 20:23:14 +00:00
|
|
|
#include "data/notify/data_notify_settings.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "data/data_session.h"
|
2022-09-27 16:52:35 +00:00
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "dialogs/dialogs_main_list.h"
|
2022-09-29 10:33:17 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2022-10-07 13:56:07 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "api/api_unread_things.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
2022-10-07 13:56:07 +00:00
|
|
|
#include "history/history_unread_things.h"
|
2022-10-06 15:11:26 +00:00
|
|
|
#include "history/view/history_view_item_preview.h"
|
2022-10-07 13:56:07 +00:00
|
|
|
#include "main/main_session.h"
|
2022-09-27 16:52:35 +00:00
|
|
|
#include "ui/painter.h"
|
2022-10-05 07:42:44 +00:00
|
|
|
#include "ui/color_int_conversion.h"
|
2022-09-29 10:33:17 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2022-10-04 17:02:40 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
|
2022-10-05 07:42:44 +00:00
|
|
|
#include <QtSvg/QSvgRenderer>
|
|
|
|
|
2022-09-20 18:12:30 +00:00
|
|
|
namespace Data {
|
2022-10-07 13:56:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using UpdateFlag = TopicUpdate::Flag;
|
|
|
|
|
|
|
|
} // namespace
|
2022-09-20 18:12:30 +00:00
|
|
|
|
2022-10-05 07:42:44 +00:00
|
|
|
const base::flat_map<int32, QString> &ForumTopicIcons() {
|
|
|
|
static const auto Result = base::flat_map<int32, QString>{
|
|
|
|
{ 0x6FB9F0, u"blue"_q },
|
|
|
|
{ 0xFFD67E, u"yellow"_q },
|
|
|
|
{ 0xCB86DB, u"violet"_q },
|
|
|
|
{ 0x8EEE98, u"green"_q },
|
|
|
|
{ 0xFF93B2, u"rose"_q },
|
|
|
|
{ 0xFB6F5F, u"red"_q },
|
|
|
|
};
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<int32> &ForumTopicColorIds() {
|
|
|
|
static const auto Result = ForumTopicIcons(
|
|
|
|
) | ranges::views::transform([](const auto &pair) {
|
|
|
|
return pair.first;
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &ForumTopicDefaultIcon() {
|
|
|
|
static const auto Result = u"gray"_q;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &ForumTopicIcon(int32 colorId) {
|
|
|
|
const auto &icons = ForumTopicIcons();
|
|
|
|
const auto i = icons.find(colorId);
|
|
|
|
return (i != end(icons)) ? i->second : ForumTopicDefaultIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ForumTopicIconPath(const QString &name) {
|
|
|
|
return u":/gui/topic_icons/%1.svg"_q.arg(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage ForumTopicIconBackground(int32 colorId, int size) {
|
|
|
|
const auto ratio = style::DevicePixelRatio();
|
|
|
|
auto svg = QSvgRenderer(ForumTopicIconPath(ForumTopicIcon(colorId)));
|
|
|
|
auto result = QImage(
|
|
|
|
QSize(size, size) * ratio,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(ratio);
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
|
|
|
|
auto p = QPainter(&result);
|
|
|
|
svg.render(&p, QRect(0, 0, size, size));
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtractNonEmojiLetter(const QString &title) {
|
|
|
|
const auto begin = title.data();
|
|
|
|
const auto end = begin + title.size();
|
|
|
|
for (auto ch = begin; ch != end;) {
|
|
|
|
auto length = 0;
|
|
|
|
if (Ui::Emoji::Find(ch, end, &length)) {
|
|
|
|
ch += length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
uint ucs4 = ch->unicode();
|
|
|
|
length = 1;
|
|
|
|
if (QChar::isHighSurrogate(ucs4) && ch + 1 != end) {
|
|
|
|
ushort low = ch[1].unicode();
|
|
|
|
if (QChar::isLowSurrogate(low)) {
|
|
|
|
ucs4 = QChar::surrogateToUcs4(ucs4, low);
|
|
|
|
length = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QChar::isLetterOrNumber(ucs4)) {
|
|
|
|
ch += length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return QString(ch, length);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage ForumTopicIconFrame(
|
|
|
|
int32 colorId,
|
|
|
|
const QString &title,
|
|
|
|
const style::ForumTopicIcon &st) {
|
|
|
|
auto background = ForumTopicIconBackground(colorId, st.size);
|
|
|
|
|
|
|
|
if (const auto one = ExtractNonEmojiLetter(title); !one.isEmpty()) {
|
|
|
|
auto p = QPainter(&background);
|
|
|
|
p.setPen(Qt::white);
|
2022-10-06 13:06:18 +00:00
|
|
|
p.setFont(st.font);
|
2022-10-05 07:42:44 +00:00
|
|
|
p.drawText(
|
|
|
|
QRect(0, st.textTop, st.size, st.font->height * 2),
|
|
|
|
one,
|
|
|
|
style::al_top);
|
|
|
|
}
|
|
|
|
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
ForumTopic::ForumTopic(not_null<Forum*> forum, MsgId rootId)
|
|
|
|
: Thread(&forum->history()->owner(), Type::ForumTopic)
|
|
|
|
, _forum(forum)
|
2022-10-12 12:57:17 +00:00
|
|
|
, _list(_forum->topicsList())
|
2022-10-13 10:32:03 +00:00
|
|
|
, _replies(std::make_shared<RepliesList>(history(), rootId))
|
2022-10-17 16:29:48 +00:00
|
|
|
, _sendActionPainter(owner().sendActionManager().repliesPainter(
|
|
|
|
history(),
|
|
|
|
rootId))
|
2022-10-14 13:25:05 +00:00
|
|
|
, _rootId(rootId)
|
|
|
|
, _lastKnownServerMessageId(rootId) {
|
2022-10-13 10:32:03 +00:00
|
|
|
Thread::setMuted(owner().notifySettings().isMuted(this));
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
_sendActionPainter->setTopic(this);
|
|
|
|
|
2022-10-07 11:46:27 +00:00
|
|
|
_replies->unreadCountValue(
|
2022-10-20 09:33:04 +00:00
|
|
|
) | rpl::map([=](std::optional<int> value) {
|
|
|
|
return value ? _replies->displayedUnreadCount() : value;
|
|
|
|
}) | rpl::distinct_until_changed(
|
2022-10-07 11:46:27 +00:00
|
|
|
) | rpl::combine_previous(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return inChatList();
|
|
|
|
}) | rpl::start_with_next([=](
|
|
|
|
std::optional<int> previous,
|
|
|
|
std::optional<int> now) {
|
|
|
|
notifyUnreadStateChange(unreadStateFor(
|
|
|
|
previous.value_or(0),
|
|
|
|
previous.has_value()));
|
|
|
|
}, _replies->lifetime());
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 13:56:07 +00:00
|
|
|
ForumTopic::~ForumTopic() {
|
2022-10-17 16:29:48 +00:00
|
|
|
_sendActionPainter->setTopic(nullptr);
|
2022-10-07 13:56:07 +00:00
|
|
|
session().api().unreadThings().cancelRequests(this);
|
|
|
|
}
|
2022-10-04 15:34:45 +00:00
|
|
|
|
2022-10-07 11:46:27 +00:00
|
|
|
std::shared_ptr<Data::RepliesList> ForumTopic::replies() const {
|
|
|
|
return _replies;
|
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
not_null<ChannelData*> ForumTopic::channel() const {
|
2022-10-12 12:57:17 +00:00
|
|
|
return _forum->channel();
|
2022-09-27 12:05:47 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:52:35 +00:00
|
|
|
not_null<History*> ForumTopic::history() const {
|
2022-10-12 12:57:17 +00:00
|
|
|
return _forum->history();
|
2022-09-27 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Forum*> ForumTopic::forum() const {
|
2022-10-12 12:57:17 +00:00
|
|
|
return _forum;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ForumTopic::destroyed() const {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
return rpl::merge(
|
|
|
|
_forum->destroyed(),
|
|
|
|
_forum->topicDestroyed() | rpl::filter(_1 == this) | rpl::to_empty);
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MsgId ForumTopic::rootId() const {
|
|
|
|
return _rootId;
|
|
|
|
}
|
|
|
|
|
2022-10-18 15:39:41 +00:00
|
|
|
bool ForumTopic::canEdit() const {
|
|
|
|
return (_flags & Flag::My) || channel()->canEditTopics();
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:59:37 +00:00
|
|
|
bool ForumTopic::canDelete() const {
|
|
|
|
return !creating()
|
|
|
|
&& (channel()->canEditTopics()
|
|
|
|
// We don't know if we can delete or not.
|
|
|
|
/*|| ((_flags & Flag::My) && onlyOneMyMessage)*/);
|
|
|
|
}
|
|
|
|
|
2022-10-18 15:39:41 +00:00
|
|
|
bool ForumTopic::canToggleClosed() const {
|
|
|
|
return !creating() && canEdit();
|
|
|
|
}
|
|
|
|
|
2022-10-19 08:19:11 +00:00
|
|
|
bool ForumTopic::canTogglePinned() const {
|
|
|
|
return !creating() && channel()->canEditTopics();
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
bool ForumTopic::creating() const {
|
|
|
|
return _forum->creating(_rootId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::discard() {
|
|
|
|
Expects(creating());
|
|
|
|
|
|
|
|
_forum->discardCreatingId(_rootId);
|
|
|
|
}
|
|
|
|
|
2022-10-04 15:34:45 +00:00
|
|
|
void ForumTopic::setRealRootId(MsgId realId) {
|
2022-10-07 11:46:27 +00:00
|
|
|
if (_rootId != realId) {
|
|
|
|
_rootId = realId;
|
2022-10-14 13:25:05 +00:00
|
|
|
_lastKnownServerMessageId = realId;
|
2022-10-12 12:57:17 +00:00
|
|
|
_replies = std::make_shared<RepliesList>(history(), _rootId);
|
2022-10-17 16:29:48 +00:00
|
|
|
_sendActionPainter = owner().sendActionManager().repliesPainter(
|
|
|
|
history(),
|
|
|
|
_rootId);
|
2022-10-07 11:46:27 +00:00
|
|
|
}
|
2022-10-04 15:34:45 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
|
|
|
|
Expects(_rootId == data.vid().v);
|
2022-09-20 18:12:30 +00:00
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
applyTitle(qs(data.vtitle()));
|
2022-09-27 12:05:47 +00:00
|
|
|
if (const auto iconId = data.vicon_emoji_id()) {
|
|
|
|
applyIconId(iconId->v);
|
|
|
|
} else {
|
|
|
|
applyIconId(0);
|
|
|
|
}
|
2022-10-05 07:42:44 +00:00
|
|
|
applyColorId(data.vicon_color().v);
|
2022-09-20 18:12:30 +00:00
|
|
|
|
|
|
|
if (data.is_pinned()) {
|
2022-10-19 08:19:11 +00:00
|
|
|
owner().setChatPinned(this, 0, true);
|
2022-09-20 18:12:30 +00:00
|
|
|
} else {
|
2022-10-19 08:19:11 +00:00
|
|
|
_list->pinned()->setPinned(this, false);
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
owner().notifySettings().apply(this, data.vnotify_settings());
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
const auto draft = data.vdraft();
|
|
|
|
if (draft && draft->type() == mtpc_draftMessage) {
|
|
|
|
Data::ApplyPeerCloudDraft(
|
|
|
|
&session(),
|
|
|
|
channel()->id,
|
|
|
|
_rootId,
|
|
|
|
draft->c_draftMessage());
|
|
|
|
}
|
2022-10-18 15:39:41 +00:00
|
|
|
if (data.is_my()) {
|
|
|
|
_flags |= Flag::My;
|
|
|
|
} else {
|
|
|
|
_flags &= ~Flag::My;
|
|
|
|
}
|
|
|
|
setClosed(data.is_closed());
|
2022-10-17 16:29:48 +00:00
|
|
|
|
2022-10-07 11:46:27 +00:00
|
|
|
_replies->setInboxReadTill(
|
2022-09-20 18:12:30 +00:00
|
|
|
data.vread_inbox_max_id().v,
|
2022-10-07 11:46:27 +00:00
|
|
|
data.vunread_count().v);
|
|
|
|
_replies->setOutboxReadTill(data.vread_outbox_max_id().v);
|
2022-09-20 18:12:30 +00:00
|
|
|
applyTopicTopMessage(data.vtop_message().v);
|
2022-10-07 13:56:07 +00:00
|
|
|
unreadMentions().setCount(data.vunread_mentions_count().v);
|
|
|
|
unreadReactions().setCount(data.vunread_reactions_count().v);
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 15:39:41 +00:00
|
|
|
bool ForumTopic::closed() const {
|
|
|
|
return _flags & Flag::Closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::setClosed(bool closed) {
|
|
|
|
if (this->closed() == closed) {
|
|
|
|
return;
|
|
|
|
} else if (closed) {
|
|
|
|
_flags |= Flag::Closed;
|
|
|
|
} else {
|
|
|
|
_flags &= ~Flag::Closed;
|
|
|
|
}
|
|
|
|
session().changes().topicUpdated(this, UpdateFlag::Closed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::setClosedAndSave(bool closed) {
|
|
|
|
setClosed(closed);
|
|
|
|
|
|
|
|
const auto api = &session().api();
|
|
|
|
const auto weak = base::make_weak(this);
|
|
|
|
api->request(MTPchannels_EditForumTopic(
|
|
|
|
MTP_flags(MTPchannels_EditForumTopic::Flag::f_closed),
|
|
|
|
channel()->inputChannel,
|
|
|
|
MTP_int(_rootId),
|
|
|
|
MTPstring(), // title
|
|
|
|
MTPlong(), // icon_emoji_id
|
|
|
|
MTP_bool(closed)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
api->applyUpdates(result);
|
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
if (error.type() != u"TOPIC_NOT_MODIFIED") {
|
|
|
|
if (const auto topic = weak.get()) {
|
|
|
|
topic->forum()->requestTopic(topic->rootId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2022-09-20 18:12:30 +00:00
|
|
|
void ForumTopic::indexTitleParts() {
|
|
|
|
_titleWords.clear();
|
|
|
|
_titleFirstLetters.clear();
|
|
|
|
auto toIndexList = QStringList();
|
|
|
|
auto appendToIndex = [&](const QString &value) {
|
|
|
|
if (!value.isEmpty()) {
|
|
|
|
toIndexList.push_back(TextUtilities::RemoveAccents(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
appendToIndex(_title);
|
|
|
|
const auto appendTranslit = !toIndexList.isEmpty()
|
|
|
|
&& cRussianLetters().match(toIndexList.front()).hasMatch();
|
|
|
|
if (appendTranslit) {
|
|
|
|
appendToIndex(translitRusEng(toIndexList.front()));
|
|
|
|
}
|
|
|
|
auto toIndex = toIndexList.join(' ');
|
|
|
|
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
|
|
|
|
|
|
|
const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
|
|
|
|
for (const auto &name : namesList) {
|
|
|
|
_titleWords.insert(name);
|
|
|
|
_titleFirstLetters.insert(name[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ForumTopic::chatListNameVersion() const {
|
|
|
|
return _titleVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::applyTopicTopMessage(MsgId topMessageId) {
|
|
|
|
if (topMessageId) {
|
2022-10-14 13:25:05 +00:00
|
|
|
growLastKnownServerMessageId(topMessageId);
|
2022-10-12 12:57:17 +00:00
|
|
|
const auto itemId = FullMsgId(channel()->id, topMessageId);
|
2022-09-20 18:12:30 +00:00
|
|
|
if (const auto item = owner().message(itemId)) {
|
|
|
|
setLastServerMessage(item);
|
2022-10-06 15:11:26 +00:00
|
|
|
|
|
|
|
// If we set a single album part, request the full album.
|
|
|
|
if (item->groupId() != MessageGroupId()) {
|
|
|
|
if (owner().groups().isGroupOfOne(item)
|
|
|
|
&& !item->toPreview({
|
|
|
|
.hideSender = true,
|
|
|
|
.hideCaption = true }).images.empty()
|
|
|
|
&& _requestedGroups.emplace(item->fullId()).second) {
|
|
|
|
owner().histories().requestGroupAround(item);
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 18:12:30 +00:00
|
|
|
} else {
|
|
|
|
setLastServerMessage(nullptr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setLastServerMessage(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void ForumTopic::growLastKnownServerMessageId(MsgId id) {
|
|
|
|
_lastKnownServerMessageId = std::max(_lastKnownServerMessageId, id);
|
|
|
|
}
|
|
|
|
|
2022-09-20 18:12:30 +00:00
|
|
|
void ForumTopic::setLastServerMessage(HistoryItem *item) {
|
2022-10-14 13:25:05 +00:00
|
|
|
if (item) {
|
|
|
|
growLastKnownServerMessageId(item->id);
|
|
|
|
}
|
2022-09-20 18:12:30 +00:00
|
|
|
_lastServerMessage = item;
|
|
|
|
if (_lastMessage
|
|
|
|
&& *_lastMessage
|
|
|
|
&& !(*_lastMessage)->isRegular()
|
|
|
|
&& (!item || (*_lastMessage)->date() > item->date())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setLastMessage(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::setLastMessage(HistoryItem *item) {
|
|
|
|
if (_lastMessage && *_lastMessage == item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_lastMessage = item;
|
|
|
|
if (!item || item->isRegular()) {
|
|
|
|
_lastServerMessage = item;
|
2022-10-14 13:25:05 +00:00
|
|
|
if (item) {
|
|
|
|
growLastKnownServerMessageId(item->id);
|
|
|
|
}
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
setChatListMessage(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::setChatListMessage(HistoryItem *item) {
|
|
|
|
if (_chatListMessage && *_chatListMessage == item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto was = _chatListMessage.value_or(nullptr);
|
|
|
|
if (item) {
|
|
|
|
if (item->isSponsored()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_chatListMessage
|
|
|
|
&& *_chatListMessage
|
|
|
|
&& !(*_chatListMessage)->isRegular()
|
|
|
|
&& (*_chatListMessage)->date() > item->date()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_chatListMessage = item;
|
|
|
|
setChatListTimeId(item->date());
|
|
|
|
} else if (!_chatListMessage || *_chatListMessage) {
|
|
|
|
_chatListMessage = nullptr;
|
|
|
|
updateChatListEntry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::loadUserpic() {
|
2022-09-27 16:52:35 +00:00
|
|
|
if (_icon) {
|
|
|
|
[[maybe_unused]] const auto preload = _icon->ready();
|
|
|
|
}
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
std::shared_ptr<Data::CloudImageView> &view,
|
2022-09-29 10:33:17 +00:00
|
|
|
const Dialogs::Ui::PaintContext &context) const {
|
2022-10-04 17:02:40 +00:00
|
|
|
const auto &st = context.st;
|
2022-10-05 07:42:44 +00:00
|
|
|
const auto position = QPoint(st->padding.left(), st->padding.top());
|
2022-09-27 16:52:35 +00:00
|
|
|
if (_icon) {
|
|
|
|
_icon->paint(p, {
|
|
|
|
.preview = st::windowBgOver->c,
|
2022-09-29 10:33:17 +00:00
|
|
|
.now = context.now,
|
2022-10-05 07:42:44 +00:00
|
|
|
.position = position,
|
2022-09-29 10:33:17 +00:00
|
|
|
.paused = context.paused,
|
2022-09-27 16:52:35 +00:00
|
|
|
});
|
2022-10-04 17:02:40 +00:00
|
|
|
} else {
|
2022-10-05 07:42:44 +00:00
|
|
|
validateDefaultIcon();
|
|
|
|
const auto size = st::defaultForumTopicIcon.size;
|
|
|
|
const auto esize = st::emojiSize;
|
|
|
|
const auto shift = (esize - size) / 2;
|
2022-10-06 13:06:18 +00:00
|
|
|
p.drawImage(
|
|
|
|
position + st::forumTopicIconPosition + QPoint(shift, 0),
|
|
|
|
_defaultIcon);
|
2022-10-05 07:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::validateDefaultIcon() const {
|
|
|
|
if (_defaultIcon.isNull()) {
|
|
|
|
_defaultIcon = ForumTopicIconFrame(
|
|
|
|
_colorId,
|
|
|
|
_title,
|
|
|
|
st::defaultForumTopicIcon);
|
2022-09-27 16:52:35 +00:00
|
|
|
}
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::requestChatListMessage() {
|
2022-10-06 16:06:24 +00:00
|
|
|
if (!chatListMessageKnown() && !forum()->creating(_rootId)) {
|
|
|
|
forum()->requestTopic(_rootId);
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeId ForumTopic::adjustedChatListTimeId() const {
|
|
|
|
const auto result = chatListTimeId();
|
2022-10-17 16:29:48 +00:00
|
|
|
if (const auto draft = history()->cloudDraft(_rootId)) {
|
|
|
|
if (!Data::DraftIsNull(draft) && !session().supportMode()) {
|
2022-09-20 18:12:30 +00:00
|
|
|
return std::max(result, draft->date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ForumTopic::fixedOnTopIndex() const {
|
2022-09-23 19:21:31 +00:00
|
|
|
return 0;
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ForumTopic::shouldBeInChatList() const {
|
|
|
|
return isPinnedDialog(FilterId())
|
|
|
|
|| !lastMessageKnown()
|
|
|
|
|| (lastMessage() != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *ForumTopic::lastMessage() const {
|
|
|
|
return _lastMessage.value_or(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ForumTopic::lastMessageKnown() const {
|
|
|
|
return _lastMessage.has_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *ForumTopic::lastServerMessage() const {
|
|
|
|
return _lastServerMessage.value_or(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ForumTopic::lastServerMessageKnown() const {
|
|
|
|
return _lastServerMessage.has_value();
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
MsgId ForumTopic::lastKnownServerMessageId() const {
|
|
|
|
return _lastKnownServerMessageId;
|
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
QString ForumTopic::title() const {
|
|
|
|
return _title;
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
void ForumTopic::applyTitle(const QString &title) {
|
2022-10-13 08:46:30 +00:00
|
|
|
if (_title == title) {
|
2022-09-23 19:21:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-13 08:46:30 +00:00
|
|
|
_title = title;
|
2022-09-23 19:21:31 +00:00
|
|
|
++_titleVersion;
|
2022-10-05 07:42:44 +00:00
|
|
|
_defaultIcon = QImage();
|
2022-09-23 19:21:31 +00:00
|
|
|
indexTitleParts();
|
|
|
|
updateChatListEntry();
|
2022-10-14 16:53:06 +00:00
|
|
|
session().changes().topicUpdated(this, UpdateFlag::Title);
|
2022-09-23 19:21:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
DocumentId ForumTopic::iconId() const {
|
|
|
|
return _iconId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::applyIconId(DocumentId iconId) {
|
2022-10-14 16:53:06 +00:00
|
|
|
if (_iconId == iconId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_iconId = iconId;
|
|
|
|
_icon = iconId
|
|
|
|
? owner().customEmojiManager().create(
|
|
|
|
_iconId,
|
|
|
|
[=] { updateChatListEntry(); },
|
|
|
|
Data::CustomEmojiManager::SizeTag::Normal)
|
|
|
|
: nullptr;
|
|
|
|
if (iconId) {
|
|
|
|
_defaultIcon = QImage();
|
2022-09-27 16:52:35 +00:00
|
|
|
}
|
2022-09-27 12:05:47 +00:00
|
|
|
updateChatListEntry();
|
2022-10-18 12:38:43 +00:00
|
|
|
session().changes().topicUpdated(this, UpdateFlag::IconId);
|
2022-09-27 12:05:47 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 07:42:44 +00:00
|
|
|
int32 ForumTopic::colorId() const {
|
|
|
|
return _colorId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::applyColorId(int32 colorId) {
|
2022-10-18 12:38:43 +00:00
|
|
|
if (_colorId != colorId) {
|
|
|
|
_colorId = colorId;
|
|
|
|
session().changes().topicUpdated(this, UpdateFlag::ColorId);
|
|
|
|
}
|
2022-10-05 07:42:44 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
void ForumTopic::applyItemAdded(not_null<HistoryItem*> item) {
|
|
|
|
setLastMessage(item);
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
void ForumTopic::maybeSetLastMessage(not_null<HistoryItem*> item) {
|
|
|
|
Expects(item->topicRootId() == _rootId);
|
|
|
|
|
|
|
|
if (!_lastMessage
|
|
|
|
|| ((*_lastMessage)->date() < item->date())
|
|
|
|
|| ((*_lastMessage)->date() == item->date()
|
|
|
|
&& (*_lastMessage)->id < item->id)) {
|
|
|
|
setLastMessage(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
void ForumTopic::applyItemRemoved(MsgId id) {
|
|
|
|
if (const auto lastItem = lastMessage()) {
|
|
|
|
if (lastItem->id == id) {
|
|
|
|
_lastMessage = std::nullopt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (const auto lastServerItem = lastServerMessage()) {
|
|
|
|
if (lastServerItem->id == id) {
|
|
|
|
_lastServerMessage = std::nullopt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (const auto chatListItem = _chatListMessage.value_or(nullptr)) {
|
|
|
|
if (chatListItem->id == id) {
|
|
|
|
_chatListMessage = std::nullopt;
|
2022-10-06 16:06:24 +00:00
|
|
|
requestChatListMessage();
|
2022-09-23 19:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
bool ForumTopic::isServerSideUnread(
|
|
|
|
not_null<const HistoryItem*> item) const {
|
|
|
|
return _replies->isServerSideUnread(item);
|
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
void ForumTopic::setMuted(bool muted) {
|
2022-10-12 20:23:14 +00:00
|
|
|
if (this->muted() == muted) {
|
2022-10-13 10:32:03 +00:00
|
|
|
return;
|
2022-10-12 20:23:14 +00:00
|
|
|
}
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto state = chatListBadgesState();
|
|
|
|
const auto notify = state.unread || state.reaction;
|
2022-10-12 20:23:14 +00:00
|
|
|
const auto notifier = unreadStateChangeNotifier(notify);
|
2022-10-13 10:32:03 +00:00
|
|
|
Thread::setMuted(muted);
|
2022-10-20 08:57:12 +00:00
|
|
|
session().changes().topicUpdated(
|
|
|
|
this,
|
|
|
|
Data::TopicUpdate::Flag::Notifications);
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
not_null<HistoryView::SendActionPainter*> ForumTopic::sendActionPainter() {
|
|
|
|
return _sendActionPainter.get();
|
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
Dialogs::UnreadState ForumTopic::chatListUnreadState() const {
|
|
|
|
return unreadStateFor(
|
2022-10-20 09:33:04 +00:00
|
|
|
_replies->displayedUnreadCount(),
|
2022-10-20 08:57:12 +00:00
|
|
|
_replies->unreadCountKnown());
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
Dialogs::BadgesState ForumTopic::chatListBadgesState() const {
|
|
|
|
return Dialogs::BadgesForUnread(
|
|
|
|
chatListUnreadState(),
|
|
|
|
Dialogs::CountInBadge::Messages,
|
|
|
|
Dialogs::IncludeInBadge::All);
|
2022-10-07 11:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialogs::UnreadState ForumTopic::unreadStateFor(
|
|
|
|
int count,
|
|
|
|
bool known) const {
|
2022-09-20 18:12:30 +00:00
|
|
|
auto result = Dialogs::UnreadState();
|
2022-10-12 20:23:14 +00:00
|
|
|
const auto muted = this->muted();
|
2022-09-20 18:12:30 +00:00
|
|
|
result.messages = count;
|
|
|
|
result.chats = count ? 1 : 0;
|
2022-10-20 08:57:12 +00:00
|
|
|
result.mentions = unreadMentions().has() ? 1 : 0;
|
|
|
|
result.reactions = unreadReactions().has() ? 1 : 0;
|
|
|
|
result.messagesMuted = muted ? result.messages : 0;
|
|
|
|
result.chatsMuted = muted ? result.chats : 0;
|
|
|
|
result.reactionsMuted = muted ? result.reactions : 0;
|
2022-10-07 11:46:27 +00:00
|
|
|
result.known = known;
|
2022-09-20 18:12:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *ForumTopic::chatListMessage() const {
|
|
|
|
return _lastMessage.value_or(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ForumTopic::chatListMessageKnown() const {
|
|
|
|
return _lastMessage.has_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &ForumTopic::chatListName() const {
|
|
|
|
return _title;
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<QString> &ForumTopic::chatListNameWords() const {
|
|
|
|
return _titleWords;
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<QChar> &ForumTopic::chatListFirstLetters() const {
|
|
|
|
return _titleFirstLetters;
|
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
void ForumTopic::hasUnreadMentionChanged(bool has) {
|
|
|
|
auto was = chatListUnreadState();
|
|
|
|
if (has) {
|
|
|
|
was.mentions = 0;
|
|
|
|
} else {
|
|
|
|
was.mentions = 1;
|
|
|
|
}
|
|
|
|
notifyUnreadStateChange(was);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForumTopic::hasUnreadReactionChanged(bool has) {
|
|
|
|
auto was = chatListUnreadState();
|
|
|
|
if (has) {
|
|
|
|
was.reactions = was.reactionsMuted = 0;
|
|
|
|
} else {
|
|
|
|
was.reactions = 1;
|
|
|
|
was.reactionsMuted = muted() ? was.reactions : 0;
|
|
|
|
}
|
|
|
|
notifyUnreadStateChange(was);
|
|
|
|
}
|
|
|
|
|
2022-09-20 18:12:30 +00:00
|
|
|
const QString &ForumTopic::chatListNameSortKey() const {
|
|
|
|
static const auto empty = QString();
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Data
|