mirror of https://github.com/procxx/kepka.git
Fix forwarded from for single message forward.
Closes #3699, closes #3701, closes #3700.
This commit is contained in:
parent
e1e286aa13
commit
24b3b2a658
|
@ -138,7 +138,7 @@ struct HistoryMessageForwarded : public RuntimeComponent<HistoryMessageForwarded
|
||||||
void create(const HistoryMessageVia *via) const;
|
void create(const HistoryMessageVia *via) const;
|
||||||
|
|
||||||
QDateTime _originalDate;
|
QDateTime _originalDate;
|
||||||
PeerData *_originalPeer = nullptr;
|
PeerData *_originalSender = nullptr;
|
||||||
QString _originalAuthor;
|
QString _originalAuthor;
|
||||||
MsgId _originalId = 0;
|
MsgId _originalId = 0;
|
||||||
mutable Text _text = { 1 };
|
mutable Text _text = { 1 };
|
||||||
|
@ -802,15 +802,16 @@ public:
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
PeerData *peerOriginal() const {
|
PeerData *senderOriginal() const {
|
||||||
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
||||||
return forwarded->_originalPeer;
|
return forwarded->_originalSender;
|
||||||
}
|
}
|
||||||
return history()->peer;
|
auto peer = history()->peer;
|
||||||
|
return (peer->isChannel() && !peer->isMegagroup()) ? peer : from();
|
||||||
}
|
}
|
||||||
PeerData *fromOriginal() const {
|
PeerData *fromOriginal() const {
|
||||||
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
||||||
if (auto user = forwarded->_originalPeer->asUser()) {
|
if (auto user = forwarded->_originalSender->asUser()) {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,19 +372,20 @@ int HistoryMessageEdited::maxWidth() const {
|
||||||
|
|
||||||
void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
|
void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
|
||||||
QString text;
|
QString text;
|
||||||
|
auto fromChannel = (_originalSender->isChannel() && !_originalSender->isMegagroup());
|
||||||
if (!_originalAuthor.isEmpty()) {
|
if (!_originalAuthor.isEmpty()) {
|
||||||
text = lng_forwarded_signed(lt_channel, App::peerName(_originalPeer), lt_user, _originalAuthor);
|
text = lng_forwarded_signed(lt_channel, App::peerName(_originalSender), lt_user, _originalAuthor);
|
||||||
} else {
|
} else {
|
||||||
text = App::peerName(_originalPeer);
|
text = App::peerName(_originalSender);
|
||||||
}
|
}
|
||||||
if (via) {
|
if (via) {
|
||||||
if (_originalPeer->isChannel()) {
|
if (fromChannel) {
|
||||||
text = lng_forwarded_channel_via(lt_channel, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username));
|
text = lng_forwarded_channel_via(lt_channel, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username));
|
||||||
} else {
|
} else {
|
||||||
text = lng_forwarded_via(lt_user, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username));
|
text = lng_forwarded_via(lt_user, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_originalPeer->isChannel()) {
|
if (fromChannel) {
|
||||||
text = lng_forwarded_channel(lt_channel, textcmdLink(1, text));
|
text = lng_forwarded_channel(lt_channel, textcmdLink(1, text));
|
||||||
} else {
|
} else {
|
||||||
text = lng_forwarded(lt_user, textcmdLink(1, text));
|
text = lng_forwarded(lt_user, textcmdLink(1, text));
|
||||||
|
@ -392,7 +393,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
|
||||||
}
|
}
|
||||||
TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto };
|
TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto };
|
||||||
_text.setText(st::fwdTextStyle, text, opts);
|
_text.setText(st::fwdTextStyle, text, opts);
|
||||||
_text.setLink(1, (_originalId && _originalPeer->isChannel()) ? goToMessageClickHandler(_originalPeer, _originalId) : _originalPeer->openLink());
|
_text.setLink(1, fromChannel ? goToMessageClickHandler(_originalSender, _originalId) : _originalSender->openLink());
|
||||||
if (via) {
|
if (via) {
|
||||||
_text.setLink(2, via->_lnk);
|
_text.setLink(2, via->_lnk);
|
||||||
}
|
}
|
||||||
|
@ -611,7 +612,7 @@ HistoryMessage::HistoryMessage(gsl::not_null<History*> history, const MTPDmessag
|
||||||
auto &f = msg.vfwd_from.c_messageFwdHeader();
|
auto &f = msg.vfwd_from.c_messageFwdHeader();
|
||||||
config.originalDate = ::date(f.vdate);
|
config.originalDate = ::date(f.vdate);
|
||||||
if (f.has_from_id() || f.has_channel_id()) {
|
if (f.has_from_id() || f.has_channel_id()) {
|
||||||
config.peerIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id);
|
config.senderOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id);
|
||||||
if (f.has_channel_post()) config.originalId = f.vchannel_post.v;
|
if (f.has_channel_post()) config.originalId = f.vchannel_post.v;
|
||||||
if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author);
|
if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author);
|
||||||
}
|
}
|
||||||
|
@ -658,10 +659,10 @@ HistoryMessage::HistoryMessage(gsl::not_null<History*> history, MsgId id, MTPDme
|
||||||
if (fwd->Has<HistoryMessageForwarded>() || !fwd->history()->peer->isSelf()) {
|
if (fwd->Has<HistoryMessageForwarded>() || !fwd->history()->peer->isSelf()) {
|
||||||
// Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself.
|
// Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself.
|
||||||
config.originalDate = fwd->dateOriginal();
|
config.originalDate = fwd->dateOriginal();
|
||||||
auto peerOriginal = fwd->peerOriginal();
|
auto senderOriginal = fwd->senderOriginal();
|
||||||
config.peerIdOriginal = peerOriginal->id;
|
config.senderOriginal = senderOriginal->id;
|
||||||
config.authorOriginal = fwd->authorOriginal();
|
config.authorOriginal = fwd->authorOriginal();
|
||||||
if (peerOriginal->isChannel()) {
|
if (senderOriginal->isChannel()) {
|
||||||
config.originalId = fwd->idOriginal();
|
config.originalId = fwd->idOriginal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -844,7 +845,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
||||||
if (displayEditedBadge(hasViaBot || hasInlineMarkup())) {
|
if (displayEditedBadge(hasViaBot || hasInlineMarkup())) {
|
||||||
mask |= HistoryMessageEdited::Bit();
|
mask |= HistoryMessageEdited::Bit();
|
||||||
}
|
}
|
||||||
if (config.peerIdOriginal) {
|
if (config.senderOriginal) {
|
||||||
mask |= HistoryMessageForwarded::Bit();
|
mask |= HistoryMessageForwarded::Bit();
|
||||||
}
|
}
|
||||||
if (config.mtpMarkup) {
|
if (config.mtpMarkup) {
|
||||||
|
@ -881,7 +882,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
||||||
}
|
}
|
||||||
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
||||||
forwarded->_originalDate = config.originalDate;
|
forwarded->_originalDate = config.originalDate;
|
||||||
forwarded->_originalPeer = App::peer(config.peerIdOriginal);
|
forwarded->_originalSender = App::peer(config.senderOriginal);
|
||||||
forwarded->_originalId = config.originalId;
|
forwarded->_originalId = config.originalId;
|
||||||
forwarded->_originalAuthor = config.authorOriginal;
|
forwarded->_originalAuthor = config.authorOriginal;
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1238,7 @@ bool HistoryMessage::displayForwardedFrom() const {
|
||||||
|| !_media
|
|| !_media
|
||||||
|| !_media->isDisplayed()
|
|| !_media->isDisplayed()
|
||||||
|| !_media->hideForwardedFrom()
|
|| !_media->hideForwardedFrom()
|
||||||
|| forwarded->_originalPeer->isChannel();
|
|| forwarded->_originalSender->isChannel();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ private:
|
||||||
UserId viaBotId = 0;
|
UserId viaBotId = 0;
|
||||||
int viewsCount = -1;
|
int viewsCount = -1;
|
||||||
QString author;
|
QString author;
|
||||||
PeerId peerIdOriginal = 0;
|
PeerId senderOriginal = 0;
|
||||||
MsgId originalId = 0;
|
MsgId originalId = 0;
|
||||||
QString authorOriginal;
|
QString authorOriginal;
|
||||||
QDateTime originalDate;
|
QDateTime originalDate;
|
||||||
|
|
|
@ -6414,7 +6414,7 @@ void HistoryWidget::updateForwardingTexts() {
|
||||||
QVector<PeerData*> fromUsers;
|
QVector<PeerData*> fromUsers;
|
||||||
fromUsers.reserve(_toForward.size());
|
fromUsers.reserve(_toForward.size());
|
||||||
for (auto i = _toForward.cbegin(), e = _toForward.cend(); i != e; ++i) {
|
for (auto i = _toForward.cbegin(), e = _toForward.cend(); i != e; ++i) {
|
||||||
auto from = i.value()->peerOriginal();
|
auto from = i.value()->senderOriginal();
|
||||||
if (!fromUsersMap.contains(from)) {
|
if (!fromUsersMap.contains(from)) {
|
||||||
fromUsersMap.insert(from, true);
|
fromUsersMap.insert(from, true);
|
||||||
fromUsers.push_back(from);
|
fromUsers.push_back(from);
|
||||||
|
@ -6444,7 +6444,7 @@ void HistoryWidget::checkForwardingInfo() {
|
||||||
if (!_toForward.isEmpty()) {
|
if (!_toForward.isEmpty()) {
|
||||||
auto version = 0;
|
auto version = 0;
|
||||||
for_const (auto item, _toForward) {
|
for_const (auto item, _toForward) {
|
||||||
version += item->peerOriginal()->nameVersion;
|
version += item->senderOriginal()->nameVersion;
|
||||||
}
|
}
|
||||||
if (version != _toForwardNameVersion) {
|
if (version != _toForwardNameVersion) {
|
||||||
updateForwardingTexts();
|
updateForwardingTexts();
|
||||||
|
|
|
@ -1212,7 +1212,7 @@ void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) {
|
||||||
_y = (height() - _h) / 2;
|
_y = (height() - _h) / 2;
|
||||||
_width = _w;
|
_width = _w;
|
||||||
if (_msgid && item) {
|
if (_msgid && item) {
|
||||||
_from = item->peerOriginal();
|
_from = item->senderOriginal();
|
||||||
} else {
|
} else {
|
||||||
_from = _user;
|
_from = _user;
|
||||||
}
|
}
|
||||||
|
@ -1366,7 +1366,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty
|
||||||
_x = (width() - _w) / 2;
|
_x = (width() - _w) / 2;
|
||||||
_y = (height() - _h) / 2;
|
_y = (height() - _h) / 2;
|
||||||
if (_msgid && item) {
|
if (_msgid && item) {
|
||||||
_from = item->peerOriginal();
|
_from = item->senderOriginal();
|
||||||
} else {
|
} else {
|
||||||
_from = _user;
|
_from = _user;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue