2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Handle fwd_from without a link to the account.

This commit is contained in:
John Preston
2019-03-15 19:15:56 +04:00
parent 6d1193a751
commit a34e998c42
36 changed files with 503 additions and 192 deletions

View File

@@ -1156,6 +1156,12 @@ Message ParseMessage(
}
return PeerId(0);
});
result.forwardedFromName = data.vfwd_from.match(
[](const MTPDmessageFwdHeader &data) {
return data.has_from_name()
? data.vfrom_name.v
: QByteArray();
});
result.forwardedDate = data.vfwd_from.match(
[](const MTPDmessageFwdHeader &data) {
return data.vdate.v;
@@ -1167,6 +1173,8 @@ Message ParseMessage(
}
return PeerId(0);
});
result.forwarded = result.forwardedFromId
|| !result.forwardedFromName.isEmpty();
}
if (data.has_post_author()) {
result.signature = ParseString(data.vpost_author);

View File

@@ -501,7 +501,9 @@ struct Message {
int32 fromId = 0;
PeerId toId = 0;
PeerId forwardedFromId = 0;
Utf8String forwardedFromName;
TimeId forwardedDate = 0;
bool forwarded = false;
PeerId savedFromChatId = 0;
Utf8String signature;
int32 viaBotId = 0;

View File

@@ -203,6 +203,9 @@ Stats AbstractWriter::produceTestExample(
if (++count % 3 == 0) {
message.forwardedFromId = Data::UserPeerId(user.info.userId);
message.forwardedDate = date();
} else if (count % 3 == 2) {
message.forwardedFromName = "Test hidden forward";
message.forwardedDate = date();
}
message.fromId = user.info.userId;
message.replyToMsgId = counter();

View File

@@ -513,6 +513,8 @@ struct HtmlWriter::MessageInfo {
int32 fromId = 0;
TimeId date = 0;
Data::PeerId forwardedFromId = 0;
QString forwardedFromName;
bool forwarded = false;
TimeId forwardedDate = 0;
};
@@ -648,6 +650,20 @@ void FillUserpicNames(UserpicData &data, const Data::Peer &peer) {
}
}
void FillUserpicNames(UserpicData &data, const QByteArray &full) {
const auto names = full.split(' ');
data.firstName = names[0];
for (auto i = 1; i != names.size(); ++i) {
if (names[i].isEmpty()) {
continue;
}
if (!data.lastName.isEmpty()) {
data.lastName.append(' ');
}
data.lastName.append(names[i]);
}
}
QByteArray ComposeName(const UserpicData &data, const QByteArray &empty) {
return ((data.firstName.isEmpty() && data.lastName.isEmpty())
? empty
@@ -948,7 +964,9 @@ auto HtmlWriter::Wrap::pushMessage(
info.fromId = message.fromId;
info.date = message.date;
info.forwardedFromId = message.forwardedFromId;
info.forwardedFromName = message.forwardedFromName;
info.forwardedDate = message.forwardedDate;
info.forwarded = message.forwarded;
if (message.media.content.is<UnsupportedMedia>()) {
return { info, pushServiceMessage(
message.id,
@@ -1122,19 +1140,24 @@ auto HtmlWriter::Wrap::pushMessage(
block.append(pushDiv("from_name"));
block.append(SerializeString(
ComposeName(userpic, "Deleted Account")));
if (!via.isEmpty() && !message.forwardedFromId) {
if (!via.isEmpty() && !message.forwarded) {
block.append(" via @" + via);
}
block.append(popTag());
}
if (message.forwardedFromId) {
if (message.forwarded) {
auto forwardedUserpic = UserpicData();
forwardedUserpic.colorIndex = PeerColorIndex(
BarePeerId(message.forwardedFromId));
forwardedUserpic.colorIndex = message.forwardedFromId
? PeerColorIndex(BarePeerId(message.forwardedFromId))
: PeerColorIndex(message.id);
forwardedUserpic.pixelSize = kHistoryUserpicSize;
FillUserpicNames(
forwardedUserpic,
peers.peer(message.forwardedFromId));
if (message.forwardedFromId) {
FillUserpicNames(
forwardedUserpic,
peers.peer(message.forwardedFromId));
} else {
FillUserpicNames(forwardedUserpic, message.forwardedFromName);
}
const auto forwardedWrap = forwardedNeedsWrap(message, previous);
if (forwardedWrap) {
@@ -1179,7 +1202,7 @@ auto HtmlWriter::Wrap::pushMessage(
block.append(SerializeString(message.signature));
block.append(popTag());
}
if (message.forwardedFromId) {
if (message.forwarded) {
block.append(popTag());
}
block.append(popTag());
@@ -1200,10 +1223,12 @@ bool HtmlWriter::Wrap::messageNeedsWrap(
} else if (QDateTime::fromTime_t(previous->date).date()
!= QDateTime::fromTime_t(message.date).date()) {
return true;
} else if (!message.forwardedFromId != !previous->forwardedFromId) {
} else if (message.forwarded != previous->forwarded) {
return true;
} else if (std::abs(message.date - previous->date)
> (message.forwardedFromId ? 1 : kJoinWithinSeconds)) {
> ((message.forwardedFromId || !message.forwardedFromName.isEmpty())
? 1
: kJoinWithinSeconds)) {
return true;
}
return false;
@@ -1725,11 +1750,12 @@ MediaData HtmlWriter::Wrap::prepareMediaData(
bool HtmlWriter::Wrap::forwardedNeedsWrap(
const Data::Message &message,
const MessageInfo *previous) const {
Expects(message.forwardedFromId != 0);
Expects(message.forwarded);
if (messageNeedsWrap(message, previous)) {
return true;
} else if (message.forwardedFromId != previous->forwardedFromId) {
} else if (!message.forwardedFromId
|| message.forwardedFromId != previous->forwardedFromId) {
return true;
} else if (Data::IsChatPeerId(message.forwardedFromId)) {
return true;

View File

@@ -471,6 +471,10 @@ QByteArray SerializeMessage(
pushBare(
"forwarded_from",
wrapPeerName(message.forwardedFromId));
} else if (!message.forwardedFromName.isEmpty()) {
pushBare(
"forwarded_from",
StringAllowNull(message.forwardedFromName));
}
if (message.savedFromChatId) {
pushBare("saved_from", wrapPeerName(message.savedFromChatId));

View File

@@ -342,6 +342,8 @@ QByteArray SerializeMessage(
push("Author", message.signature);
if (message.forwardedFromId) {
push("Forwarded from", wrapPeerName(message.forwardedFromId));
} else if (!message.forwardedFromName.isEmpty()) {
push("Forwarded from", message.forwardedFromName);
}
if (message.savedFromChatId) {
push("Saved from", wrapPeerName(message.savedFromChatId));