Show notifications
This commit is contained in:
@@ -49,6 +49,7 @@ if(ANDROID)
|
||||
"go-down"
|
||||
"list-add"
|
||||
"irc-join-channel"
|
||||
"settings-configure"
|
||||
)
|
||||
else()
|
||||
target_link_libraries(neochat PRIVATE Qt5::Widgets ${QTKEYCHAIN_LIBRARIES})
|
||||
|
||||
@@ -72,7 +72,6 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterType<PublicRoomListModel>("org.kde.neochat", 1, 0, "PublicRoomListModel");
|
||||
qmlRegisterType<UserDirectoryListModel>("org.kde.neochat", 1, 0, "UserDirectoryListModel");
|
||||
qmlRegisterType<EmojiModel>("org.kde.neochat", 1, 0, "EmojiModel");
|
||||
qmlRegisterType<NotificationsManager>("org.kde.neochat", 1, 0, "NotificationsManager");
|
||||
qmlRegisterType<TrayIcon>("org.kde.neochat", 1, 0, "TrayIcon");
|
||||
qmlRegisterType<SortFilterRoomListModel>("org.kde.neochat", 1, 0, "SortFilterRoomListModel");
|
||||
qmlRegisterUncreatableType<RoomMessageEvent>("org.kde.neochat", 1, 0, "RoomMessageEvent", "ENUM");
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
<entry name="OpenRoom" type="String">
|
||||
<label>Latest opened room</label>
|
||||
</entry>
|
||||
<entry name="ShowNotifications" type="bool">
|
||||
<label>Show notifications</label>
|
||||
<default>true</default>
|
||||
</entry>
|
||||
</group>
|
||||
</kcfg>
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "jobs/downloadfilejob.h"
|
||||
#include "user.h"
|
||||
#include "utils.h"
|
||||
#include "notificationsmanager.h"
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
@@ -43,6 +44,18 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
||||
setFileUploadingProgress(0);
|
||||
setHasFileUploading(false);
|
||||
});
|
||||
connect(this, &NeoChatRoom::notificationCountChanged, this, [this]() {
|
||||
if(messageEvents().size() == 0)
|
||||
return;
|
||||
const RoomEvent *lastEvent = messageEvents().rbegin()->get();
|
||||
if (lastEvent->isStateEvent())
|
||||
return;
|
||||
User *sender = user(lastEvent->senderId());
|
||||
if (sender == localUser())
|
||||
return;
|
||||
|
||||
NotificationsManager::instance().postNotification(id(), lastEvent->id(), displayName(), sender->displayname(this), eventToString(*lastEvent), avatar(128));
|
||||
});
|
||||
}
|
||||
|
||||
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
|
||||
|
||||
@@ -11,6 +11,15 @@
|
||||
#include <KLocalizedString>
|
||||
#include <KNotification>
|
||||
|
||||
#include "neochatconfig.h"
|
||||
|
||||
NotificationsManager &NotificationsManager::instance()
|
||||
{
|
||||
static NotificationsManager _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
@@ -18,6 +27,10 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
||||
|
||||
void NotificationsManager::postNotification(const QString &roomid, const QString &eventid, const QString &roomname, const QString &sender, const QString &text, const QImage &icon)
|
||||
{
|
||||
if(!NeoChatConfig::self()->showNotifications()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPixmap img;
|
||||
img.convertFromImage(icon);
|
||||
KNotification *notification = new KNotification("message");
|
||||
|
||||
@@ -17,10 +17,12 @@ class NotificationsManager : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NotificationsManager(QObject *parent = nullptr);
|
||||
static NotificationsManager &instance();
|
||||
|
||||
Q_INVOKABLE void postNotification(const QString &roomId, const QString &eventId, const QString &roomName, const QString &senderName, const QString &text, const QImage &icon);
|
||||
|
||||
private:
|
||||
NotificationsManager(QObject *parent = nullptr);
|
||||
|
||||
QMultiMap<QString, KNotification *> m_notifications;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user