From d8b89e2ef0a1a650a4bc249025ad6987cbf2176d Mon Sep 17 00:00:00 2001 From: lkito Date: Tue, 19 May 2020 23:04:38 +0400 Subject: Added an optional feature to show bigger emoji-only messages with 3 or less emoji --- src/timeline/TimelineModel.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 6e653f10..6a4de92c 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -207,6 +207,7 @@ TimelineModel::roleNames() const {Section, "section"}, {Type, "type"}, {TypeString, "typeString"}, + {IsOnlyEmoji, "isOnlyEmoji"}, {Body, "body"}, {FormattedBody, "formattedBody"}, {UserId, "userId"}, @@ -272,6 +273,22 @@ TimelineModel::data(const QString &id, int role) const return QVariant(toRoomEventType(event)); case TypeString: return QVariant(toRoomEventTypeString(event)); + case IsOnlyEmoji: { + QString qBody = QString::fromStdString(body(event)); + + QVector utf32_string = qBody.toUcs4(); + int emojiCount = 0; + + for (auto &code : utf32_string) { + if (utils::codepointIsEmoji(code)) { + emojiCount++; + } else { + return QVariant(0); + } + } + + return QVariant(emojiCount); + } case Body: return QVariant(utils::replaceEmoji(QString::fromStdString(body(event)))); case FormattedBody: { @@ -374,6 +391,7 @@ TimelineModel::data(const QString &id, int role) const // m.insert(names[Section], data(id, static_cast(Section))); m.insert(names[Type], data(id, static_cast(Type))); m.insert(names[TypeString], data(id, static_cast(TypeString))); + m.insert(names[IsOnlyEmoji], data(id, static_cast(IsOnlyEmoji))); m.insert(names[Body], data(id, static_cast(Body))); m.insert(names[FormattedBody], data(id, static_cast(FormattedBody))); m.insert(names[UserId], data(id, static_cast(UserId))); -- cgit 1.4.1