Show room avatar in notification.
This commit is contained in:
@@ -29,5 +29,7 @@
|
|||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<string>True</string>
|
<string>True</string>
|
||||||
|
<key>NSUserNotificationAlertStyle</key>
|
||||||
|
<string>alert</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
|
|
||||||
#import <UserNotifications/UserNotifications.h>
|
#include <Foundation/Foundation.h>
|
||||||
|
#include <QtMac>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
#include <QApplication>
|
@interface NSUserNotification (CFIPrivate)
|
||||||
|
- (void)set_identityImage:(NSImage*)image;
|
||||||
|
@end
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {}
|
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {}
|
||||||
|
|
||||||
@@ -16,42 +20,17 @@ void NotificationsManager::postNotification(const QString& roomId,
|
|||||||
Q_UNUSED(eventId);
|
Q_UNUSED(eventId);
|
||||||
Q_UNUSED(icon);
|
Q_UNUSED(icon);
|
||||||
|
|
||||||
UNUserNotificationCenter* center =
|
NSUserNotification* notif = [[NSUserNotification alloc] init];
|
||||||
[UNUserNotificationCenter currentNotificationCenter];
|
|
||||||
UNAuthorizationOptions options =
|
|
||||||
UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
|
|
||||||
|
|
||||||
[center requestAuthorizationWithOptions:options
|
notif.title = roomName.toNSString();
|
||||||
completionHandler:^(BOOL granted,
|
notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
||||||
NSError* _Nullable error) {
|
notif.informativeText = text.toNSString();
|
||||||
if (!granted) {
|
notif.soundName = NSUserNotificationDefaultSoundName;
|
||||||
NSLog(@"Something went wrong");
|
notif.contentImage = QtMac::toNSImage(QPixmap::fromImage(icon));
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
UNTimeIntervalNotificationTrigger* trigger =
|
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
||||||
[UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0 repeats:NO];
|
deliverNotification:notif];
|
||||||
|
[notif autorelease];
|
||||||
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
|
|
||||||
|
|
||||||
content.title = roomName.toNSString();
|
|
||||||
content.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
|
||||||
content.body = text.toNSString();
|
|
||||||
content.sound = [UNNotificationSound defaultSound];
|
|
||||||
|
|
||||||
NSString* identifier = QApplication::applicationName().toNSString();
|
|
||||||
|
|
||||||
UNNotificationRequest* request =
|
|
||||||
[UNNotificationRequest requestWithIdentifier:identifier
|
|
||||||
content:content
|
|
||||||
trigger:trigger];
|
|
||||||
|
|
||||||
[center addNotificationRequest:request
|
|
||||||
withCompletionHandler:^(NSError* _Nullable error) {
|
|
||||||
if (error != nil) {
|
|
||||||
NSLog(@"Something went wrong: %@", error);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unused
|
// unused
|
||||||
|
|||||||
Reference in New Issue
Block a user