Request full album for last topic message.

This commit is contained in:
John Preston 2022-10-06 19:11:26 +04:00
parent 377b86372b
commit 032e6c57e9
16 changed files with 58 additions and 35 deletions

View File

@ -337,7 +337,7 @@ void EditForumTopicBox(
const auto topic = (!creating && forum->peer->forum())
? forum->peer->forum()->topicFor(rootId)
: nullptr;
// #TODO forum lang
// #TODO lang-forum
box->setTitle(rpl::single(creating ? u"New topic"_q : u"Edit topic"_q));
box->setMaxHeight(st::editTopicMaxHeight);
@ -365,7 +365,7 @@ void EditForumTopicBox(
object_ptr<Ui::InputField>(
box,
st::defaultInputField,
rpl::single(u"Topic Title"_q), // #TODO forum lang
rpl::single(u"Topic Title"_q), // #TODO lang-forum
topic ? topic->title() : QString()),
st::editTopicTitleMargin);
box->setFocusCallback([=] {

View File

@ -818,7 +818,7 @@ void Controller::fillForumButton() {
AddButtonWithText(
_controls.buttonsLayout,
rpl::single(u"Topics"_q), // #TODO forum lang
rpl::single(u"Topics"_q), // #TODO lang-forum
rpl::single(QString()),
[] {},
{ &st::settingsIconGroup, Settings::kIconPurple }

View File

@ -203,7 +203,7 @@ ForumTopic *Forum::topicFor(MsgId rootId) {
return i->second.get();
}
} else {
// #TODO forum lang
// #TODO lang-forum
applyTopicAdded(rootId, "General! Created.", kGeneralColorId, 0);
return _topics.find(rootId)->second.get();
}

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_forum.h"
#include "data/data_histories.h"
#include "data/data_session.h"
#include "data/stickers/data_custom_emoji.h"
#include "dialogs/dialogs_main_list.h"
@ -17,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/core_settings.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/view/history_view_item_preview.h"
#include "ui/painter.h"
#include "ui/color_int_conversion.h"
#include "styles/style_dialogs.h"
@ -229,6 +231,17 @@ void ForumTopic::applyTopicTopMessage(MsgId topMessageId) {
const auto itemId = FullMsgId(_history->peer->id, topMessageId);
if (const auto item = owner().message(itemId)) {
setLastServerMessage(item);
// 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);
}
}
} else {
setLastServerMessage(nullptr);
}
@ -276,16 +289,6 @@ void ForumTopic::setChatListMessage(HistoryItem *item) {
}
_chatListMessage = item;
setChatListTimeId(item->date());
#if 0 // #TODO forum
// If we have a single message from a group, request the full album.
if (hasOrphanMediaGroupPart()
&& !item->toPreview({
.hideSender = true,
.hideCaption = true }).images.empty()) {
owner().histories().requestGroupAround(item);
}
#endif
} else if (!_chatListMessage || *_chatListMessage) {
_chatListMessage = nullptr;
updateChatListEntry();
@ -402,7 +405,7 @@ void ForumTopic::applyTitle(const QString &title) {
if (_title == title || (isGeneral() && !_title.isEmpty())) {
return;
}
_title = isGeneral() ? "General! Topic." : title; // #TODO forum lang
_title = isGeneral() ? "General! Topic." : title; // #TODO lang-forum
++_titleVersion;
_defaultIcon = QImage();
indexTitleParts();

View File

@ -147,6 +147,7 @@ private:
std::optional<HistoryItem*> _lastMessage;
std::optional<HistoryItem*> _lastServerMessage;
std::optional<HistoryItem*> _chatListMessage;
base::flat_set<FullMsgId> _requestedGroups;
bool _unreadMark = false;
rpl::lifetime _lifetime;

View File

@ -33,6 +33,14 @@ bool Groups::isGrouped(not_null<const HistoryItem*> item) const {
return media && media->canBeGrouped();
}
bool Groups::isGroupOfOne(not_null<const HistoryItem*> item) const {
if (const auto groupId = item->groupId()) {
const auto i = _groups.find(groupId);
return (i != _groups.end()) && (i->second.items.size() == 1);
}
return false;
}
void Groups::registerMessage(not_null<HistoryItem*> item) {
if (!isGrouped(item)) {
return;
@ -146,12 +154,7 @@ void Groups::refreshViews(const HistoryItemsList &items) {
const auto history = items.front()->history();
for (const auto &item : items) {
_data->requestItemViewRefresh(item);
history->lastItemDialogsView.itemInvalidated(item);
if (const auto forum = history->peer->forum()) {
if (const auto topic = forum->topicFor(item)) {
topic->lastItemDialogsView.itemInvalidated(item);
}
}
item->invalidateChatListEntry();
}
}

View File

@ -22,6 +22,7 @@ public:
Groups(not_null<Session*> data);
[[nodiscard]] bool isGrouped(not_null<const HistoryItem*> item) const;
[[nodiscard]] bool isGroupOfOne(not_null<const HistoryItem*> item) const;
void registerMessage(not_null<HistoryItem*> item);
void unregisterMessage(not_null<const HistoryItem*> item);
void refreshMessage(

View File

@ -445,7 +445,8 @@ void Histories::requestFakeChatListMessage(
void Histories::requestGroupAround(not_null<HistoryItem*> item) {
const auto history = item->history();
const auto id = item->id;
const auto i = _chatListGroupRequests.find(history);
const auto key = GroupRequestKey{ history, item->topicRootId() };
const auto i = _chatListGroupRequests.find(key);
if (i != end(_chatListGroupRequests)) {
if (i->second.aroundId == id) {
return;
@ -470,18 +471,18 @@ void Histories::requestGroupAround(not_null<HistoryItem*> item) {
_owner->processExistingMessages(
history->peer->asChannel(),
result);
_chatListGroupRequests.remove(history);
_chatListGroupRequests.remove(key);
history->migrateToOrMe()->applyChatListGroup(
history->peer->id,
result);
finish();
}).fail([=] {
_chatListGroupRequests.remove(history);
_chatListGroupRequests.remove(key);
finish();
}).send();
});
_chatListGroupRequests.emplace(
history,
key,
ChatListGroupRequest{ .aroundId = id, .requestId = requestId });
}

View File

@ -152,6 +152,14 @@ private:
Fn<void(const MTP::Error&, const MTP::Response&)> fail;
int requestId = 0;
};
struct GroupRequestKey {
not_null<History*> history;
MsgId rootId = 0;
friend inline constexpr auto operator<=>(
GroupRequestKey,
GroupRequestKey) = default;
};
template <typename Arg>
static auto ReplaceReplyTo(Arg arg, MsgId replyTo) {
@ -203,7 +211,7 @@ private:
base::flat_set<not_null<History*>> _fakeChatListRequests;
base::flat_map<
not_null<History*>,
GroupRequestKey,
ChatListGroupRequest> _chatListGroupRequests;
base::flat_map<

View File

@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_messages.h"
#include "data/data_media_types.h"
#include "data/data_folder.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
@ -374,6 +375,11 @@ void HistoryItem::invalidateChatListEntry() {
this,
Data::MessageUpdate::Flag::DialogRowRefresh);
history()->lastItemDialogsView.itemInvalidated(this);
if (const auto forum = history()->peer->forum()) {
if (const auto topic = forum->topicFor(this)) {
topic->lastItemDialogsView.itemInvalidated(this);
}
}
}
void HistoryItem::customEmojiRepaint() {

View File

@ -138,6 +138,8 @@ public:
void clearMainView();
void removeMainView();
void invalidateChatListEntry();
void destroy();
[[nodiscard]] bool out() const {
return _flags & MessageFlag::Outgoing;
@ -477,8 +479,6 @@ protected:
const not_null<PeerData*> _from;
MessageFlags _flags = 0;
void invalidateChatListEntry();
void setGroupId(MessageGroupId groupId);
void applyTTL(const MTPDmessage &data);

View File

@ -638,15 +638,15 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
auto prepareTopicCreate = [&](const MTPDmessageActionTopicCreate &action) {
auto result = PreparedText{};
// #TODO forum lang
// #TODO lang-forum
result.text = { "topic created: " + qs(action.vtitle()) };
return result;
};
auto prepareTopicEdit = [&](const MTPDmessageActionTopicEdit &action) {
auto result = PreparedText{};
// #TODO forum lang
result.text = { "topic edited: " }; // #TODO forum lang
// #TODO lang-forum
result.text = { "topic edited: " };
if (const auto icon = action.vicon_emoji_id()) {
result.text.append(TextWithEntities{
"@",

View File

@ -1611,7 +1611,7 @@ bool RepliesWidget::preventsClose(Fn<void()> &&continueCallback) const {
}
};
controller()->show(Ui::MakeConfirmBox({
.text = rpl::single(u"Sure discard?"_q), // #TODO forum lang
.text = rpl::single(u"Sure discard?"_q), // #TODO lang-forum
.confirmed = std::move(sure),
.confirmText = tr::lng_record_lock_discard(),
.confirmStyle = &st::attentionBoxButton,

View File

@ -81,7 +81,7 @@ void Widget::setInnerFocus() {
rpl::producer<QString> Widget::title() {
if (const auto topic = controller()->key().topic()) {
return rpl::single(u"Topic Info"_q); // #TODO forum lang
return rpl::single(u"Topic Info"_q); // #TODO lang-forum
}
const auto peer = controller()->key().peer();
if (const auto user = peer->asUser()) {

View File

@ -1961,7 +1961,7 @@ void MainWidget::windowShown() {
void MainWidget::dialogsToUp() {
if (_dialogs) {
_dialogs->jumpToTop();
_dialogs->jumpToTop(true);
}
}

View File

@ -751,7 +751,7 @@ void Filler::addManageTopic() {
if (!_topic) {
return;
}
// #TODO forum lang
// #TODO lang-forum
const auto history = _topic->history();
const auto rootId = _topic->rootId();
const auto navigation = _controller;