From ed9501023ae57e668a930e5d3accbb47ad3d7812 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 5 May 2018 16:38:41 +0300 Subject: Add support for retrieving the notification events (#33) --- include/Cache.h | 7 +++++++ include/ChatPage.h | 2 ++ include/MatrixClient.h | 2 ++ include/Utils.h | 34 ++++++++++++++++++++++++++++++++++ include/timeline/TimelineView.h | 3 --- 5 files changed, 45 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/Cache.h b/include/Cache.h index 0829acf5..1fa6c430 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -233,6 +233,12 @@ public: std::vector searchRooms(const std::string &query, std::uint8_t max_items = 5); + void markSentNotification(const std::string &event_id); + //! Removes an event from the sent notifications. + void removeReadNotification(const std::string &event_id); + //! Check if we have sent a desktop notification for the given event id. + bool isNotificationSent(const std::string &event_id); + private: //! Save an invited room. void saveInvite(lmdb::txn &txn, @@ -422,6 +428,7 @@ private: lmdb::dbi invitesDb_; lmdb::dbi mediaDb_; lmdb::dbi readReceiptsDb_; + lmdb::dbi notificationsDb_; QString localUserId_; QString cacheDirectory_; diff --git a/include/ChatPage.h b/include/ChatPage.h index 147ff6b2..f659163c 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -136,6 +136,8 @@ private: //! Update the room with the new notification count. void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count); + //! Send desktop notification for the received messages. + void sendDesktopNotifications(const mtx::responses::Notifications &); QStringList generateTypingUsers(const QString &room_id, const std::vector &typing_users); diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 1be15e56..35f05c31 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -91,6 +91,7 @@ public: void redactEvent(const QString &room_id, const QString &event_id); void inviteUser(const QString &room_id, const QString &user); void createRoom(const mtx::requests::CreateRoom &request); + void getNotifications() noexcept; QUrl getHomeServer() { return server_; }; int transactionId() { return txn_id_; }; @@ -178,6 +179,7 @@ signals: void redactionCompleted(const QString &room_id, const QString &event_id); void invalidToken(); void syncError(const QString &error); + void notificationsRetrieved(const mtx::responses::Notifications ¬ifications); private: QNetworkReply *makeUploadRequest(QSharedPointer iodev); diff --git a/include/Utils.h b/include/Utils.h index c9dc460a..6fea4962 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -32,6 +32,9 @@ firstChar(const QString &input); QString humanReadableFileSize(uint64_t bytes); +QString +event_body(const mtx::events::collections::TimelineEvents &event); + //! Match widgets/events with a description message. template QString @@ -131,6 +134,37 @@ erase_if(ContainerT &items, const PredicateT &predicate) } } +inline mtx::events::EventType +event_type(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return msg.type; }, event); +} + +inline std::string +event_id(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return msg.event_id; }, event); +} + +inline QString +eventId(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(event_id(event)); +} + +inline QString +event_sender(const mtx::events::collections::TimelineEvents &event) +{ + return mpark::visit([](auto msg) { return QString::fromStdString(msg.sender); }, event); +} + +template +QString +message_body(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(mpark::get(event).content.body); +} + //! Calculate the Levenshtein distance between two strings with character skipping. int levenshtein_distance(const std::string &s1, const std::string &s2); diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index ab4fbd47..02e2872a 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -211,9 +211,6 @@ private: bool isScrollbarActivated() { return scroll_area_->verticalScrollBar()->value() != 0; } //! Retrieve the event id of the last item. QString getLastEventId() const; - QString getEventSender(const mtx::events::collections::TimelineEvents &event) const; - mtx::events::EventType getEventType( - const mtx::events::collections::TimelineEvents &event) const; template TimelineItem *processMessageEvent(const Event &event, TimelineDirection direction); -- cgit 1.5.1