added posting private posts

This commit is contained in:
Jeena Paradies 2012-12-22 19:37:03 +01:00
parent eb540fae1d
commit 2ca5d1ea68
12 changed files with 144 additions and 92 deletions

View file

@ -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;

View file

@ -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];
}

View file

@ -131,14 +131,14 @@
<string key="NSFrame">{{2, 0}, {18, 19}}</string>
<reference key="NSSuperview" ref="568628114"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="184011745"/>
<reference key="NSNextKeyView" ref="306901015"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="482669194">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<object class="NSFont" key="NSSupport">
<object class="NSFont" key="NSSupport" id="29">
<string key="NSName">LucidaGrande-Bold</string>
<double key="NSSize">12</double>
<int key="NSfFlags">16</int>
@ -187,6 +187,35 @@
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
<object class="NSButton" id="306901015">
<reference key="NSNextResponder" ref="568628114"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 1}, {19, 19}}</string>
<reference key="NSSuperview" ref="568628114"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="184011745"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="448152979">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="29"/>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="306901015"/>
<int key="NSButtonFlags">113524736</int>
<int key="NSButtonFlags2">268435629</int>
<object class="NSCustomResource" key="NSNormalImage">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSLockUnlockedTemplate</string>
</object>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent">p</string>
<int key="NSPeriodicDelay">200</int>
<int key="NSPeriodicInterval">25</int>
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
</object>
<string key="NSFrameSize">{299, 113}</string>
<reference key="NSSuperview"/>
@ -394,6 +423,22 @@ A</bytes>
</object>
<int key="connectionID">100073</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">togglePrivate:</string>
<reference key="source" ref="512844837"/>
<reference key="destination" ref="306901015"/>
</object>
<int key="connectionID">100076</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">togglePrivateButton</string>
<reference key="source" ref="512844837"/>
<reference key="destination" ref="306901015"/>
</object>
<int key="connectionID">100080</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
@ -453,6 +498,7 @@ A</bytes>
<reference ref="482035741"/>
<reference ref="647941004"/>
<reference ref="184011745"/>
<reference ref="306901015"/>
</object>
<reference key="parent" ref="275939982"/>
</object>
@ -552,6 +598,20 @@ A</bytes>
<reference key="object" ref="486389227"/>
<reference key="parent" ref="723763594"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">100074</int>
<reference key="object" ref="306901015"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="448152979"/>
</object>
<reference key="parent" ref="568628114"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">100075</int>
<reference key="object" ref="448152979"/>
<reference key="parent" ref="306901015"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@ -574,6 +634,8 @@ A</bytes>
<string>100065.IBPluginDependency</string>
<string>100066.IBPluginDependency</string>
<string>100071.IBPluginDependency</string>
<string>100074.IBPluginDependency</string>
<string>100075.IBPluginDependency</string>
<string>5.IBPluginDependency</string>
<string>5.IBWindowTemplateEditedContentRect</string>
<string>6.IBPluginDependency</string>
@ -597,6 +659,8 @@ A</bytes>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{127, 736}, {299, 113}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
@ -613,78 +677,11 @@ A</bytes>
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">100073</int>
<int key="maxID">100080</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">NSDocument</string>
<object class="NSMutableDictionary" key="actions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>printDocument:</string>
<string>revertDocumentToSaved:</string>
<string>runPageLayout:</string>
<string>saveDocument:</string>
<string>saveDocumentAs:</string>
<string>saveDocumentTo:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>printDocument:</string>
<string>revertDocumentToSaved:</string>
<string>runPageLayout:</string>
<string>saveDocument:</string>
<string>saveDocumentAs:</string>
<string>saveDocumentTo:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">printDocument:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">revertDocumentToSaved:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">runPageLayout:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">saveDocument:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">saveDocumentAs:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">saveDocumentTo:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/NSDocument.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NewMessageWindow</string>
<string key="superclassName">NSDocument</string>
@ -697,6 +694,7 @@ A</bytes>
<string>openAddMenu:</string>
<string>sendPost:</string>
<string>sendPostButtonPressed:</string>
<string>togglePrivate:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -705,6 +703,7 @@ A</bytes>
<string>id</string>
<string>NSControl</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
@ -716,6 +715,7 @@ A</bytes>
<string>openAddMenu:</string>
<string>sendPost:</string>
<string>sendPostButtonPressed:</string>
<string>togglePrivate:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -739,6 +739,10 @@ A</bytes>
<string key="name">sendPostButtonPressed:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">togglePrivate:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@ -749,6 +753,7 @@ A</bytes>
<string>addMenuButton</string>
<string>counter</string>
<string>textField</string>
<string>togglePrivateButton</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -756,6 +761,7 @@ A</bytes>
<string>NSButton</string>
<string>NSTextField</string>
<string>NSTextField</string>
<string>NSButton</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
@ -766,6 +772,7 @@ A</bytes>
<string>addMenuButton</string>
<string>counter</string>
<string>textField</string>
<string>togglePrivateButton</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -785,6 +792,10 @@ A</bytes>
<string key="name">textField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">togglePrivateButton</string>
<string key="candidateClassName">NSButton</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@ -807,12 +818,14 @@ A</bytes>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSAddTemplate</string>
<string>NSLockUnlockedTemplate</string>
<string>NSMenuCheckmark</string>
<string>NSMenuMixedState</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{8, 8}</string>
<string>{9, 12}</string>
<string>{11, 11}</string>
<string>{10, 3}</string>
</object>

View file

@ -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

View file

@ -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 {

View file

@ -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

View file

@ -11,7 +11,7 @@
@implementation PostModel
@synthesize text, inReplyTostatusId, inReplyToEntity, location, imageFilePath;
@synthesize text, inReplyTostatusId, inReplyToEntity, location, imageFilePath, isPrivate;
- (void)dealloc
{

View file

@ -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";

View file

@ -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) {

View file

@ -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<a href='https://skate.io/search?q=%23$3'>$3</a>");
}
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;

View file

@ -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);
}
}

View file

@ -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;