Show Saved Messages in Reply in another chat.

This commit is contained in:
John Preston 2023-10-29 09:52:42 +04:00
parent ec3fc8c749
commit 597816db09
7 changed files with 31 additions and 25 deletions

View file

@ -2361,6 +2361,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_saved_messages" = "Saved Messages"; "lng_saved_messages" = "Saved Messages";
"lng_saved_short" = "Save"; "lng_saved_short" = "Save";
"lng_saved_forward_here" = "Forward messages here for quick access"; "lng_saved_forward_here" = "Forward messages here for quick access";
"lng_saved_quote_here" = "Quote here to save";
"lng_scheduled_messages" = "Scheduled Messages"; "lng_scheduled_messages" = "Scheduled Messages";
"lng_scheduled_messages_empty" = "No scheduled messages here yet..."; "lng_scheduled_messages_empty" = "No scheduled messages here yet...";

View file

@ -456,7 +456,7 @@ int PeerListController::descriptionTopSkipMin() const {
void PeerListBox::addSelectItem( void PeerListBox::addSelectItem(
not_null<PeerData*> peer, not_null<PeerData*> peer,
anim::type animated) { anim::type animated) {
const auto respect = _controller->respectSavedMessagesChat(); const auto respect = !_controller->savedMessagesChatStatus().isEmpty();
const auto text = (respect && peer->isSelf()) const auto text = (respect && peer->isSelf())
? tr::lng_saved_short(tr::now) ? tr::lng_saved_short(tr::now)
: (respect && peer->isRepliesChat()) : (respect && peer->isRepliesChat())
@ -579,8 +579,8 @@ void PeerListRow::refreshStatus() {
_statusType = StatusType::LastSeen; _statusType = StatusType::LastSeen;
_statusValidTill = 0; _statusValidTill = 0;
if (auto user = peer()->asUser()) { if (auto user = peer()->asUser()) {
if (_isSavedMessagesChat) { if (!_savedMessagesStatus.isEmpty()) {
setStatusText(tr::lng_saved_forward_here(tr::now)); setStatusText(_savedMessagesStatus);
} else { } else {
auto time = base::unixtime::now(); auto time = base::unixtime::now();
setStatusText(Data::OnlineText(user, time)); setStatusText(Data::OnlineText(user, time));
@ -613,7 +613,7 @@ void PeerListRow::refreshName(const style::PeerListItem &st) {
if (!_initialized) { if (!_initialized) {
return; return;
} }
const auto text = _isSavedMessagesChat const auto text = !_savedMessagesStatus.isEmpty()
? tr::lng_saved_messages(tr::now) ? tr::lng_saved_messages(tr::now)
: _isRepliesMessagesChat : _isRepliesMessagesChat
? tr::lng_replies_messages(tr::now) ? tr::lng_replies_messages(tr::now)
@ -683,7 +683,7 @@ QString PeerListRow::generateName() {
} }
QString PeerListRow::generateShortName() { QString PeerListRow::generateShortName() {
return _isSavedMessagesChat return !_savedMessagesStatus.isEmpty()
? tr::lng_saved_short(tr::now) ? tr::lng_saved_short(tr::now)
: _isRepliesMessagesChat : _isRepliesMessagesChat
? tr::lng_replies_messages(tr::now) ? tr::lng_replies_messages(tr::now)
@ -699,7 +699,7 @@ Ui::PeerUserpicView &PeerListRow::ensureUserpicView() {
PaintRoundImageCallback PeerListRow::generatePaintUserpicCallback( PaintRoundImageCallback PeerListRow::generatePaintUserpicCallback(
bool forceRound) { bool forceRound) {
const auto saved = _isSavedMessagesChat; const auto saved = !_savedMessagesStatus.isEmpty();
const auto replies = _isRepliesMessagesChat; const auto replies = _isRepliesMessagesChat;
const auto peer = this->peer(); const auto peer = this->peer();
auto userpic = saved ? Ui::PeerUserpicView() : ensureUserpicView(); auto userpic = saved ? Ui::PeerUserpicView() : ensureUserpicView();
@ -745,7 +745,9 @@ int PeerListRow::paintNameIconGetWidth(
int availableWidth, int availableWidth,
int outerWidth, int outerWidth,
bool selected) { bool selected) {
if (special() || _isSavedMessagesChat || _isRepliesMessagesChat) { if (special()
|| !_savedMessagesStatus.isEmpty()
|| _isRepliesMessagesChat) {
return 0; return 0;
} }
return _bagde.drawGetWidth( return _bagde.drawGetWidth(
@ -855,7 +857,7 @@ void PeerListRow::paintDisabledCheckUserpic(
auto iconBorderPen = st.checkbox.check.border->p; auto iconBorderPen = st.checkbox.check.border->p;
iconBorderPen.setWidth(st.checkbox.selectWidth); iconBorderPen.setWidth(st.checkbox.selectWidth);
if (_isSavedMessagesChat) { if (!_savedMessagesStatus.isEmpty()) {
Ui::EmptyUserpic::PaintSavedMessages(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2); Ui::EmptyUserpic::PaintSavedMessages(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2);
} else if (_isRepliesMessagesChat) { } else if (_isRepliesMessagesChat) {
Ui::EmptyUserpic::PaintRepliesMessages(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2); Ui::EmptyUserpic::PaintRepliesMessages(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2);
@ -1046,9 +1048,10 @@ void PeerListContent::setRowHidden(not_null<PeerListRow*> row, bool hidden) {
} }
void PeerListContent::addRowEntry(not_null<PeerListRow*> row) { void PeerListContent::addRowEntry(not_null<PeerListRow*> row) {
if (_controller->respectSavedMessagesChat() && !row->special()) { const auto savedMessagesStatus = _controller->savedMessagesChatStatus();
if (!savedMessagesStatus.isEmpty() && !row->special()) {
if (row->peer()->isSelf()) { if (row->peer()->isSelf()) {
row->setIsSavedMessagesChat(true); row->setSavedMessagesChatStatus(savedMessagesStatus);
} else if (row->peer()->isRepliesChat()) { } else if (row->peer()->isRepliesChat()) {
row->setIsRepliesMessagesChat(true); row->setIsRepliesMessagesChat(true);
} }

View file

@ -185,8 +185,8 @@ public:
void setIsSearchResult(bool isSearchResult) { void setIsSearchResult(bool isSearchResult) {
_isSearchResult = isSearchResult; _isSearchResult = isSearchResult;
} }
void setIsSavedMessagesChat(bool isSavedMessagesChat) { void setSavedMessagesChatStatus(QString savedMessagesStatus) {
_isSavedMessagesChat = isSavedMessagesChat; _savedMessagesStatus = savedMessagesStatus;
} }
void setIsRepliesMessagesChat(bool isRepliesMessagesChat) { void setIsRepliesMessagesChat(bool isRepliesMessagesChat) {
_isRepliesMessagesChat = isRepliesMessagesChat; _isRepliesMessagesChat = isRepliesMessagesChat;
@ -278,12 +278,12 @@ private:
StatusType _statusType = StatusType::Online; StatusType _statusType = StatusType::Online;
crl::time _statusValidTill = 0; crl::time _statusValidTill = 0;
base::flat_set<QChar> _nameFirstLetters; base::flat_set<QChar> _nameFirstLetters;
QString _savedMessagesStatus;
int _absoluteIndex = -1; int _absoluteIndex = -1;
State _disabledState = State::Active; State _disabledState = State::Active;
bool _hidden : 1 = false; bool _hidden : 1 = false;
bool _initialized : 1 = false; bool _initialized : 1 = false;
bool _isSearchResult : 1 = false; bool _isSearchResult : 1 = false;
bool _isSavedMessagesChat : 1 = false;
bool _isRepliesMessagesChat : 1 = false; bool _isRepliesMessagesChat : 1 = false;
}; };
@ -517,8 +517,8 @@ public:
void peerListSearchAddRow(PeerListRowId id) override; void peerListSearchAddRow(PeerListRowId id) override;
void peerListSearchRefreshRows() override; void peerListSearchRefreshRows() override;
[[nodiscard]] virtual bool respectSavedMessagesChat() const { [[nodiscard]] virtual QString savedMessagesChatStatus() const {
return false; return QString();
} }
[[nodiscard]] virtual int customRowHeight() { [[nodiscard]] virtual int customRowHeight() {
Unexpected("PeerListController::customRowHeight."); Unexpected("PeerListController::customRowHeight.");

View file

@ -313,7 +313,7 @@ void ChatsListBoxController::rebuildRows() {
return count; return count;
}; };
auto added = 0; auto added = 0;
if (respectSavedMessagesChat()) { if (!savedMessagesChatStatus().isEmpty()) {
if (appendRow(session().data().history(session().user()))) { if (appendRow(session().data().history(session().user()))) {
++added; ++added;
} }
@ -330,7 +330,7 @@ void ChatsListBoxController::rebuildRows() {
const auto history = static_cast<const Row&>(a).history(); const auto history = static_cast<const Row&>(a).history();
return history->inChatList(); return history->inChatList();
}); });
if (respectSavedMessagesChat()) { if (!savedMessagesChatStatus().isEmpty()) {
delegate()->peerListPartitionRows([](const PeerListRow &a) { delegate()->peerListPartitionRows([](const PeerListRow &a) {
return a.peer()->isSelf(); return a.peer()->isSelf();
}); });
@ -696,6 +696,10 @@ void ChooseRecipientBoxController::rowClicked(not_null<PeerListRow*> row) {
} }
} }
QString ChooseRecipientBoxController::savedMessagesChatStatus() const {
return tr::lng_saved_forward_here(tr::now);
}
auto ChooseRecipientBoxController::createRow( auto ChooseRecipientBoxController::createRow(
not_null<History*> history) -> std::unique_ptr<Row> { not_null<History*> history) -> std::unique_ptr<Row> {
const auto peer = history->peer; const auto peer = history->peer;

View file

@ -218,9 +218,7 @@ public:
Main::Session &session() const override; Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
bool respectSavedMessagesChat() const override { QString savedMessagesChatStatus() const override;
return true;
}
protected: protected:
void prepareViewHook() override; void prepareViewHook() override;

View file

@ -45,8 +45,8 @@ public:
Main::Session &session() const override; Main::Session &session() const override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
bool respectSavedMessagesChat() const override { QString savedMessagesChatStatus() const override {
return true; return tr::lng_saved_forward_here(tr::now);
} }
private: private:

View file

@ -854,12 +854,12 @@ void ShowReplyToChatBox(
ChooseRecipientBoxController::rowClicked(row); ChooseRecipientBoxController::rowClicked(row);
} }
[[nodiscard]] rpl::producer<Chosen> singleChosen() const{ [[nodiscard]] rpl::producer<Chosen> singleChosen() const {
return _singleChosen.events(); return _singleChosen.events();
} }
bool respectSavedMessagesChat() const override { QString savedMessagesChatStatus() const override {
return false; return tr::lng_saved_quote_here(tr::now);
} }
private: private: