Add support for retrieving the notification events (#33)

This commit is contained in:
Konstantinos Sideris 2018-05-05 16:38:41 +03:00
parent b47007d59a
commit ed9501023a
11 changed files with 192 additions and 26 deletions

View file

@ -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_;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);