From 2ca5d1ea6882b10f906d1e651df191cd70943286 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sat, 22 Dec 2012 19:37:03 +0100 Subject: [PATCH] added posting private posts --- Mac/Controller.h | 2 +- Mac/Controller.m | 17 ++- Mac/English.lproj/NewMessageWindow.xib | 153 ++++++++++++++----------- Mac/NewMessageWindow.h | 4 + Mac/NewMessageWindow.m | 17 +++ Mac/PostModel.h | 2 + Mac/PostModel.m | 2 +- WebKit/scripts/controller/Profile.js | 2 +- WebKit/scripts/controller/Timeline.js | 4 +- WebKit/scripts/helper/Core.js | 21 +++- WebKit/scripts/helper/HostApp.js | 6 +- WebKit/scripts/helper/Paths.js | 6 +- 12 files changed, 144 insertions(+), 92 deletions(-) diff --git a/Mac/Controller.h b/Mac/Controller.h index 9d7a875..fc39233 100644 --- a/Mac/Controller.h +++ b/Mac/Controller.h @@ -61,7 +61,7 @@ - (void)initWebViews; - (void)initHotKeys; - (void)alertTitle:(NSString *)title withMessage:(NSString *)message; -- (void)openNewMessageWindowInReplyTo:(NSString *)userName statusId:(NSString *)statusId withString:(NSString *)string; +- (void)openNewMessageWindowInReplyTo:(NSString *)userName statusId:(NSString *)statusId withString:(NSString *)string isPrivate:(BOOL)isPrivate; - (NSString *)pluginURL; - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; - (void)unreadMentions:(int)count; diff --git a/Mac/Controller.m b/Mac/Controller.m index 84909ef..f552dd6 100644 --- a/Mac/Controller.m +++ b/Mac/Controller.m @@ -296,11 +296,12 @@ [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:nil]; } -- (void)openNewMessageWindowInReplyTo:(NSString *)userName statusId:(NSString *)statusId withString:(NSString *)string +- (void)openNewMessageWindowInReplyTo:(NSString *)userName statusId:(NSString *)statusId withString:(NSString *)string isPrivate:(BOOL)isPrivate { [NSApp activateIgnoringOtherApps:YES]; - NewMessageWindow *newTweet = (NewMessageWindow *)[[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:nil]; - [newTweet inReplyTo:userName statusId:statusId withString:string]; + NewMessageWindow *newMessage = (NewMessageWindow *)[[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:nil]; + [newMessage inReplyTo:userName statusId:statusId withString:string]; + [newMessage setIsPrivate:isPrivate]; } - (void)openNewMessageWindowWithString:(NSString *)aString @@ -347,12 +348,18 @@ imageFilePath = [NSString stringWithFormat:@"\"data:%@;base64,%@\"", mimeType, base64]; } - NSString *func = [NSString stringWithFormat:@"tentia_instance.sendNewMessage(\"%@\", \"%@\", \"%@\", %@, %@)", + NSString *isPrivate = @"false"; + if (post.isPrivate) { + isPrivate = @"true"; + } + + NSString *func = [NSString stringWithFormat:@"tentia_instance.sendNewMessage(\"%@\", \"%@\", \"%@\", %@, %@, %@)", text, post.inReplyTostatusId, post.inReplyToEntity, locationObject, - imageFilePath]; + imageFilePath, + isPrivate]; [timelineView stringByEvaluatingJavaScriptFromString:func]; } diff --git a/Mac/English.lproj/NewMessageWindow.xib b/Mac/English.lproj/NewMessageWindow.xib index 0bc3e7d..ef1c613 100644 --- a/Mac/English.lproj/NewMessageWindow.xib +++ b/Mac/English.lproj/NewMessageWindow.xib @@ -131,14 +131,14 @@ {{2, 0}, {18, 19}} - + _NS:9 YES 67108864 134217728 - + LucidaGrande-Bold 12 16 @@ -187,6 +187,35 @@ NO + + + 292 + {{20, 1}, {19, 19}} + + + + _NS:9 + YES + + 67108864 + 134217728 + + + _NS:9 + + 113524736 + 268435629 + + NSImage + NSLockUnlockedTemplate + + + p + 200 + 25 + + NO + {299, 113} @@ -394,6 +423,22 @@ A 100073 + + + togglePrivate: + + + + 100076 + + + + togglePrivateButton + + + + 100080 + delegate @@ -453,6 +498,7 @@ A + @@ -552,6 +598,20 @@ A + + 100074 + + + YES + + + + + + 100075 + + + @@ -574,6 +634,8 @@ A 100065.IBPluginDependency 100066.IBPluginDependency 100071.IBPluginDependency + 100074.IBPluginDependency + 100075.IBPluginDependency 5.IBPluginDependency 5.IBWindowTemplateEditedContentRect 6.IBPluginDependency @@ -597,6 +659,8 @@ A com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{127, 736}, {299, 113}} com.apple.InterfaceBuilder.CocoaPlugin @@ -613,78 +677,11 @@ A - 100073 + 100080 YES - - NSDocument - - YES - - YES - printDocument: - revertDocumentToSaved: - runPageLayout: - saveDocument: - saveDocumentAs: - saveDocumentTo: - - - YES - id - id - id - id - id - id - - - - YES - - YES - printDocument: - revertDocumentToSaved: - runPageLayout: - saveDocument: - saveDocumentAs: - saveDocumentTo: - - - YES - - printDocument: - id - - - revertDocumentToSaved: - id - - - runPageLayout: - id - - - saveDocument: - id - - - saveDocumentAs: - id - - - saveDocumentTo: - id - - - - - IBProjectSource - ./Classes/NSDocument.h - - NewMessageWindow NSDocument @@ -697,6 +694,7 @@ A openAddMenu: sendPost: sendPostButtonPressed: + togglePrivate: YES @@ -705,6 +703,7 @@ A id NSControl id + id @@ -716,6 +715,7 @@ A openAddMenu: sendPost: sendPostButtonPressed: + togglePrivate: YES @@ -739,6 +739,10 @@ A sendPostButtonPressed: id + + togglePrivate: + id + @@ -749,6 +753,7 @@ A addMenuButton counter textField + togglePrivateButton YES @@ -756,6 +761,7 @@ A NSButton NSTextField NSTextField + NSButton @@ -766,6 +772,7 @@ A addMenuButton counter textField + togglePrivateButton YES @@ -785,6 +792,10 @@ A textField NSTextField + + togglePrivateButton + NSButton + @@ -807,12 +818,14 @@ A YES NSAddTemplate + NSLockUnlockedTemplate NSMenuCheckmark NSMenuMixedState YES {8, 8} + {9, 12} {11, 11} {10, 3} diff --git a/Mac/NewMessageWindow.h b/Mac/NewMessageWindow.h index 624361d..556dfd6 100644 --- a/Mac/NewMessageWindow.h +++ b/Mac/NewMessageWindow.h @@ -23,6 +23,7 @@ CLLocationManager *locationManager; CLLocation *currentLocation; NSString *imageFilePath; + NSButton *togglePrivateButton; } @property (nonatomic, retain) IBOutlet NSTextField *textField; @@ -32,6 +33,7 @@ @property (retain, nonatomic) CLLocationManager *locationManager; @property (retain, nonatomic) CLLocation *currentLocation; @property (retain, nonatomic) NSString *imageFilePath; +@property (assign) IBOutlet NSButton *togglePrivateButton; - (IBAction)sendPost:(NSControl *)control; - (void)inReplyTo:(NSString *)userName statusId:(NSString *)statusId withString:(NSString *)string; @@ -39,5 +41,7 @@ - (IBAction)addCurrentLocation:(id)sender; - (IBAction)addImage:(id)sender; - (IBAction)openAddMenu:(id)sender; +- (IBAction)togglePrivate:(id)sender; +- (void)setIsPrivate:(BOOL)isPrivate; @end diff --git a/Mac/NewMessageWindow.m b/Mac/NewMessageWindow.m index 5ebfd73..2998997 100644 --- a/Mac/NewMessageWindow.m +++ b/Mac/NewMessageWindow.m @@ -23,6 +23,7 @@ @synthesize textField, counter; @synthesize locationManager, currentLocation; @synthesize imageFilePath; +@synthesize togglePrivateButton; - (void)dealloc { @@ -159,6 +160,21 @@ [NSMenu popUpContextMenu:self.addMenu withEvent:event forView:self.addMenuButton]; } +- (IBAction)togglePrivate:(id)sender +{ + NSImage *image = [NSImage imageNamed:NSImageNameLockLockedTemplate]; + if (self.togglePrivateButton.image == [NSImage imageNamed:NSImageNameLockLockedTemplate]) + { + image = [NSImage imageNamed:NSImageNameLockUnlockedTemplate]; + } + [self.togglePrivateButton setImage:image]; +} + +- (void)setIsPrivate:(BOOL)isPrivate { + NSImage *image = [NSImage imageNamed:(isPrivate ? NSImageNameLockLockedTemplate : NSImageNameLockUnlockedTemplate)]; + [self.togglePrivateButton setImage:image]; +} + -(void)controlTextDidChange:(NSNotification *)aNotification { NSInteger c = MESSAGE_MAX_LENGTH - [[textField stringValue] length]; [counter setIntValue:c]; @@ -207,6 +223,7 @@ post.inReplyToEntity = inReplyToEntity; post.location = self.currentLocation; post.imageFilePath = self.imageFilePath; + post.isPrivate = self.togglePrivateButton.image == [NSImage imageNamed:NSImageNameLockLockedTemplate]; [[NSNotificationCenter defaultCenter] postNotificationName:@"sendTweet" object:post]; [self close]; } else { diff --git a/Mac/PostModel.h b/Mac/PostModel.h index 426a539..ececd47 100644 --- a/Mac/PostModel.h +++ b/Mac/PostModel.h @@ -15,6 +15,7 @@ NSString *inReplyToEntity; CLLocation *location; NSString *imageFilePath; + BOOL isPrivate; } @property (nonatomic, retain) NSString *text; @@ -22,5 +23,6 @@ @property (nonatomic, retain) NSString *inReplyToEntity; @property (nonatomic, retain) CLLocation *location; @property (nonatomic, retain) NSString *imageFilePath; +@property (nonatomic) BOOL isPrivate; @end diff --git a/Mac/PostModel.m b/Mac/PostModel.m index 777c3ff..bea4d65 100644 --- a/Mac/PostModel.m +++ b/Mac/PostModel.m @@ -11,7 +11,7 @@ @implementation PostModel -@synthesize text, inReplyTostatusId, inReplyToEntity, location, imageFilePath; +@synthesize text, inReplyTostatusId, inReplyToEntity, location, imageFilePath, isPrivate; - (void)dealloc { diff --git a/WebKit/scripts/controller/Profile.js b/WebKit/scripts/controller/Profile.js index ac2e303..9a376fd 100644 --- a/WebKit/scripts/controller/Profile.js +++ b/WebKit/scripts/controller/Profile.js @@ -71,7 +71,7 @@ function(HostApp, Core, Paths, URI) { if (e.startsWith("https://")) { e = e.substr(8, e.length); } - HostApp.openNewMessageWidow(null, null, "^" + e + " "); + HostApp.openNewMessageWidow(null, null, "^" + e + " ", false); } div.appendChild(this.profile_template.mention_button); this.profile_template.mention_button.innerHTML = "Mention"; diff --git a/WebKit/scripts/controller/Timeline.js b/WebKit/scripts/controller/Timeline.js index 51e4f9e..bc3fb7c 100644 --- a/WebKit/scripts/controller/Timeline.js +++ b/WebKit/scripts/controller/Timeline.js @@ -128,10 +128,10 @@ function(Core, Paths, HostApp, URI) { } } - Timeline.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri) { + Timeline.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, is_private) { var _this = this; var callback = function(data) { _this.getNewData(); } - Core.prototype.sendNewMessage.call(this, content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, callback); + Core.prototype.sendNewMessage.call(this, content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, is_private, callback); } Timeline.prototype.remove = function(id) { diff --git a/WebKit/scripts/helper/Core.js b/WebKit/scripts/helper/Core.js index 3e0bee7..9f1a481 100644 --- a/WebKit/scripts/helper/Core.js +++ b/WebKit/scripts/helper/Core.js @@ -171,7 +171,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { mentions.push(mention); } - _this.replyTo(status.entity, status.id, mentions); + _this.replyTo(status.entity, status.id, mentions, (status && status.permissions && !status.permissions.public)); return false; } @@ -399,11 +399,11 @@ function(jQuery, Paths, URI, HostApp, Cache) { } } - Core.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_file_path, callback) { + Core.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_file_path, is_private, callback) { if (image_file_path) { - this.sendNewMessageWithImage(content, in_reply_to_status_id, in_reply_to_entity, location, image_file_path, callback); + this.sendNewMessageWithImage(content, in_reply_to_status_id, in_reply_to_entity, location, image_file_path, is_private, callback); } else { @@ -415,7 +415,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { "type": "https://tent.io/types/post/status/v0.1.0", "published_at": parseInt(new Date().getTime() / 1000, 10), "permissions": { - "public": true + "public": !is_private }, "content": { "text": content, @@ -430,6 +430,15 @@ function(jQuery, Paths, URI, HostApp, Cache) { if (mentions.length > 0) { data["mentions"] = mentions; + if (is_private) { + var entities = {}; + for (var i = 0; i < mentions.length; i++) { + var entity = mentions[i]["entity"] + entities[entity] = true; + }; + + data["permissions"]["entities"] = entities; + } } Paths.getURL(url.toString(), http_method, callback, JSON.stringify(data)); @@ -708,7 +717,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { return text.replace(hash, "$1$2$3"); } - Core.prototype.replyTo = function(entity, status_id, mentions) { + Core.prototype.replyTo = function(entity, status_id, mentions, is_private) { var string = "^" + entity.replace("https://", "") + " "; for (var i = 0; i < mentions.length; i++) { @@ -716,7 +725,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { if(string.indexOf(e) == -1) string += "^" + e + " "; } - HostApp.openNewMessageWidow(entity, status_id, string); + HostApp.openNewMessageWidow(entity, status_id, string, is_private); } return Core; diff --git a/WebKit/scripts/helper/HostApp.js b/WebKit/scripts/helper/HostApp.js index 37c870e..4d2116a 100644 --- a/WebKit/scripts/helper/HostApp.js +++ b/WebKit/scripts/helper/HostApp.js @@ -69,12 +69,12 @@ define(function() { } } - HostApp.openNewMessageWidow = function(entity, status_id, string) { + HostApp.openNewMessageWidow = function(entity, status_id, string, is_private) { if (OS_TYPE == "mac") { - controller.openNewMessageWindowInReplyTo_statusId_withString_(entity, status_id, string); + controller.openNewMessageWindowInReplyTo_statusId_withString_isPrivate_(entity, status_id, string, is_private); } else { - controller.openNewMessageWindowInReplyTostatusIdwithString(entity, status_id, string); + controller.openNewMessageWindowInReplyTostatusIdwithStringIsPrivate(entity, status_id, string, is_private); } } diff --git a/WebKit/scripts/helper/Paths.js b/WebKit/scripts/helper/Paths.js index f93be35..ae4dab1 100644 --- a/WebKit/scripts/helper/Paths.js +++ b/WebKit/scripts/helper/Paths.js @@ -138,9 +138,9 @@ function(jQuery, HostApp, Hmac, Cache) { Paths.getURL(entity, "GET", function(resp) { if (resp.status >= 200 && resp.status < 300) { - var div = document.createElement("div"); - div.innerHTML = resp.responseText; - var links = $(div).find("link[rel='https://tent.io/rels/profile']"); + var doc = document.implementation.createHTMLDocument(""); + doc.documentElement.innerHTML = resp.responseText; + var links = $(doc).find("link[rel='https://tent.io/rels/profile']"); if (links.length > 0) { var href = links.get(0).href;