From 4aa3e0962a01146eccba11fa53cd84b0cf4ed544 Mon Sep 17 00:00:00 2001 From: Greg Omelaenko Date: Wed, 21 Dec 2016 02:16:40 +1100 Subject: [PATCH 1/3] Fix conversation prev/next navigation - change keyboard shortcuts as the previous conflicted with the search feature (which overrode) --- Messenger/Base.lproj/MainMenu.xib | 18 +++++------------- website/app/main.js | 6 +++--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Messenger/Base.lproj/MainMenu.xib b/Messenger/Base.lproj/MainMenu.xib index 75bc174..eca9e6e 100644 --- a/Messenger/Base.lproj/MainMenu.xib +++ b/Messenger/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - - + + - + @@ -430,20 +430,12 @@ - - -CQ - - + - - -CQ - - + diff --git a/website/app/main.js b/website/app/main.js index eccc687..d833565 100644 --- a/website/app/main.js +++ b/website/app/main.js @@ -260,7 +260,7 @@ }, currentConversationItem: function() { - return document.querySelector('li[role="log"]'); + return document.querySelector('div[aria-label="Conversations"] li[aria-relevant]'); }, canSelectNewerConversation: function () { @@ -270,7 +270,7 @@ selectNewerConversation: function () { var newer = this.currentConversationItem().previousElementSibling; if (newer) { - newer.querySelector('[data-reactid]:first-child').click(); + newer.querySelector('a').click(); } }, @@ -281,7 +281,7 @@ selectOlderConversation: function () { var newer = this.currentConversationItem().nextElementSibling; if (newer) { - newer.querySelector('[data-reactid]:first-child').click(); + newer.querySelector('a').click(); } }, From 18048a6951c8b7c864941caa32f78e65e0df2a07 Mon Sep 17 00:00:00 2001 From: Greg Omelaenko Date: Wed, 21 Dec 2016 17:32:55 +1100 Subject: [PATCH 2/3] Basic Touch Bar support - Compose button, and prev/next conversation navigation --- Messenger/AppDelegate.h | 1 + Messenger/AppDelegate.mm | 5 +++++ Messenger/FBMWindow.h | 2 +- Messenger/FBMWindow.mm | 42 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Messenger/AppDelegate.h b/Messenger/AppDelegate.h index ccf45c0..bfdfeaf 100644 --- a/Messenger/AppDelegate.h +++ b/Messenger/AppDelegate.h @@ -22,6 +22,7 @@ int FBMOSX1010OrNewer(); - (void)showActiveFriends; - (void)showInbox; - (void)showMessageRequests; +- (IBAction)composeNewMessage:(id)sender; - (void)windowDidBecomeKey:(NSWindow*)w; // [self evaluateJavaScript:@"try { (typeof MacMessenger != 'undefined') && MacMessenger.focusComposer(); } catch(_) {}"]; diff --git a/Messenger/AppDelegate.mm b/Messenger/AppDelegate.mm index 1dc76ab..dbeb138 100644 --- a/Messenger/AppDelegate.mm +++ b/Messenger/AppDelegate.mm @@ -242,6 +242,11 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification { toItem:_curtainView attribute:NSLayoutAttributeCenterY multiplier:1.f constant:0.f]]; + + // Touch bar + if ([NSTouchBar class]) { + [[NSApplication sharedApplication] setAutomaticCustomizeTouchBarMenuItemEnabled:YES]; + } // Present main window [_window makeKeyAndOrderFront:self]; diff --git a/Messenger/FBMWindow.h b/Messenger/FBMWindow.h index d0bae5e..66bf9fa 100644 --- a/Messenger/FBMWindow.h +++ b/Messenger/FBMWindow.h @@ -1,4 +1,4 @@ -@interface FBMWindow : NSWindow +@interface FBMWindow : NSWindow - (void)setMainView:(NSView*)mainView; diff --git a/Messenger/FBMWindow.mm b/Messenger/FBMWindow.mm index 2abe080..2d9b940 100644 --- a/Messenger/FBMWindow.mm +++ b/Messenger/FBMWindow.mm @@ -151,6 +151,48 @@ - (void)hideTitlebarAnimate:(BOOL)animate { +#pragma mark - Touch Bar + +static NSString * const touchBarIdentifier = @"me.rsms.fbmessenger.touchbar"; +static NSString * const touchBarComposeButtonIdentifier = @"me.rsms.fbmessenger.touchbar.compose"; +static NSString * const touchBarConversationNavigationIdentifier = @"me.rsms.fbmessenger.touchbar.conversationNavigation"; + +- (NSTouchBar *)makeTouchBar { + auto bar = [NSTouchBar new]; + bar.delegate = self; + bar.customizationIdentifier = touchBarIdentifier; + bar.defaultItemIdentifiers = @[touchBarComposeButtonIdentifier, NSTouchBarItemIdentifierOtherItemsProxy, NSTouchBarItemIdentifierFlexibleSpace, touchBarConversationNavigationIdentifier]; + bar.customizationAllowedItemIdentifiers = @[touchBarComposeButtonIdentifier, touchBarConversationNavigationIdentifier]; + + return bar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { + if ([identifier isEqual:touchBarComposeButtonIdentifier]) { + auto item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.customizationLabel = @"New Message"; + item.view = [NSButton buttonWithImage:[NSImage imageNamed:NSImageNameTouchBarComposeTemplate] target:[NSApp delegate] action:@selector(composeNewMessage:)]; + return item; + } + if ([identifier isEqual:touchBarConversationNavigationIdentifier]) { + auto item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.customizationLabel = @"Conversation Navigation"; + auto segmentedControl = [NSSegmentedControl segmentedControlWithImages:@[[NSImage imageNamed:NSImageNameTouchBarGoUpTemplate], [NSImage imageNamed:NSImageNameTouchBarGoDownTemplate]] trackingMode:NSSegmentSwitchTrackingMomentary target:self action:@selector(conversationNavigationSegmentedControlDidSelect:)]; + segmentedControl.segmentStyle = NSSegmentStyleSeparated; + item.view = segmentedControl; + return item; + } + return nil; +} + +- (void)conversationNavigationSegmentedControlDidSelect:(NSSegmentedControl *)sender { + auto delegate = (AppDelegate *)[NSApp delegate]; + if (sender.selectedSegment == 0) [delegate selectNewerConversation:sender]; + else if (sender.selectedSegment == 1) [delegate selectOlderConversation:sender]; +} + + + #pragma mark - NSWindowDelegate From 4fbf60d4ced27271a03567debcf751de36167107 Mon Sep 17 00:00:00 2001 From: Greg Omelaenko Date: Sat, 24 Dec 2016 02:18:46 +1100 Subject: [PATCH 3/3] Fix conversation navigation with some unread messages Selected conversation would not be found correctly if there were non-selected unread conversations. --- website/app/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/website/app/main.js b/website/app/main.js index d833565..1ad4285 100644 --- a/website/app/main.js +++ b/website/app/main.js @@ -260,7 +260,11 @@ }, currentConversationItem: function() { - return document.querySelector('div[aria-label="Conversations"] li[aria-relevant]'); + // when a conversation is unread, it has both aria-relevant _and_ aria-live. + // so we are looking for the element with aria-relevant but _not_ aria-live, _unless_ there's only one aria-relevant (then it's selected and unread). + var item = document.querySelector('div[aria-label="Conversations"] li[aria-relevant]:not([aria-live])'); + if (!item) item = document.querySelector('div[aria-label="Conversations"] li[aria-relevant]'); + return item; }, canSelectNewerConversation: function () {