summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-02-14 15:43:17 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-02-14 15:43:17 +0100
commitddcd4850f101d3aa1d480a3a1b515209f38bfe82 (patch)
tree9663e2551efa94e623ad49ca3578d82f8ca699a5 /src
parentPrevent old verification requests from showing up (diff)
parentimprove spacings (diff)
downloadnheko-ddcd4850f101d3aa1d480a3a1b515209f38bfe82.tar.xz
Merge branch 'message-bubbles' of https://github.com/maltee1/nheko into maltee1-message-bubbles
Diffstat (limited to 'src')
-rw-r--r--src/UserSettingsPage.cpp62
-rw-r--r--src/UserSettingsPage.h13
-rw-r--r--src/timeline/TimelineModel.cpp13
-rw-r--r--src/timeline/TimelineModel.h2
4 files changed, 85 insertions, 5 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp

index 7da82153..862a70d0 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp
@@ -69,7 +69,9 @@ UserSettings::load(std::optional<QString> profile) settings.value(QStringLiteral("user/timeline/message_hover_highlight"), false).toBool(); enlargeEmojiOnlyMessages_ = settings.value(QStringLiteral("user/timeline/enlarge_emoji_only_msg"), false).toBool(); - markdown_ = settings.value(QStringLiteral("user/markdown_enabled"), true).toBool(); + markdown_ = settings.value(QStringLiteral("user/markdown_enabled"), true).toBool(); + bubbles_ = settings.value(QStringLiteral("user/bubbles_enabled"), false).toBool(); + smallAvatars_ = settings.value(QStringLiteral("user/small_avatars_enabled"), false).toBool(); animateImagesOnHover_ = settings.value(QStringLiteral("user/animate_images_on_hover"), false).toBool(); typingNotifications_ = @@ -252,6 +254,26 @@ UserSettings::setMarkdown(bool state) } void +UserSettings::setBubbles(bool state) +{ + if (state == bubbles_) + return; + bubbles_ = state; + emit bubblesChanged(state); + save(); +} + +void +UserSettings::setSmallAvatars(bool state) +{ + if (state == smallAvatars_) + return; + smallAvatars_ = state; + emit smallAvatarsChanged(state); + save(); +} + +void UserSettings::setAnimateImagesOnHover(bool state) { if (state == animateImagesOnHover_) @@ -705,6 +727,8 @@ UserSettings::save() settings.setValue(QStringLiteral("read_receipts"), readReceipts_); settings.setValue(QStringLiteral("group_view"), groupView_); settings.setValue(QStringLiteral("markdown_enabled"), markdown_); + settings.setValue(QStringLiteral("bubbles_enabled"), bubbles_); + settings.setValue(QStringLiteral("small_avatars_enabled"), smallAvatars_); settings.setValue(QStringLiteral("animate_images_on_hover"), animateImagesOnHover_); settings.setValue(QStringLiteral("desktop_notifications"), hasDesktopNotifications_); settings.setValue(QStringLiteral("alert_on_notification"), hasAlertOnNotification_); @@ -806,6 +830,10 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return tr("Group's sidebar"); case Markdown: return tr("Send messages as Markdown"); + case Bubbles: + return tr("Enable message bubbles"); + case SmallAvatars: + return tr("Enable small Avatars"); case AnimateImagesOnHover: return tr("Play animated images only on hover"); case TypingNotifications: @@ -926,6 +954,10 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return i->groupView(); case Markdown: return i->markdown(); + case Bubbles: + return i->bubbles(); + case SmallAvatars: + return i->smallAvatars(); case AnimateImagesOnHover: return i->animateImagesOnHover(); case TypingNotifications: @@ -1052,6 +1084,11 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return tr( "Allow using markdown in messages.\nWhen disabled, all messages are sent as a plain " "text."); + case Bubbles: + return tr( + "Messages get a bubble background. This also triggers some layout changes (WIP)."); + case SmallAvatars: + return tr("Avatars are resized to fit above the message."); case AnimateImagesOnHover: return tr("Plays media like GIFs or WEBPs only when explicitly hovering over them."); case TypingNotifications: @@ -1168,6 +1205,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const case StartInTray: case GroupView: case Markdown: + case Bubbles: + case SmallAvatars: case AnimateImagesOnHover: case TypingNotifications: case SortByImportance: @@ -1385,6 +1424,20 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int } else return false; } + case Bubbles: { + if (value.userType() == QMetaType::Bool) { + i->setBubbles(value.toBool()); + return true; + } else + return false; + } + case SmallAvatars: { + if (value.userType() == QMetaType::Bool) { + i->setSmallAvatars(value.toBool()); + return true; + } else + return false; + } case AnimateImagesOnHover: { if (value.userType() == QMetaType::Bool) { i->setAnimateImagesOnHover(value.toBool()); @@ -1747,7 +1800,12 @@ UserSettingsModel::UserSettingsModel(QObject *p) connect(s.get(), &UserSettings::markdownChanged, this, [this]() { emit dataChanged(index(Markdown), index(Markdown), {Value}); }); - + connect(s.get(), &UserSettings::bubblesChanged, this, [this]() { + emit dataChanged(index(Bubbles), index(Bubbles), {Value}); + }); + connect(s.get(), &UserSettings::smallAvatarsChanged, this, [this]() { + emit dataChanged(index(SmallAvatars), index(SmallAvatars), {Value}); + }); connect(s.get(), &UserSettings::groupViewStateChanged, this, [this]() { emit dataChanged(index(GroupView), index(GroupView), {Value}); }); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h
index ebe46672..67fa89c7 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h
@@ -40,6 +40,8 @@ class UserSettings : public QObject Q_PROPERTY(bool startInTray READ startInTray WRITE setStartInTray NOTIFY startInTrayChanged) Q_PROPERTY(bool groupView READ groupView WRITE setGroupView NOTIFY groupViewStateChanged) Q_PROPERTY(bool markdown READ markdown WRITE setMarkdown NOTIFY markdownChanged) + Q_PROPERTY(bool bubbles READ bubbles WRITE setBubbles NOTIFY bubblesChanged) + Q_PROPERTY(bool smallAvatars READ smallAvatars WRITE setSmallAvatars NOTIFY smallAvatarsChanged) Q_PROPERTY(bool animateImagesOnHover READ animateImagesOnHover WRITE setAnimateImagesOnHover NOTIFY animateImagesOnHoverChanged) Q_PROPERTY(bool typingNotifications READ typingNotifications WRITE setTypingNotifications NOTIFY @@ -141,6 +143,8 @@ public: void setEmojiFontFamily(QString family); void setGroupView(bool state); void setMarkdown(bool state); + void setBubbles(bool state); + void setSmallAvatars(bool state); void setAnimateImagesOnHover(bool state); void setReadReceipts(bool state); void setTypingNotifications(bool state); @@ -193,6 +197,8 @@ public: bool privacyScreen() const { return privacyScreen_; } int privacyScreenTimeout() const { return privacyScreenTimeout_; } bool markdown() const { return markdown_; } + bool bubbles() const { return bubbles_; } + bool smallAvatars() const { return smallAvatars_; } bool animateImagesOnHover() const { return animateImagesOnHover_; } bool typingNotifications() const { return typingNotifications_; } bool sortByImportance() const { return sortByImportance_; } @@ -251,6 +257,8 @@ signals: void trayChanged(bool state); void startInTrayChanged(bool state); void markdownChanged(bool state); + void bubblesChanged(bool state); + void smallAvatarsChanged(bool state); void animateImagesOnHoverChanged(bool state); void typingNotificationsChanged(bool state); void buttonInTimelineChanged(bool state); @@ -307,6 +315,8 @@ private: bool startInTray_; bool groupView_; bool markdown_; + bool bubbles_; + bool smallAvatars_; bool animateImagesOnHover_; bool typingNotifications_; bool sortByImportance_; @@ -386,7 +396,8 @@ class UserSettingsModel : public QAbstractListModel ReadReceipts, ButtonsInTimeline, Markdown, - + Bubbles, + SmallAvatars, SidebarSection, GroupView, SortByImportance, diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 662bbb38..fe92fcf7 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -467,6 +467,7 @@ TimelineModel::roleNames() const {UserId, "userId"}, {UserName, "userName"}, {PreviousMessageDay, "previousMessageDay"}, + {PreviousMessageIsStateEvent, "previousMessageIsStateEvent"}, {Day, "day"}, {Timestamp, "timestamp"}, {Url, "url"}, @@ -483,6 +484,7 @@ TimelineModel::roleNames() const {IsEdited, "isEdited"}, {IsEditable, "isEditable"}, {IsEncrypted, "isEncrypted"}, + {IsStateEvent, "isStateEvent"}, {Trustlevel, "trustlevel"}, {EncryptionError, "encryptionError"}, {ReplyTo, "replyTo"}, @@ -680,6 +682,9 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r std::holds_alternative<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( *encrypted_event); } + case IsStateEvent: { + return is_state_event(event); + } case Trustlevel: { auto encrypted_event = events.get(event_id(event), "", false); @@ -744,6 +749,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r m.insert(names[IsEdited], data(event, static_cast<int>(IsEdited))); m.insert(names[IsEditable], data(event, static_cast<int>(IsEditable))); m.insert(names[IsEncrypted], data(event, static_cast<int>(IsEncrypted))); + m.insert(names[IsStateEvent], data(event, static_cast<int>(IsStateEvent))); m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo))); m.insert(names[RoomName], data(event, static_cast<int>(RoomName))); m.insert(names[RoomTopic], data(event, static_cast<int>(RoomTopic))); @@ -776,7 +782,8 @@ TimelineModel::data(const QModelIndex &index, int role) const if (!event) return ""; - if (role == PreviousMessageDay || role == PreviousMessageUserId) { + if (role == PreviousMessageDay || role == PreviousMessageUserId || + role == PreviousMessageIsStateEvent) { int prevIdx = rowCount() - index.row() - 2; if (prevIdx < 0) return {}; @@ -785,8 +792,10 @@ TimelineModel::data(const QModelIndex &index, int role) const return {}; if (role == PreviousMessageUserId) return data(*tempEv, UserId); - else + else if (role == PreviousMessageDay) return data(*tempEv, Day); + else + return data(*tempEv, IsStateEvent); } return data(*event, role); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 6cdff285..e4e3fa9d 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -210,6 +210,7 @@ public: UserId, UserName, PreviousMessageDay, + PreviousMessageIsStateEvent, Day, Timestamp, Url, @@ -226,6 +227,7 @@ public: IsEdited, IsEditable, IsEncrypted, + IsStateEvent, Trustlevel, EncryptionError, ReplyTo,