Support General topic somehow.

This commit is contained in:
John Preston 2022-11-29 15:54:47 +04:00
parent 8cd5105813
commit 57af221d39
12 changed files with 29 additions and 27 deletions

View file

@ -689,7 +689,7 @@ QString ApiWrap::exportDirectMessageLink(
auto linkItemId = item->id;
auto linkCommentId = MsgId();
auto linkThreadId = MsgId();
//auto linkThreadIsTopic = false;
auto linkThreadIsTopic = false;
if (inRepliesContext) {
if (const auto rootId = item->replyToTop()) {
const auto root = item->history()->owner().message(
@ -711,7 +711,7 @@ QString ApiWrap::exportDirectMessageLink(
} else {
// Reply in a thread, maybe comment in a private channel.
linkThreadId = rootId;
//linkThreadIsTopic = (item->topicRootId() == rootId);
linkThreadIsTopic = (item->topicRootId() == rootId);
}
}
}
@ -723,7 +723,7 @@ QString ApiWrap::exportDirectMessageLink(
+ '/'
+ (linkCommentId
? (post + "?comment=" + QString::number(linkCommentId.bare))
: (linkThreadId/* && !linkThreadIsTopic*/)
: (linkThreadId && !linkThreadIsTopic)
? (post + "?thread=" + QString::number(linkThreadId.bare))
: linkThreadId
? (QString::number(linkThreadId.bare) + '/' + post)

View file

@ -51,6 +51,8 @@ class Forum;
class ForumTopic final : public Thread {
public:
static constexpr auto kGeneralId = 1;
ForumTopic(not_null<Forum*> forum, MsgId rootId);
~ForumTopic();
@ -58,6 +60,10 @@ public:
return history();
}
[[nodiscard]] bool isGeneral() const {
return (_rootId == kGeneralId);
}
[[nodiscard]] std::shared_ptr<RepliesList> replies() const;
[[nodiscard]] not_null<ChannelData*> channel() const;
[[nodiscard]] not_null<History*> history() const;

View file

@ -304,7 +304,7 @@ void RepliesList::injectRootMessage(not_null<Viewer*> viewer) {
return;
}
const auto root = lookupRoot();
if (!root || root->topicRootId()) {
if (!root || root->topicRootId() != Data::ForumTopic::kGeneralId) {
return;
}
injectRootDivider(root, slice);

View file

@ -2088,14 +2088,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
const auto itemId = item->fullId();
const auto canReply = [&] {
const auto peer = item->history()->peer;
if (const auto forum = peer->forum()) {
const auto topicRootId = item->topicRootId();
const auto topic = item->topic();
return topic
? topic->canWrite()
: peer->canWrite(!topicRootId);
}
return peer->canWrite();
const auto topic = item->topic();
return topic ? topic->canWrite() : peer->canWrite();
}();
if (canReply) {
_menu->addAction(tr::lng_context_reply_msg(tr::now), [=] {

View file

@ -231,7 +231,8 @@ MsgId LookupReplyToTop(HistoryItem *replyTo) {
}
bool LookupReplyIsTopicPost(HistoryItem *replyTo) {
return replyTo && (replyTo->topicRootId() != 0);
return replyTo
&& (replyTo->topicRootId() != Data::ForumTopic::kGeneralId);
}
MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) {
@ -1502,7 +1503,7 @@ MsgId HistoryMessage::topicRootId() const {
; reply && reply->topicPost) {
return reply->replyToTop();
}
return 0;
return Data::ForumTopic::kGeneralId;
}
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {

View file

@ -1344,7 +1344,7 @@ MsgId HistoryService::topicRootId() const {
} else if (Has<HistoryServiceTopicInfo>()) {
return id;
}
return 0;
return Data::ForumTopic::kGeneralId;
}
void HistoryService::setReplyFields(

View file

@ -6721,7 +6721,7 @@ void HistoryWidget::processReply() {
return processCancel();
} else if (const auto forum = _peer->forum()) {
const auto topicRootId = _processingReplyItem->topicRootId();
if (!topicRootId || forum->topicDeleted(topicRootId)) {
if (forum->topicDeleted(topicRootId)) {
return processCancel();
} else if (const auto topic = forum->topicFor(topicRootId)) {
if (!topic->canWrite()) {

View file

@ -686,7 +686,7 @@ auto Element::contextDependentServiceText() -> TextWithLinks {
}
const auto peerId = item->history()->peer->id;
const auto topicRootId = item->topicRootId();
if (!topicRootId || !peerIsChannel(peerId)) {
if (!peerIsChannel(peerId)) {
return {};
}
const auto from = item->from();

View file

@ -2711,13 +2711,8 @@ bool Message::displayFastReply() const {
const auto canWrite = [&] {
const auto item = data();
const auto peer = item->history()->peer;
if (peer->isForum()) {
const auto topic = item->topic();
return topic
? topic->canWrite()
: peer->canWrite(!item->topicRootId());
}
return peer->canWrite();
const auto topic = item->topic();
return topic ? topic->canWrite() : peer->canWrite();
};
return hasFastReply()

View file

@ -1467,7 +1467,11 @@ void RepliesWidget::refreshTopBarActiveChat() {
MsgId RepliesWidget::replyToId() const {
const auto custom = _composeControls->replyingToMessage().msg;
return custom ? custom : _rootId;
return custom
? custom
: (_rootId == Data::ForumTopic::kGeneralId)
? MsgId()
: _rootId;
}
void RepliesWidget::refreshUnreadCountBadge(std::optional<int> count) {

View file

@ -4166,9 +4166,9 @@ void OverlayWidget::setContext(
not_null<PeerData*>> context) {
if (const auto item = std::get_if<ItemContext>(&context)) {
_message = item->item;
_topicRootId = item->topicRootId;
_history = _message->history();
_peer = _history->peer;
_topicRootId = _peer->isForum() ? item->topicRootId : MsgId();
} else if (const auto peer = std::get_if<not_null<PeerData*>>(&context)) {
_peer = *peer;
_history = _peer->owner().history(_peer);

View file

@ -257,10 +257,12 @@ void Uploader::sendProgressUpdate(
const auto history = item->history();
auto &manager = _api->session().sendProgressManager();
manager.update(history, type, progress);
if (const auto replyTo = item->topicRootId()) {
if (const auto replyTo = item->replyToTop()) {
if (history->peer->isMegagroup()) {
manager.update(history, replyTo, type, progress);
}
} else if (history->peer->isForum()) {
manager.update(history, item->topicRootId(), type, progress);
}
_api->session().data().requestItemRepaint(item);
}