Skip to content
Snippets Groups Projects
Commit 2c37beba authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Fix translation of roomlist message preview

This also makes long messages unreadable, because we don't shorten long
usernames anymore. We may eventually want to do that again, but it is
hard with translations and we probably want to shorten the displayname
more, as before this change the message was only ever as long as the
timestamp, which is usually just 5 characters...
parent 6b6085b2
No related branches found
No related tags found
No related merge requests found
...@@ -118,7 +118,7 @@ RoomInfoListItem::RoomInfoListItem(QString room_id, RoomInfo info, QWidget *pare ...@@ -118,7 +118,7 @@ RoomInfoListItem::RoomInfoListItem(QString room_id, RoomInfo info, QWidget *pare
// so we can't use them for sorting. // so we can't use them for sorting.
if (roomType_ == RoomType::Invited) if (roomType_ == RoomType::Invited)
lastMsgInfo_ = { lastMsgInfo_ = {
emptyEventId, "-", "-", "-", "-", QDateTime::currentDateTime().addYears(10)}; emptyEventId, "-", "-", "-", QDateTime::currentDateTime().addYears(10)};
} }
void void
...@@ -210,33 +210,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) ...@@ -210,33 +210,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
p.setFont(QFont{}); p.setFont(QFont{});
p.setPen(subtitlePen); p.setPen(subtitlePen);
// The limit is the space between the end of the avatar and the start of the int descriptionLimit = std::max(
// timestamp. 0, width() - 3 * wm.padding - bottomLineWidthLimit - wm.iconSize);
int usernameLimit =
std::max(0, width() - 3 * wm.padding - msgStampWidth - wm.iconSize - 20);
auto userName =
metrics.elidedText(lastMsgInfo_.username, Qt::ElideRight, usernameLimit);
p.setFont(QFont{});
p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), userName);
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int nameWidth = QFontMetrics(QFont{}).width(userName);
#else
int nameWidth = QFontMetrics(QFont{}).horizontalAdvance(userName);
#endif
p.setFont(QFont{});
// The limit is the space between the end of the username and the start of
// the timestamp.
int descriptionLimit =
std::max(0,
width() - 3 * wm.padding - bottomLineWidthLimit - wm.iconSize -
nameWidth - 5);
auto description = auto description =
metrics.elidedText(lastMsgInfo_.body, Qt::ElideRight, descriptionLimit); metrics.elidedText(lastMsgInfo_.body, Qt::ElideRight, descriptionLimit);
p.drawText(QPoint(2 * wm.padding + wm.iconSize + nameWidth, bottom_y), p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), description);
description);
// We show the last message timestamp. // We show the last message timestamp.
p.save(); p.save();
......
...@@ -146,11 +146,6 @@ utils::getMessageDescription(const TimelineEvent &event, ...@@ -146,11 +146,6 @@ utils::getMessageDescription(const TimelineEvent &event,
const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts);
DescInfo info; DescInfo info;
if (sender == localUser)
info.username = QCoreApplication::translate("utils", "You");
else
info.username = username;
info.userid = sender; info.userid = sender;
info.body = QString(" %1").arg(messageDescription<Encrypted>()); info.body = QString(" %1").arg(messageDescription<Encrypted>());
info.timestamp = utils::descriptiveTime(ts); info.timestamp = utils::descriptiveTime(ts);
......
...@@ -94,38 +94,72 @@ messageDescription(const QString &username = "", ...@@ -94,38 +94,72 @@ messageDescription(const QString &username = "",
using Video = mtx::events::RoomEvent<mtx::events::msg::Video>; using Video = mtx::events::RoomEvent<mtx::events::msg::Video>;
using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>;
// Sometimes the verb form of sent changes in some languages depending on the actor.
auto remoteSent = QCoreApplication::translate(
"message-description: ", "sent", "For when you are the sender");
auto localSent = QCoreApplication::translate(
"message-description:", "sent", "For when someone else is the sender");
QString sentVerb = isLocal ? localSent : remoteSent;
if (std::is_same<T, AudioItem>::value || std::is_same<T, Audio>::value) { if (std::is_same<T, AudioItem>::value || std::is_same<T, Audio>::value) {
return QCoreApplication::translate("message-description sent:", "%1 an audio clip") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent an audio clip");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent an audio clip")
.arg(username);
} else if (std::is_same<T, ImageItem>::value || std::is_same<T, Image>::value) { } else if (std::is_same<T, ImageItem>::value || std::is_same<T, Image>::value) {
return QCoreApplication::translate("message-description sent:", "%1 an image") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent an image");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent an image")
.arg(username);
} else if (std::is_same<T, FileItem>::value || std::is_same<T, File>::value) { } else if (std::is_same<T, FileItem>::value || std::is_same<T, File>::value) {
return QCoreApplication::translate("message-description sent:", "%1 a file") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent a file");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent a file")
.arg(username);
} else if (std::is_same<T, VideoItem>::value || std::is_same<T, Video>::value) { } else if (std::is_same<T, VideoItem>::value || std::is_same<T, Video>::value) {
return QCoreApplication::translate("message-description sent:", "%1 a video clip") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent a video");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent a video")
.arg(username);
} else if (std::is_same<T, StickerItem>::value || std::is_same<T, Sticker>::value) { } else if (std::is_same<T, StickerItem>::value || std::is_same<T, Sticker>::value) {
return QCoreApplication::translate("message-description sent:", "%1 a sticker") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent a sticker");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent a sticker")
.arg(username);
} else if (std::is_same<T, Notice>::value) { } else if (std::is_same<T, Notice>::value) {
return QCoreApplication::translate("message-description sent:", "%1 a notification") if (isLocal)
.arg(sentVerb); return QCoreApplication::translate("message-description sent:",
"You sent a notification");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent a notification")
.arg(username);
} else if (std::is_same<T, Text>::value) { } else if (std::is_same<T, Text>::value) {
return QString(": %1").arg(body); if (isLocal)
return QCoreApplication::translate("message-description sent:", "You: %1")
.arg(body);
else
return QCoreApplication::translate("message-description sent:", "%1: %2")
.arg(username)
.arg(body);
} else if (std::is_same<T, Emote>::value) { } else if (std::is_same<T, Emote>::value) {
return QString("* %1 %2").arg(username).arg(body); return QString("* %1 %2").arg(username).arg(body);
} else if (std::is_same<T, Encrypted>::value) { } else if (std::is_same<T, Encrypted>::value) {
return QCoreApplication::translate("message-description sent:", if (isLocal)
"%1 an encrypted message") return QCoreApplication::translate("message-description sent:",
.arg(sentVerb); "You sent an encrypted message");
else
return QCoreApplication::translate("message-description sent:",
"%1 sent an encrypted message")
.arg(username);
} else { } else {
return QCoreApplication::translate("utils", "Unknown Message Type"); return QCoreApplication::translate("utils", "Unknown Message Type");
} }
...@@ -144,20 +178,13 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin ...@@ -144,20 +178,13 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin
const auto username = Cache::displayName(room_id, sender); const auto username = Cache::displayName(room_id, sender);
const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts);
bool isText = std::is_same<T, Text>::value; return DescInfo{QString::fromStdString(msg.event_id),
bool isEmote = std::is_same<T, Emote>::value; sender,
messageDescription<T>(username,
return DescInfo{ QString::fromStdString(msg.content.body).trimmed(),
QString::fromStdString(msg.event_id), sender == localUser),
isEmote ? "" utils::descriptiveTime(ts),
: (sender == localUser ? QCoreApplication::translate("utils", "You") : username), ts};
sender,
(isText || isEmote)
? messageDescription<T>(
username, QString::fromStdString(msg.content.body).trimmed(), sender == localUser)
: QString(" %1").arg(messageDescription<T>()),
utils::descriptiveTime(ts),
ts};
} }
//! Scale down an image to fit to the given width & height limitations. //! Scale down an image to fit to the given width & height limitations.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment