summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
commited9501023ae57e668a930e5d3accbb47ad3d7812 (patch)
tree11d0150f0bd3bae0013e67cbd3e184b778e9946b /include
parentAdd compile option for address sanitizers (diff)
downloadnheko-ed9501023ae57e668a930e5d3accbb47ad3d7812.tar.xz
Add support for retrieving the notification events (#33)
Diffstat (limited to 'include')
-rw-r--r--include/Cache.h7
-rw-r--r--include/ChatPage.h2
-rw-r--r--include/MatrixClient.h2
-rw-r--r--include/Utils.h34
-rw-r--r--include/timeline/TimelineView.h3
5 files changed, 45 insertions, 3 deletions
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<RoomSearchResult> 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<std::string> &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 &notifications); private: QNetworkReply *makeUploadRequest(QSharedPointer<QIODevice> 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<class T> 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<class T> +QString +message_body(const mtx::events::collections::TimelineEvents &event) +{ + return QString::fromStdString(mpark::get<T>(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<class Event, class Widget> TimelineItem *processMessageEvent(const Event &event, TimelineDirection direction);