Skip to content
Snippets Groups Projects
Commit a219d292 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Add basic notification support

Partly stolen from depecher.
parent 033bdbd7
No related branches found
No related tags found
No related merge requests found
Pipeline #71 passed
......@@ -20,6 +20,7 @@ sailfish_dep = dependency('sailfishapp')
#networkstate_dep = dependency('statefs-qt5')
networkstate_dep = dependency('contextkit-statefs')
keepalive_dep = dependency('keepalive')
notifications_dep = dependency('nemonotifications-qt5')
threads_dep = dependency('threads')
# generate dbus
......@@ -31,7 +32,7 @@ gen_xml = custom_target('gen-dbus-xml',
install: true,
install_dir: 'share/dbus-1/interfaces')
deps = [qt5_dep, zlib_dep, olm_dep, matrix_dep, json_dep, ssl_dep, sailfish_dep, threads_dep, boost_dep, networkstate_dep, keepalive_dep]
deps = [qt5_dep, zlib_dep, olm_dep, matrix_dep, json_dep, ssl_dep, sailfish_dep, threads_dep, boost_dep, networkstate_dep, keepalive_dep, notifications_dep]
defines = ['-DBOOST_ASIO_DISABLE_EPOLL']
extra_flags = ['-Winvalid-pch']
......@@ -97,3 +98,4 @@ install_data('icons/128x128/harbour-spoon.png',
install_data('icons/172x172/harbour-spoon.png',
install_dir: 'share/icons/hicolor/172x172/apps')
......@@ -71,7 +71,7 @@ void DBusActivator::showApp() {
}
}
void DBusActivator::openRoom(const QString &roomId) {}
void DBusActivator::openRoom(const QString &roomId) { showApp(); }
void DBusActivator::onViewDestroyed()
{
......
......@@ -8,6 +8,8 @@
#include <QDebug>
#include <notification.h>
#include "client.h"
#include "debug_out.h"
......@@ -160,9 +162,56 @@ Room::Room(QObject *parent) : loadingOlderMessages(false) {
Q_UNUSED(parent);
connect(this, &Room::newEvents, this, &Room::addEvents, Qt::QueuedConnection);
connect(this, &Room::newTags, this, &Room::setTags, Qt::QueuedConnection);
connect(this, &Room::newUnreadState, this, &Room::setUnread, Qt::QueuedConnection);
connect(this, &Room::lastReadSig, this, &Room::lastReadSlot, Qt::AutoConnection);
connect(this, &Room::markReadSig, this, &Room::markReadSlot, Qt::AutoConnection);
connect(
this, &Room::newUnreadState, this,
[this](int notificationCount) {
if (notificationCount == this->unreadNotifications)
return;
setUnread(notificationCount);
Notification n;
n.setReplacesId(this->notificationId);
if (notificationCount == 0) {
n.close();
this->notificationId = 0;
return;
}
QString username = this->msgInfo.userid;
try {
username = QString::fromStdString(this->memberInfos.at(username.toStdString()).display_name);
} catch (...) {
}
n.setAppIcon("harbour-spoon");
n.setAppName(tr("Spoon"));
n.setCategory("x-nemo.messaging.im");
n.setItemCount(notificationCount);
n.setSummary(roomName());
if (notificationCount == 1)
n.setBody(this->msgInfo.userid + ": " + this->msgInfo.body);
else
n.setBody(tr("%n new messages", "Notification", notificationCount));
n.setPreviewSummary(roomName());
n.setPreviewBody(this->msgInfo.userid + ": " + this->msgInfo.body);
n.setTimestamp(this->msgInfo.datetime);
n.setHintValue("x-nemo-priority", 101);
QVariantList arguments;
arguments.append(QString::fromStdString(id));
QVariantList actions;
actions.append(Notification::remoteAction("default", "openRoom", "dev.neko.spoon", "/dev/neko/spoon",
"dev.neko.spoon", "openRoom", arguments));
n.setRemoteActions(actions);
n.publish();
this->notificationId = n.replacesId();
},
Qt::QueuedConnection);
this->moveToThread(QGuiApplication::instance()->thread());
}
......
......@@ -211,4 +211,6 @@ struct Room : public QAbstractListModel {
int member_count_ = 0;
std::string lastRead_;
quint32 notificationId = 0;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment