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

View file

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

View file

@ -203,7 +203,7 @@ ForumTopic *Forum::topicFor(MsgId rootId) {
return i->second.get(); return i->second.get();
} }
} else { } else {
// #TODO forum lang // #TODO lang-forum
applyTopicAdded(rootId, "General! Created.", kGeneralColorId, 0); applyTopicAdded(rootId, "General! Created.", kGeneralColorId, 0);
return _topics.find(rootId)->second.get(); 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_channel.h"
#include "data/data_forum.h" #include "data/data_forum.h"
#include "data/data_histories.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "dialogs/dialogs_main_list.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 "core/core_settings.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/view/history_view_item_preview.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/color_int_conversion.h" #include "ui/color_int_conversion.h"
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
@ -229,6 +231,17 @@ void ForumTopic::applyTopicTopMessage(MsgId topMessageId) {
const auto itemId = FullMsgId(_history->peer->id, topMessageId); const auto itemId = FullMsgId(_history->peer->id, topMessageId);
if (const auto item = owner().message(itemId)) { if (const auto item = owner().message(itemId)) {
setLastServerMessage(item); 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 { } else {
setLastServerMessage(nullptr); setLastServerMessage(nullptr);
} }
@ -276,16 +289,6 @@ void ForumTopic::setChatListMessage(HistoryItem *item) {
} }
_chatListMessage = item; _chatListMessage = item;
setChatListTimeId(item->date()); 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) { } else if (!_chatListMessage || *_chatListMessage) {
_chatListMessage = nullptr; _chatListMessage = nullptr;
updateChatListEntry(); updateChatListEntry();
@ -402,7 +405,7 @@ void ForumTopic::applyTitle(const QString &title) {
if (_title == title || (isGeneral() && !_title.isEmpty())) { if (_title == title || (isGeneral() && !_title.isEmpty())) {
return; return;
} }
_title = isGeneral() ? "General! Topic." : title; // #TODO forum lang _title = isGeneral() ? "General! Topic." : title; // #TODO lang-forum
++_titleVersion; ++_titleVersion;
_defaultIcon = QImage(); _defaultIcon = QImage();
indexTitleParts(); indexTitleParts();

View file

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

View file

@ -33,6 +33,14 @@ bool Groups::isGrouped(not_null<const HistoryItem*> item) const {
return media && media->canBeGrouped(); 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) { void Groups::registerMessage(not_null<HistoryItem*> item) {
if (!isGrouped(item)) { if (!isGrouped(item)) {
return; return;
@ -146,12 +154,7 @@ void Groups::refreshViews(const HistoryItemsList &items) {
const auto history = items.front()->history(); const auto history = items.front()->history();
for (const auto &item : items) { for (const auto &item : items) {
_data->requestItemViewRefresh(item); _data->requestItemViewRefresh(item);
history->lastItemDialogsView.itemInvalidated(item); item->invalidateChatListEntry();
if (const auto forum = history->peer->forum()) {
if (const auto topic = forum->topicFor(item)) {
topic->lastItemDialogsView.itemInvalidated(item);
}
}
} }
} }

View file

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

View file

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

View file

@ -152,6 +152,14 @@ private:
Fn<void(const MTP::Error&, const MTP::Response&)> fail; Fn<void(const MTP::Error&, const MTP::Response&)> fail;
int requestId = 0; int requestId = 0;
}; };
struct GroupRequestKey {
not_null<History*> history;
MsgId rootId = 0;
friend inline constexpr auto operator<=>(
GroupRequestKey,
GroupRequestKey) = default;
};
template <typename Arg> template <typename Arg>
static auto ReplaceReplyTo(Arg arg, MsgId replyTo) { static auto ReplaceReplyTo(Arg arg, MsgId replyTo) {
@ -203,7 +211,7 @@ private:
base::flat_set<not_null<History*>> _fakeChatListRequests; base::flat_set<not_null<History*>> _fakeChatListRequests;
base::flat_map< base::flat_map<
not_null<History*>, GroupRequestKey,
ChatListGroupRequest> _chatListGroupRequests; ChatListGroupRequest> _chatListGroupRequests;
base::flat_map< 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_messages.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "data/data_folder.h" #include "data/data_folder.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h" #include "data/data_forum_topic.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_chat.h" #include "data/data_chat.h"
@ -374,6 +375,11 @@ void HistoryItem::invalidateChatListEntry() {
this, this,
Data::MessageUpdate::Flag::DialogRowRefresh); Data::MessageUpdate::Flag::DialogRowRefresh);
history()->lastItemDialogsView.itemInvalidated(this); 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() { void HistoryItem::customEmojiRepaint() {

View file

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

View file

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

View file

@ -1611,7 +1611,7 @@ bool RepliesWidget::preventsClose(Fn<void()> &&continueCallback) const {
} }
}; };
controller()->show(Ui::MakeConfirmBox({ 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), .confirmed = std::move(sure),
.confirmText = tr::lng_record_lock_discard(), .confirmText = tr::lng_record_lock_discard(),
.confirmStyle = &st::attentionBoxButton, .confirmStyle = &st::attentionBoxButton,

View file

@ -81,7 +81,7 @@ void Widget::setInnerFocus() {
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {
if (const auto topic = controller()->key().topic()) { 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(); const auto peer = controller()->key().peer();
if (const auto user = peer->asUser()) { if (const auto user = peer->asUser()) {

View file

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

View file

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