Commit a56ffc3a authored by Robert Maerkisch's avatar Robert Maerkisch Committed by LNJ

Add functionality to mute notifications of contacts

parent 3e87d8b3
......@@ -174,6 +174,17 @@ void Kaidan::setDisconnReason(DisconnectionReason reason)
emit disconnReasonChanged();
}
bool Kaidan::notificationsMuted(const QString &jid)
{
return m_caches->settings->value(QString("muted/") + jid, false).toBool();
}
void Kaidan::setNotificationsMuted(const QString &jid, bool muted)
{
m_caches->settings->setValue(QString("muted/") + jid, muted);
emit notificationsMutedChanged(jid);
}
void Kaidan::setJid(const QString &jid)
{
creds.jid = jid;
......
......@@ -360,6 +360,11 @@ signals:
*/
void passwordChangeFailed();
/**
* Emitted, when a contact was muted/unmuted.
*/
void notificationsMutedChanged(const QString& jid);
public slots:
/**
* Set current connection state
......@@ -389,6 +394,19 @@ public slots:
emit uploadServiceFoundChanged();
}
/**
* Returns whether notifications are enabled for the given contact.
*/
bool notificationsMuted(const QString& jid);
/**
* Sets the notifications to muted/unmuted.
*
* @param muted true if notifications should be muted.
* @param jid contains the current chatpartner's jid.
*/
void setNotificationsMuted(const QString& jid, bool muted);
private:
void connectDatabases();
......
......@@ -167,7 +167,7 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
contactName = contactJid;
if (!message.sentByMe())
Notifications::sendMessageNotification(contactName, msg.body());
Notifications::sendMessageNotification(contactJid, contactName, msg.body());
// TODO: Move back following call to RosterManager::handleMessage when spoiler
// messages are implemented in QXmpp
......
......@@ -30,20 +30,25 @@
// Kaidan
#include "Notifications.h"
#include "Kaidan.h"
// Qt
#include <QVariant>
// KNotifications
#ifdef HAVE_KNOTIFICATIONS
#include <KNotification>
#endif
#ifdef HAVE_KNOTIFICATIONS
void Notifications::sendMessageNotification(const QString& fromName, const QString& message)
void Notifications::sendMessageNotification(const QString& jid, const QString& fromName, const QString& message)
{
KNotification *notif = new KNotification("new-message");
notif->setText(QString("<b>%1</b>: %2").arg(fromName, message));
notif->sendEvent();
if (!Kaidan::instance()->notificationsMuted(jid)) {
KNotification *notif = new KNotification("new-message");
notif->setText(QString("<b>%1</b>: %2").arg(fromName, message));
notif->sendEvent();
}
}
#else
void Notifications::sendMessageNotification(const QString&, const QString&)
void Notifications::sendMessageNotification(const QString&, const QString&, const QString&)
{
}
#endif
......@@ -33,5 +33,5 @@
class Notifications
{
public:
static void sendMessageNotification(const QString &fromName, const QString &message);
static void sendMessageNotification(const QString &jid, const QString &fromName, const QString &message);
};
......@@ -82,6 +82,7 @@ RosterManager::RosterManager(Kaidan *kaidan,
this, [=] (QString jid, bool accepted) {
if (accepted) {
manager.acceptSubscription(jid);
// do not send a subscription request if both users have already subscribed
// each others presence
if (manager.getRosterEntry(jid).subscriptionType() != QXmppRosterIq::Item::Both)
......
......@@ -47,9 +47,44 @@ Kirigami.ScrollablePage {
actions.contextualActions: [
Kirigami.Action {
visible: !isWritingSpoiler
iconSource: "password-show-off"
icon.name: "password-show-off"
text: qsTr("Send a spoiler message")
onTriggered: isWritingSpoiler = true
},
Kirigami.Action {
visible: true
icon.name: {
kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
? "player-volume"
: "audio-volume-muted-symbolic"
}
text: {
kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
? qsTr("Unmute notifications")
: qsTr("Mute notifications")
}
onTriggered: {
kaidan.setNotificationsMuted(
kaidan.messageModel.chatPartner,
!kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
)
}
function handleNotificationsMuted(jid) {
text = kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
? qsTr("Unmute notifications")
: qsTr("Mute notifications")
icon.name = kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
? "player-volume"
: "audio-volume-muted-symbolic"
}
Component.onCompleted: {
kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
}
Component.onDestruction: {
kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
}
}
]
......
......@@ -32,10 +32,11 @@ import QtQuick 2.0
Rectangle {
property int counter: 0
property bool muted: false
id: counterCircle
radius: counterCircle.height * 0.5
color: "#4CAF50"
color: muted ? "grey" : "#4CAF50"
Text {
id: msgCounter
......
......@@ -103,14 +103,29 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true
// contact name
Kirigami.Heading {
text: name
textFormat: Text.PlainText
elide: Text.ElideRight
maximumLineCount: 1
level: 3
Layout.fillWidth: true
Layout.maximumHeight: Kirigami.Units.gridUnit * 1.5
RowLayout {
Kirigami.Heading {
text: name
textFormat: Text.PlainText
elide: Text.ElideRight
maximumLineCount: 1
level: 3
Layout.fillWidth: true
Layout.maximumHeight: Kirigami.Units.gridUnit * 1.5
}
// muted-icon
Kirigami.Icon {
id: muteIcon
source: "audio-volume-muted-symbolic"
width: 16
height: 16
visible: kaidan.notificationsMuted(jid)
}
Item {
Layout.fillWidth: true
}
}
// bottom
RowLayout {
......@@ -133,8 +148,10 @@ Kirigami.SwipeListItem {
// unread message counter
MessageCounter {
id: counter
visible: unreadMessages > 0
counter: unreadMessages
muted: kaidan.notificationsMuted(jid)
Layout.preferredHeight: Kirigami.Units.gridUnit * 1.25
Layout.preferredWidth: Kirigami.Units.gridUnit * 1.25
......@@ -184,4 +201,16 @@ Kirigami.SwipeListItem {
}
return string
}
function handleNotificationsMuted(mutedContact) {
counter.muted = kaidan.notificationsMuted(jid)
muteIcon.visible = kaidan.notificationsMuted(jid)
}
Component.onCompleted: {
kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
}
Component.onDestruction: {
kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment