mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Allow editing topic title and icon.
This commit is contained in:
@@ -165,60 +165,4 @@ rpl::producer<> Forum::chatsListLoadedEvents() const {
|
||||
return _chatsListLoadedEvents.events();
|
||||
}
|
||||
|
||||
void ShowAddForumTopic(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<ChannelData*> forum) {
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
box->setTitle(rpl::single(u"New Topic"_q));
|
||||
|
||||
const auto title = box->addRow(
|
||||
object_ptr<Ui::InputField>(
|
||||
box,
|
||||
st::defaultInputField,
|
||||
rpl::single(u"Topic Title"_q))); // #TODO forum lang
|
||||
const auto message = box->addRow(
|
||||
object_ptr<Ui::InputField>(
|
||||
box,
|
||||
st::newGroupDescription,
|
||||
Ui::InputField::Mode::MultiLine,
|
||||
rpl::single(u"Message"_q))); // #TODO forum lang
|
||||
box->setFocusCallback([=] {
|
||||
title->setFocusFast();
|
||||
});
|
||||
box->addButton(tr::lng_create_group_create(), [=] {
|
||||
if (!forum->isForum()) {
|
||||
box->closeBox();
|
||||
return;
|
||||
} else if (title->getLastText().trimmed().isEmpty()) {
|
||||
title->setFocus();
|
||||
return;
|
||||
} else if (message->getLastText().trimmed().isEmpty()) {
|
||||
message->setFocus();
|
||||
return;
|
||||
}
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
const auto api = &forum->session().api();
|
||||
api->request(MTPchannels_CreateForumTopic(
|
||||
MTP_flags(0),
|
||||
forum->inputChannel,
|
||||
MTP_string(title->getLastText().trimmed()),
|
||||
MTPlong(), // icon_emoji_id
|
||||
MTPInputMedia(),
|
||||
MTP_string(message->getLastText().trimmed()),
|
||||
MTP_long(randomId),
|
||||
MTPVector<MTPMessageEntity>(),
|
||||
MTPInputPeer() // send_as
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
api->applyUpdates(result, randomId);
|
||||
box->closeBox();
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
api->sendMessageFail(error, forum, randomId);
|
||||
}).send();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
}), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
@@ -59,8 +59,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
void ShowAddForumTopic(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<ChannelData*> forum);
|
||||
|
||||
} // namespace Data
|
||||
|
@@ -25,6 +25,10 @@ ForumTopic::ForumTopic(not_null<History*> forum, MsgId rootId)
|
||||
, _rootId(rootId) {
|
||||
}
|
||||
|
||||
not_null<ChannelData*> ForumTopic::channel() const {
|
||||
return _forum->peer->asChannel();
|
||||
}
|
||||
|
||||
not_null<History*> ForumTopic::forum() const {
|
||||
return _forum;
|
||||
}
|
||||
@@ -38,6 +42,11 @@ void ForumTopic::applyTopic(const MTPForumTopic &topic) {
|
||||
|
||||
const auto &data = topic.data();
|
||||
applyTitle(qs(data.vtitle()));
|
||||
if (const auto iconId = data.vicon_emoji_id()) {
|
||||
applyIconId(iconId->v);
|
||||
} else {
|
||||
applyIconId(0);
|
||||
}
|
||||
|
||||
const auto pinned = _list->pinned();
|
||||
#if 0 // #TODO forum pinned
|
||||
@@ -242,6 +251,10 @@ bool ForumTopic::lastServerMessageKnown() const {
|
||||
return _lastServerMessage.has_value();
|
||||
}
|
||||
|
||||
QString ForumTopic::title() const {
|
||||
return _title;
|
||||
}
|
||||
|
||||
void ForumTopic::applyTitle(const QString &title) {
|
||||
if (_title == title || (isGeneral() && !_title.isEmpty())) {
|
||||
return;
|
||||
@@ -252,6 +265,15 @@ void ForumTopic::applyTitle(const QString &title) {
|
||||
updateChatListEntry();
|
||||
}
|
||||
|
||||
DocumentId ForumTopic::iconId() const {
|
||||
return _iconId;
|
||||
}
|
||||
|
||||
void ForumTopic::applyIconId(DocumentId iconId) {
|
||||
_iconId = iconId;
|
||||
updateChatListEntry();
|
||||
}
|
||||
|
||||
void ForumTopic::applyItemAdded(not_null<HistoryItem*> item) {
|
||||
setLastMessage(item);
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ public:
|
||||
ForumTopic(const ForumTopic &) = delete;
|
||||
ForumTopic &operator=(const ForumTopic &) = delete;
|
||||
|
||||
[[nodiscard]] not_null<ChannelData*> channel() const;
|
||||
[[nodiscard]] not_null<History*> forum() const;
|
||||
[[nodiscard]] MsgId rootId() const;
|
||||
[[nodiscard]] bool isGeneral() const {
|
||||
@@ -62,7 +63,10 @@ public:
|
||||
[[nodiscard]] bool lastMessageKnown() const;
|
||||
[[nodiscard]] bool lastServerMessageKnown() const;
|
||||
|
||||
[[nodiscard]] QString title() const;
|
||||
void applyTitle(const QString &title);
|
||||
[[nodiscard]] DocumentId iconId() const;
|
||||
void applyIconId(DocumentId iconId);
|
||||
void applyItemAdded(not_null<HistoryItem*> item);
|
||||
void applyItemRemoved(MsgId id);
|
||||
|
||||
@@ -108,6 +112,7 @@ private:
|
||||
const MsgId _rootId = 0;
|
||||
|
||||
QString _title;
|
||||
DocumentId _iconId = 0;
|
||||
base::flat_set<QString> _titleWords;
|
||||
base::flat_set<QChar> _titleFirstLetters;
|
||||
int _titleVersion = 0;
|
||||
|
Reference in New Issue
Block a user