Changeset View
Changeset View
Standalone View
Standalone View
src/ruqolacore/receivetypingnotificationmanager.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 60 | if (onTyping) { | |||
---|---|---|---|---|---|
61 | mMapTypingNotifications.insert(roomId, {userName}); | 61 | mMapTypingNotifications.insert(roomId, {userName}); | ||
62 | Q_EMIT notificationChanged(roomId, generateNotification({userName})); | 62 | Q_EMIT notificationChanged(roomId, generateNotification({userName})); | ||
63 | } | 63 | } | ||
64 | } | 64 | } | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | QString ReceiveTypingNotificationManager::generateNotification(const QStringList &userNames) const | 67 | QString ReceiveTypingNotificationManager::generateNotification(const QStringList &userNames) const | ||
68 | { | 68 | { | ||
69 | if (userNames.isEmpty()) { | ||||
70 | return QString(); | ||||
71 | } else if (userNames.count() == 1) { | ||||
72 | return i18n("%1 is typing...", userNames[0]); | ||||
73 | } else { | ||||
69 | QString notificationStr; | 74 | QString notificationStr; | ||
70 | for (const QString &user : userNames) { | 75 | for (int i = 0; i < userNames.count(); ++i) { | ||
71 | if (!notificationStr.isEmpty()) { | 76 | const QString user = userNames.at(i); | ||
72 | notificationStr += QLatin1String(", "); | 77 | if (i == 0) { | ||
78 | notificationStr = user; | ||||
79 | } else if (i < userNames.count() - 1) { | ||||
80 | notificationStr = i18n("%1, %2", notificationStr, user); | ||||
81 | } else { | ||||
82 | notificationStr = i18n("%1 and %2", notificationStr, user); | ||||
83 | } | ||||
73 | } | 84 | } | ||
74 | notificationStr += i18n("%1 is typing...", user); | 85 | return i18n("%1 are typing...", notificationStr); | ||
75 | } | 86 | } | ||
76 | return notificationStr; | | |||
77 | } | 87 | } | ||
78 | 88 | | |||
79 | QString ReceiveTypingNotificationManager::typingNotification(const QString &roomId) const | 89 | QString ReceiveTypingNotificationManager::typingNotification(const QString &roomId) const | ||
80 | { | 90 | { | ||
81 | return generateNotification(mMapTypingNotifications.value(roomId)); | 91 | return generateNotification(mMapTypingNotifications.value(roomId)); | ||
82 | } | 92 | } |