diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c65f9e0..759f610a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,7 +337,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG 795b6a82d4f10c629ce0eb99803cc677c413f940 + GIT_TAG a897142a3fa6ece92daa1040551fb8ac09be1766 ) FetchContent_MakeAvailable(MatrixClient) else() diff --git a/io.github.NhekoReborn.Nheko.json b/io.github.NhekoReborn.Nheko.json index 7ffb1995..feeb1960 100644 --- a/io.github.NhekoReborn.Nheko.json +++ b/io.github.NhekoReborn.Nheko.json @@ -146,9 +146,9 @@ "name": "mtxclient", "sources": [ { - "sha256": "7ba85bb477c9e17e2389faf2333034aa9ceae4b1c65d6bf5f7067f2799e9b770", + "sha256": "6a4368da5fda1db426c36c9a7b26c6e62ca99bd8c7fea421460156642e65a5cb", "type": "archive", - "url": "https://github.com/Nheko-Reborn/mtxclient/archive/795b6a82d4f10c629ce0eb99803cc677c413f940.tar.gz" + "url": "https://github.com/Nheko-Reborn/mtxclient/archive/a897142a3fa6ece92daa1040551fb8ac09be1766.tar.gz" } ] }, diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index 351eec65..1ba57370 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. Du bist dem Raum beigetreten. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 Nutzer konnte nicht eingeladen werden: %1 - + Invited user: %1 Eingeladener Benutzer: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. Migrieren des Caches auf die aktuelle Version fehlgeschlagen. Das kann verschiedene Gründe als Ursache haben. Bitte lege einen Bugreport an und verwende in der Zwischenzeit eine ältere Version. Alternativ kannst du das Cache manuell entfernen. - + Room %1 created. Raum %1 erzeugt. @@ -68,7 +68,7 @@ Verbannung von %1 wurde aufgehoben. - + Failed to upload media. Please try again. Medienupload fehlgeschlagen. Bitte versuche es erneut. @@ -103,13 +103,13 @@ Fehler beim Setup der Verschlüsselungsschlüssel. Servermeldung: %1 %2. Bitte versuche es später erneut. - - + + Please try to login again: %1 Bitte melde dich erneut an: %1 - + Failed to join room: %1 Konnte Raum nicht betreten: %1 @@ -492,7 +492,7 @@ Beispiel: https://mein.server:8787 RoomInfo - + no version stored keine Version gespeichert @@ -921,7 +921,7 @@ Beispiel: https://mein.server:8787 Kein Raum geöffnet - + Close Schließen @@ -975,15 +975,50 @@ Beispiel: https://mein.server:8787 UserInfoWidget - + Logout Abmelden + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Ins Benachrichtigungsfeld minimieren diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 1e612ea1..47405976 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ - - + + Please try to login again: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -917,7 +917,7 @@ Example: https://server.my:8787 - + Close @@ -971,15 +971,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Ελαχιστοποίηση diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index 91e8a061..db24f1fe 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 Failed to invite user: %1 - + Invited user: %1 Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. Room %1 created. @@ -68,7 +68,7 @@ Unbanned user: %1 - + Failed to upload media. Please try again. Failed to upload media. Please try again. @@ -103,13 +103,13 @@ Failed to setup encryption keys. Server response: %1 %2. Please try again later. - - + + Please try to login again: %1 Please try to login again: %1 - + Failed to join room: %1 Failed to join room: %1 @@ -492,7 +492,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored no version stored @@ -921,7 +921,7 @@ Example: https://server.my:8787 No room open - + Close Close @@ -975,15 +975,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout Logout + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Minimize to tray diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index 648bc7b9..9e95ed62 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ Salausavainten lähetys epäonnistui. Palvelimen vastaus: %1 %2. Ole hyvä ja yritä uudelleen myöhemmin. - - + + Please try to login again: %1 Ole hyvä ja yritä kirjautua sisään uudelleen: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored ei tallennettua versiota @@ -917,7 +917,7 @@ Example: https://server.my:8787 - + Close Sulje @@ -971,15 +971,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout Kirjaudu ulos + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Pienennä ilmoitusalueelle diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index e1daa315..bf9b36f6 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ - - + + Please try to login again: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -917,7 +917,7 @@ Example: https://server.my:8787 - + Close @@ -971,15 +971,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Réduire à la barre des tâches diff --git a/resources/langs/nheko_it.ts b/resources/langs/nheko_it.ts index 59132966..b5026408 100644 --- a/resources/langs/nheko_it.ts +++ b/resources/langs/nheko_it.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. Sei entrato in questa stanza. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 Impossibile invitare l'utente: %1 - + Invited user: %1 Invitato utente: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. Migrazione della cache alla versione corrente fallita. Questo può avere diverse cause. Per favore apri una issue e nel frattempo prova ad usare una versione più vecchia. In alternativa puoi provare a cancellare la cache manualmente. - + Room %1 created. Stanza %1 creata. @@ -68,7 +68,7 @@ Rimosso il ban dall'utente: %1 - + Failed to upload media. Please try again. Impossibile inviare il file multimediale. Per favore riprova. @@ -103,13 +103,13 @@ Impossibile configurare le chiavi crittografiche. Risposta del server: %1 %2. Per favore riprova in seguito. - - + + Please try to login again: %1 Per favore prova ad accedere nuovamente: %1 - + Failed to join room: %1 Impossibile accedere alla stanza: %1 @@ -492,7 +492,7 @@ Esempio: https://server.mio:8787 RoomInfo - + no version stored nessuna versione memorizzata @@ -921,7 +921,7 @@ Esempio: https://server.mio:8787 Nessuna stanza aperta - + Close Chiudi @@ -975,15 +975,50 @@ Esempio: https://server.mio:8787 UserInfoWidget - + Logout Disconnettiti + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Minimizza nella tray diff --git a/resources/langs/nheko_ja.ts b/resources/langs/nheko_ja.ts index beb3cbde..a806031b 100644 --- a/resources/langs/nheko_ja.ts +++ b/resources/langs/nheko_ja.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 ユーザーを招待できませんでした: %1 - + Invited user: %1 招待されたユーザー: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ 永久追放を解除されたユーザー: %1 - + Failed to upload media. Please try again. メディアをアップロードできませんでした。やり直して下さい。 @@ -103,13 +103,13 @@ 暗号化鍵を設定できませんでした。サーバーの応答: %1 %2. 後でやり直して下さい。 - - + + Please try to login again: %1 もう一度ログインしてみて下さい: %1 - + Failed to join room: %1 部屋に参加できませんでした: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored バージョンが保存されていません @@ -916,7 +916,7 @@ Example: https://server.my:8787 部屋が開いていません - + Close 閉じる @@ -970,15 +970,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout ログアウト + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray トレイへ最小化 diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index bd02caf6..8d6a9f68 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ - - + + Please try to login again: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -917,7 +917,7 @@ Example: https://server.my:8787 - + Close @@ -971,15 +971,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Minimaliseren naar systeemvak diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index c93aae67..934221a2 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ - - + + Please try to login again: %1 Spróbuj zalogować się ponownie: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -918,7 +918,7 @@ Example: https://server.my:8787 - + Close @@ -972,15 +972,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout Wyloguj + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Zminimalizuj do paska zadań diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 3a900f9d..541b0df9 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ Не удалось настроить ключи шифрования. Ответ сервера:%1 %2. Пожалуйста, попробуйте позже. - - + + Please try to login again: %1 Повторите попытку входа: %1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -918,7 +918,7 @@ Example: https://server.my:8787 - + Close Закрыть @@ -972,15 +972,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout Выйти + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray Сворачивать в системную панель diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index ca7e04ca..545e098b 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -4,7 +4,7 @@ Cache - + You joined this room. @@ -12,23 +12,23 @@ ChatPage - + Failed to invite user: %1 - + Invited user: %1 - + Migrating the cache to the current version failed. This can have different reasons. Please open an issue and try to use an older version in the mean time. Alternatively you can try deleting the cache manually. - + Room %1 created. @@ -68,7 +68,7 @@ - + Failed to upload media. Please try again. @@ -103,13 +103,13 @@ - - + + Please try to login again: %1 请尝试再次登录:%1 - + Failed to join room: %1 @@ -488,7 +488,7 @@ Example: https://server.my:8787 RoomInfo - + no version stored @@ -916,7 +916,7 @@ Example: https://server.my:8787 - + Close @@ -970,15 +970,50 @@ Example: https://server.my:8787 UserInfoWidget - + Logout 登出 + + + Set custom status message + + + + + Custom status message + + + + + Status: + + + + + Set presence automatically + + + + + Online + + + + + Unavailable + + + + + Offline + + UserSettingsPage - + Minimize to tray 最小化至托盘 diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml index 465a8e1c..9ac7b562 100644 --- a/resources/qml/Avatar.qml +++ b/resources/qml/Avatar.qml @@ -9,6 +9,7 @@ Rectangle { radius: settings.avatarCircles ? height/2 : 3 property alias url: img.source + property string userid property string displayName Label { @@ -42,6 +43,23 @@ Rectangle { radius: settings.avatarCircles ? height/2 : 3 } } + } + + Rectangle { + anchors.bottom: avatar.bottom + anchors.right: avatar.right + + height: avatar.height / 6 + width: height + radius: settings.avatarCircles ? height / 2 : height / 4 + color: switch (timelineManager.userPresence(userid)) { + case "online": return "#00cc66" + case "unavailable": return "#ff9933" + case "offline": return "#a82353" + default: "transparent" + } + } + color: colors.base } diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index a468e0ef..f3d5d219 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -171,6 +171,8 @@ Page { onCountChanged: if (atYEnd) model.currentIndex = 0 // Mark last event as read, since we are at the bottom + property int delegateMaxWidth: (settings.timelineMaxWidth > 100 && (parent.width - settings.timelineMaxWidth) > 32) ? settings.timelineMaxWidth : (parent.width - 32) + delegate: Rectangle { // This would normally be previousSection, but our model's order is inverted. property bool sectionBoundary: (ListView.nextSection != "" && ListView.nextSection !== ListView.section) || model.index === chat.count - 1 @@ -178,7 +180,7 @@ Page { id: wrapper property Item section anchors.horizontalCenter: parent.horizontalCenter - width: (settings.timelineMaxWidth > 100 && (parent.width - settings.timelineMaxWidth) > 32) ? settings.timelineMaxWidth : (parent.width - 32) + width: chat.delegateMaxWidth height: section ? section.height + timelinerow.height : timelinerow.height color: "transparent" @@ -255,6 +257,7 @@ Page { height: avatarSize url: chat.model.avatarUrl(modelData.userId).replace("mxc://", "image://MxcImage/") displayName: modelData.userName + userid: modelData.userId MouseArea { anchors.fill: parent @@ -277,6 +280,15 @@ Page { propagateComposedEvents: true } } + + Label { + color: colors.buttonText + text: timelineManager.userStatus(modelData.userId) + textFormat: Text.PlainText + elide: Text.ElideRight + width: chat.delegateMaxWidth - parent.spacing*2 - userName.implicitWidth - avatarSize + font.italic: true + } } } } diff --git a/src/Cache.cpp b/src/Cache.cpp index 009cbabc..d9d1134e 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -952,6 +952,8 @@ Cache::saveState(const mtx::responses::Sync &res) saveInvites(txn, res.rooms.invite); + savePresence(txn, res.presence); + removeLeftRooms(txn, res.rooms.leave); txn.commit(); @@ -1037,6 +1039,21 @@ Cache::saveInvite(lmdb::txn &txn, } } +void +Cache::savePresence( + lmdb::txn &txn, + const std::vector> &presenceUpdates) +{ + for (const auto &update : presenceUpdates) { + auto presenceDb = getPresenceDb(txn); + + lmdb::dbi_put(txn, + presenceDb, + lmdb::val(update.sender), + lmdb::val(json(update.content).dump())); + } +} + std::vector Cache::roomsWithStateUpdates(const mtx::responses::Sync &res) { @@ -2254,6 +2271,50 @@ Cache::removeAvatarUrl(const QString &room_id, const QString &user_id) AvatarUrls.remove(fmt); } +mtx::presence::PresenceState +Cache::presenceState(const std::string &user_id) +{ + lmdb::val presenceVal; + + auto txn = lmdb::txn::begin(env_); + auto db = getPresenceDb(txn); + auto res = lmdb::dbi_get(txn, db, lmdb::val(user_id), presenceVal); + + mtx::presence::PresenceState state = mtx::presence::offline; + + if (res) { + mtx::events::presence::Presence presence = + json::parse(std::string(presenceVal.data(), presenceVal.size())); + state = presence.presence; + } + + txn.commit(); + + return state; +} + +std::string +Cache::statusMessage(const std::string &user_id) +{ + lmdb::val presenceVal; + + auto txn = lmdb::txn::begin(env_); + auto db = getPresenceDb(txn); + auto res = lmdb::dbi_get(txn, db, lmdb::val(user_id), presenceVal); + + std::string status_msg; + + if (res) { + mtx::events::presence::Presence presence = + json::parse(std::string(presenceVal.data(), presenceVal.size())); + status_msg = presence.status_msg; + } + + txn.commit(); + + return status_msg; +} + void to_json(json &j, const RoomInfo &info) { @@ -2425,6 +2486,17 @@ insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &a instance_->insertAvatarUrl(room_id, user_id, avatar_url); } +mtx::presence::PresenceState +presenceState(const std::string &user_id) +{ + return instance_->presenceState(user_id); +} +std::string +statusMessage(const std::string &user_id) +{ + return instance_->statusMessage(user_id); +} + //! Load saved data for the display names & avatars. void populateMembers() diff --git a/src/Cache.h b/src/Cache.h index 12465c9d..b5275623 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -54,6 +54,12 @@ insertDisplayName(const QString &room_id, const QString &user_id, const QString void insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &avatar_url); +// presence +mtx::presence::PresenceState +presenceState(const std::string &user_id); +std::string +statusMessage(const std::string &user_id); + //! Load saved data for the display names & avatars. void populateMembers(); diff --git a/src/Cache_p.h b/src/Cache_p.h index 0d66a608..892b66a5 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -52,6 +52,10 @@ public: static QString displayName(const QString &room_id, const QString &user_id); static QString avatarUrl(const QString &room_id, const QString &user_id); + // presence + mtx::presence::PresenceState presenceState(const std::string &user_id); + std::string statusMessage(const std::string &user_id); + static void removeDisplayName(const QString &room_id, const QString &user_id); static void removeAvatarUrl(const QString &room_id, const QString &user_id); @@ -377,6 +381,10 @@ private: void saveInvites(lmdb::txn &txn, const std::map &rooms); + void savePresence( + lmdb::txn &txn, + const std::vector> &presenceUpdates); + //! Sends signals for the rooms that are removed. void removeLeftRooms(lmdb::txn &txn, const std::map &rooms) @@ -430,6 +438,11 @@ private: return lmdb::dbi::open(txn, std::string(room_id + "/mentions").c_str(), MDB_CREATE); } + lmdb::dbi getPresenceDb(lmdb::txn &txn) + { + return lmdb::dbi::open(txn, "presence", MDB_CREATE); + } + //! Retrieves or creates the database that stores the open OLM sessions between our device //! and the given curve25519 key which represents another device. //! diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 0ca20c52..3b8af33a 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -61,6 +61,7 @@ constexpr size_t MAX_ONETIME_KEYS = 50; Q_DECLARE_METATYPE(std::optional) Q_DECLARE_METATYPE(std::optional) +Q_DECLARE_METATYPE(mtx::presence::PresenceState) ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) : QWidget(parent) @@ -72,6 +73,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) qRegisterMetaType>(); qRegisterMetaType>(); + qRegisterMetaType(); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); @@ -990,7 +992,9 @@ ChatPage::startInitialSync() nhlog::net()->info("trying initial sync"); mtx::http::SyncOpts opts; - opts.timeout = 0; + opts.timeout = 0; + opts.set_presence = currentPresence(); + http::client()->sync( opts, std::bind( @@ -1001,6 +1005,7 @@ void ChatPage::trySync() { mtx::http::SyncOpts opts; + opts.set_presence = currentPresence(); if (!connectivityTimer_.isActive()) connectivityTimer_.start(); @@ -1228,6 +1233,39 @@ ChatPage::sendTypingNotifications() }); } +QString +ChatPage::status() const +{ + return QString::fromStdString(cache::statusMessage(utils::localUser().toStdString())); +} + +void +ChatPage::setStatus(const QString &status) +{ + http::client()->put_presence_status( + currentPresence(), status.toStdString(), [](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to set presence status_msg: {}", + err->matrix_error.error); + } + }); +} + +mtx::presence::PresenceState +ChatPage::currentPresence() const +{ + switch (userSettings_->presence()) { + case UserSettings::Presence::Online: + return mtx::presence::online; + case UserSettings::Presence::Unavailable: + return mtx::presence::unavailable; + case UserSettings::Presence::Offline: + return mtx::presence::offline; + default: + return mtx::presence::online; + } +} + void ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err) { diff --git a/src/ChatPage.h b/src/ChatPage.h index 8c33a63e..c38d7717 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -89,6 +89,11 @@ public: void initiateLogout(); void focusMessageInput(); + QString status() const; + void setStatus(const QString &status); + + mtx::presence::PresenceState currentPresence() const; + public slots: void leaveRoom(const QString &room_id); void createRoom(const mtx::requests::CreateRoom &req); @@ -154,6 +159,7 @@ signals: const QImage &icon); void updateGroupsInfo(const mtx::responses::JoinedGroups &groups); + void retrievedPresence(const QString &statusMsg, mtx::presence::PresenceState state); void themeChanged(); void decryptSidebarChanged(); diff --git a/src/UserInfoWidget.cpp b/src/UserInfoWidget.cpp index e11aa6aa..f8e94431 100644 --- a/src/UserInfoWidget.cpp +++ b/src/UserInfoWidget.cpp @@ -16,7 +16,9 @@ * along with this program. If not, see . */ +#include #include +#include #include #include #include @@ -24,10 +26,12 @@ #include +#include "ChatPage.h" #include "Config.h" #include "MainWindow.h" #include "Splitter.h" #include "UserInfoWidget.h" +#include "UserSettingsPage.h" #include "ui/Avatar.h" #include "ui/FlatButton.h" #include "ui/OverlayModal.h" @@ -105,6 +109,52 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) connect(logoutButton_, &QPushButton::clicked, this, []() { MainWindow::instance()->openLogoutDialog(); }); + + menu = new QMenu(this); + + auto setStatusAction = menu->addAction(tr("Set custom status message")); + connect(setStatusAction, &QAction::triggered, this, [this]() { + bool ok = false; + QString text = QInputDialog::getText(this, + tr("Custom status message"), + tr("Status:"), + QLineEdit::Normal, + ChatPage::instance()->status(), + &ok); + if (ok) + ChatPage::instance()->setStatus(text); + }); + +#if 0 // disable presence menu until issues in synapse are resolved + auto setAutoPresence = menu->addAction(tr("Set presence automatically")); + connect(setAutoPresence, &QAction::triggered, this, []() { + ChatPage::instance()->userSettings()->setPresence( + UserSettings::Presence::AutomaticPresence); + ChatPage::instance()->setStatus(ChatPage::instance()->status()); + }); + auto setOnline = menu->addAction(tr("Online")); + connect(setOnline, &QAction::triggered, this, []() { + ChatPage::instance()->userSettings()->setPresence(UserSettings::Presence::Online); + ChatPage::instance()->setStatus(ChatPage::instance()->status()); + }); + auto setUnavailable = menu->addAction(tr("Unavailable")); + connect(setUnavailable, &QAction::triggered, this, []() { + ChatPage::instance()->userSettings()->setPresence( + UserSettings::Presence::Unavailable); + ChatPage::instance()->setStatus(ChatPage::instance()->status()); + }); + auto setOffline = menu->addAction(tr("Offline")); + connect(setOffline, &QAction::triggered, this, []() { + ChatPage::instance()->userSettings()->setPresence(UserSettings::Presence::Offline); + ChatPage::instance()->setStatus(ChatPage::instance()->status()); + }); +#endif +} + +void +UserInfoWidget::contextMenuEvent(QContextMenuEvent *event) +{ + menu->popup(event->globalPos()); } void diff --git a/src/UserInfoWidget.h b/src/UserInfoWidget.h index 575ade52..03ab2cf0 100644 --- a/src/UserInfoWidget.h +++ b/src/UserInfoWidget.h @@ -26,6 +26,7 @@ class OverlayModal; class QLabel; class QHBoxLayout; class QVBoxLayout; +class QMenu; class UserInfoWidget : public QWidget { @@ -48,6 +49,7 @@ public: protected: void resizeEvent(QResizeEvent *event) override; void paintEvent(QPaintEvent *event) override; + void contextMenuEvent(QContextMenuEvent *) override; private: Avatar *userAvatar_; @@ -70,4 +72,6 @@ private: int logoutButtonSize_; QColor borderColor_; + + QMenu *menu = nullptr; }; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 4e9e0cb0..88cbd1c9 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "Cache.h" #include "Config.h" @@ -73,6 +74,9 @@ UserSettings::load() decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); + presence_ = + settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence)) + .value(); applyTheme(); } @@ -254,6 +258,16 @@ UserSettings::setEmojiFontFamily(QString family) save(); } +void +UserSettings::setPresence(Presence state) +{ + if (state == presence_) + return; + presence_ = state; + emit presenceChanged(state); + save(); +} + void UserSettings::setTheme(QString theme) { @@ -349,6 +363,7 @@ UserSettings::save() settings.setValue("theme", theme()); settings.setValue("font_family", font_); settings.setValue("emoji_font_family", emojiFont_); + settings.setValue("presence", QVariant::fromValue(presence_)); settings.endGroup(); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index c90dc759..d2a1c641 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -70,10 +70,20 @@ class UserSettings : public QObject Q_PROPERTY(QString font READ font WRITE setFontFamily NOTIFY fontChanged) Q_PROPERTY( QString emojiFont READ emojiFont WRITE setEmojiFontFamily NOTIFY emojiFontChanged) + Q_PROPERTY(Presence presence READ presence WRITE setPresence NOTIFY presenceChanged) public: UserSettings(); + enum class Presence + { + AutomaticPresence, + Online, + Unavailable, + Offline, + }; + Q_ENUM(Presence); + void save(); void load(); void applyTheme(); @@ -96,6 +106,7 @@ public: void setAlertOnNotification(bool state); void setAvatarCircles(bool state); void setDecryptSidebar(bool state); + void setPresence(Presence state); QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool messageHoverHighlight() const { return messageHoverHighlight_; } @@ -120,6 +131,7 @@ public: double fontSize() const { return baseFontSize_; } QString font() const { return font_; } QString emojiFont() const { return emojiFont_; } + Presence presence() const { return presence_; } signals: void groupViewStateChanged(bool state); @@ -141,6 +153,7 @@ signals: void fontSizeChanged(double state); void fontChanged(QString state); void emojiFontChanged(QString state); + void presenceChanged(Presence state); private: // Default to system theme if QT_QPA_PLATFORMTHEME var is set. @@ -167,6 +180,7 @@ private: double baseFontSize_; QString font_; QString emojiFont_; + Presence presence_; }; class HorizontalLine : public QFrame diff --git a/src/main.cpp b/src/main.cpp index ec4f638d..46691e6f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,6 +104,18 @@ createCacheDirectory() int main(int argc, char *argv[]) { + // needed for settings so need to register before any settings are read to prevent warings + qRegisterMetaType(); + + QCoreApplication::setApplicationName("nheko"); + QCoreApplication::setApplicationVersion(nheko::version); + QCoreApplication::setOrganizationName("nheko"); + QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + // this needs to be after setting the application name. Or how would we find our settings + // file then? #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_FREEBSD) if (qgetenv("QT_SCALE_FACTOR").size() == 0) { float factor = utils::scaleFactor(); @@ -113,12 +125,6 @@ main(int argc, char *argv[]) } #endif - QCoreApplication::setApplicationName("nheko"); - QCoreApplication::setApplicationVersion(nheko::version); - QCoreApplication::setOrganizationName("nheko"); - QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); SingleApplication app(argc, argv, false, diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index d6f9fde1..151cfb4e 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -59,6 +59,18 @@ TimelineViewManager::userColor(QString id, QColor background) return userColors.value(id); } +QString +TimelineViewManager::userPresence(QString id) const +{ + return QString::fromStdString( + mtx::presence::to_string(cache::presenceState(id.toStdString()))); +} +QString +TimelineViewManager::userStatus(QString id) const +{ + return QString::fromStdString(cache::statusMessage(id.toStdString())); +} + TimelineViewManager::TimelineViewManager(QSharedPointer userSettings, QWidget *parent) : imgProvider(new MxcImageProvider()) , colorImgProvider(new ColorImageProvider()) diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 48505bc0..ed095058 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -44,6 +44,9 @@ public: Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const; Q_INVOKABLE QColor userColor(QString id, QColor background); + Q_INVOKABLE QString userPresence(QString id) const; + Q_INVOKABLE QString userStatus(QString id) const; + signals: void clearRoomMessageCount(QString roomid); void updateRoomsLastMessage(QString roomid, const DescInfo &info);