summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-01-17 01:25:14 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-01-17 01:25:14 +0100
commitfe912240bc1ab89b8a20ce87d5183f328f704d23 (patch)
treefd86e16977dc068c8ad404dc4ede4eb6640374de /src/timeline/TimelineModel.cpp
parentRemove embedded fonts (diff)
downloadnheko-fe912240bc1ab89b8a20ce87d5183f328f704d23.tar.xz
Move typing display to qml
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp

index 08c29927..2fd4b6d4 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -1388,3 +1388,33 @@ TimelineModel::cacheMedia(QString eventId) emit mediaCached(mxcUrl, filename.filePath()); }); } + +QString +TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg) +{ + QString temp = + tr("%1 and %2 are typing", + "Multiple users are typing. First argument is a comma separated list of potentially " + "multiple users. Second argument is the last user of that list. (If only one user is " + "typing, %1 is empty. You should still use it in your string though to silence Qt " + "warnings.)", + users.size()); + + if (users.empty()) { + return ""; + } + + QStringList uidWithoutLast; + + auto formatUser = [this, bg](const QString &user_id) -> QString { + return QString("<font color=\"%1\">%2</font>") + .arg(userColor(user_id, bg).name()) + .arg(escapeEmoji(displayName(user_id).toHtmlEscaped())); + }; + + for (size_t i = 0; i + 1 < users.size(); i++) { + uidWithoutLast.append(formatUser(users[i])); + } + + return temp.arg(uidWithoutLast.join(", ")).arg(formatUser(users.back())); +}