diff --git a/Mac/Controller.h b/Mac/Controller.h index 4a91b57..5a7a499 100644 --- a/Mac/Controller.h +++ b/Mac/Controller.h @@ -14,7 +14,7 @@ #import "AccessToken.h" -@interface Controller : NSObject { +@interface Controller : NSObject { IBOutlet WebView *timelineView; IBOutlet NSWindow *timelineViewWindow; IBOutlet WebView *mentionsView; @@ -52,6 +52,8 @@ - (NSString *)pluginURL; - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; - (void)unreadMentions:(NSInteger)count; +- (void)notificateUserAboutMention:(NSString *)text fromName:(NSString *)name withPostId:(NSString *)postId andEntity:(NSString *)entity; + - (void)openURL:(NSString *)url; - (void)setString:(NSString *)string forKey:(NSString *)aKey; diff --git a/Mac/Controller.m b/Mac/Controller.m index 0d6ce00..6f2764d 100644 --- a/Mac/Controller.m +++ b/Mac/Controller.m @@ -23,6 +23,7 @@ - (void)awakeFromNib { [self initHotKeys]; + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self @@ -257,6 +258,24 @@ } } +- (void)notificateUserAboutMention:(NSString *)text fromName:(NSString *)name withPostId:(NSString *)postId andEntity:(NSString *)entity { + + NSUserNotification *notification = [[NSUserNotification alloc] init]; + notification.title = @"Tent Mention"; + notification.subtitle = [NSString stringWithFormat:@"Mentioned by %@", name]; + notification.informativeText = text; + notification.hasActionButton = YES; + notification.actionButtonTitle = @"Show"; + notification.soundName = NSUserNotificationDefaultSoundName; + notification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys: + entity, @"entity", + postId, @"postId", nil]; + + NSLog(@"%@", notification); + + [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; +} + - (void)openURL:(NSString *)url { [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]]; } @@ -326,6 +345,13 @@ conversationViewWindow.title = @"Test"; } +// Notifications + +- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification +{ + [self showConversationForPostId:[notification.userInfo objectForKey:@"postId"] andEntity:[notification.userInfo objectForKey:@"entity"]]; +} + /* CARBON */ OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) diff --git a/WebKit/scripts/controller/Mentions.js b/WebKit/scripts/controller/Mentions.js index af86c6c..2451555 100644 --- a/WebKit/scripts/controller/Mentions.js +++ b/WebKit/scripts/controller/Mentions.js @@ -19,13 +19,23 @@ function(HostApp, Timeline) { Mentions.prototype = Object.create(Timeline.prototype); - Mentions.prototype.newStatus = function(status) { + Mentions.prototype.newStatus = function(statuses) { - Timeline.prototype.newStatus.call(this, status); + Timeline.prototype.newStatus.call(this, statuses); if(this.is_not_init) { - this.unread_mentions += status.length; + this.unread_mentions += statuses.length; HostApp.unreadMentions(this.unread_mentions); + for (var i = 0; i < statuses.length; i++) { + var status = statuses[i]; + + var name; + if(this.followings.followings[status.entity]) { + name = this.followings.followings[status.entity].profile["https://tent.io/types/info/basic/v0.1.0"].name; + } + + HostApp.notificateUserAboutMention(status.content.text, name || status.entity, status.id, status.entity); + }; } this.is_not_init = true; diff --git a/WebKit/scripts/helper/HostApp.js b/WebKit/scripts/helper/HostApp.js index 6ba6275..7e1d5e0 100644 --- a/WebKit/scripts/helper/HostApp.js +++ b/WebKit/scripts/helper/HostApp.js @@ -70,6 +70,12 @@ define(function() { } } + HostApp.notificateUserAboutMention = function(text, name, post_id, entity) { + if (OS_TYPE == "mac") { + controller.notificateUserAboutMention_fromName_withPostId_andEntity_(text, name, post_id, entity); + } + } + return HostApp; }); \ No newline at end of file