summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorlkito <lkiti17@freeuni.edu.ge>2020-05-19 23:04:38 +0400
committerlkito <lkiti17@freeuni.edu.ge>2020-05-21 16:31:27 +0400
commitd8b89e2ef0a1a650a4bc249025ad6987cbf2176d (patch)
tree3064221b74ba459cb5aca8b7130065dca46673d6 /src/timeline/TimelineModel.cpp
parentadd a bit of additional logging to image paste (diff)
downloadnheko-d8b89e2ef0a1a650a4bc249025ad6987cbf2176d.tar.xz
Added an optional feature to show bigger emoji-only messages with 3 or less emoji
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp18
1 files changed, 18 insertions, 0 deletions
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<uint> 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<int>(Section)));
                 m.insert(names[Type], data(id, static_cast<int>(Type)));
                 m.insert(names[TypeString], data(id, static_cast<int>(TypeString)));
+                m.insert(names[IsOnlyEmoji], data(id, static_cast<int>(IsOnlyEmoji)));
                 m.insert(names[Body], data(id, static_cast<int>(Body)));
                 m.insert(names[FormattedBody], data(id, static_cast<int>(FormattedBody)));
                 m.insert(names[UserId], data(id, static_cast<int>(UserId)));