Commits

Paul Schifferer  committed 54584da

Added missing query parameter for message annotations.
Added missing serialization classes.
Fixed handling of custom entities on users, posts, and messages.

  • Participants
  • Parent commits b647c54

Comments (0)

Files changed (5)

File Snapper/Source/Shared/SNPCreateMessageOperation.h

  */
 @property (nonatomic, retain) NSArray* entities;
 
+@property (nonatomic, assign) BOOL includeMessageAnnotations;
+
 // -- Initializers --
 - (id)initWithChannelId:(NSUInteger)channelId
                    text:(NSString*)text

File Snapper/Source/Shared/SNPCreateMessageOperation.m

 
 #import "SNPCreateMessageOperation.h"
 
+#import "SNPMessage.h"
 #import "SNPResponse.h"
 #import "SNPAnnotation.h"
 #import "SNPEntity.h"
+#import "SNPMention.h"
+#import "SNPLink.h"
+#import "SNPHashtag.h"
 #import "SNPPost.h"
 
 #import "SNPAPIUtils.h"
         self.machineOnly = machineOnly;
         self.annotations = annotations;
         self.entities = entities;
+        self.serializationRootClass = [SNPMessage class];
     }
 
     return self;
     self.endpoint = [[SNPAPIUtils sharedAPIUtils] createMessageEndpointURL:_channelId];
     self.method = @"POST";
 
+    [self handleQueryParameters];
+
     NSMutableDictionary* postDict = [NSMutableDictionary new];
     if([_text length]) {
         postDict[@"text"] = _text;
         postDict[@"annotations"] = serializedAnnotations;
     }
     if(_entities) {
-        NSMutableArray* serializedEntities = [NSMutableArray new];
+        NSMutableArray* serializedHashtags = [NSMutableArray new];
+        NSMutableArray* serializedLinks = [NSMutableArray new];
+        NSMutableArray* serializedMentions = [NSMutableArray new];
         for(SNPEntity* entity in _entities) {
             NSDictionary* entityDict = [entity externalRepresentation];
-            [serializedEntities addObject:entityDict];
+
+            if([entity isKindOfClass:[SNPLink class]]) {
+                [serializedLinks addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPMention class]]) {
+                [serializedMentions addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPHashtag class]]) {
+                [serializedHashtags addObject:entityDict];
+            }
+        }
+
+        if([serializedHashtags count] ||
+           [serializedLinks count] ||
+           [serializedMentions count]) {
+            NSMutableDictionary* entitiesDict = [NSMutableDictionary new];
+
+            if([serializedMentions count]) {
+                entitiesDict[@"mentions"] = serializedMentions;
+            }
+            if([serializedLinks count]) {
+                entitiesDict[@"links"] = serializedLinks;
+            }
+            if([serializedHashtags count]) {
+                entitiesDict[@"hashtags"] = serializedHashtags;
+            }
+
+            postDict[@"entities"] = entitiesDict;
         }
-        postDict[@"entities"] = serializedEntities;
     }
 
     NSError* error = nil;
     [super main];
 }
 
+- (void)handleQueryParameters {
+
+    NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
+
+    if(self.parameters) {
+        [parameters addEntriesFromDictionary:self.parameters];
+    }
+
+    if(_includeMessageAnnotations) {
+        parameters[@"include_message_annotations"] = @(_includeMessageAnnotations);
+    }
+
+    if([[parameters allKeys] count]) {
+        self.parameters = parameters;
+    }
+}
+
 @end

File Snapper/Source/Shared/SNPCreatePostOperation.m

 #import "SNPResponse.h"
 #import "SNPAnnotation.h"
 #import "SNPEntity.h"
+#import "SNPMention.h"
+#import "SNPLink.h"
+#import "SNPHashtag.h"
 #import "SNPPost.h"
 
 #import "SNPAPIUtils.h"
         self.annotations = annotations;
         self.entities = entities;
         self.progressBlock = progressBlock;
+        self.method = @"POST";
+        self.serializationRootClass = [SNPPost class];
     }
 
     return self;
 - (void)main {
 
     self.endpoint = [[SNPAPIUtils sharedAPIUtils] createPostEndpointURL];
-    self.method = @"POST";
-    self.serializationRootClass = [SNPPost class];
 
     NSMutableDictionary* postDict = [NSMutableDictionary new];
     if([_text length]) {
         postDict[@"annotations"] = serializedAnnotations;
     }
     if(_entities) {
-        NSMutableArray* serializedEntities = [NSMutableArray new];
+        NSMutableArray* serializedHashtags = [NSMutableArray new];
+        NSMutableArray* serializedLinks = [NSMutableArray new];
+        NSMutableArray* serializedMentions = [NSMutableArray new];
         for(SNPEntity* entity in _entities) {
             NSDictionary* entityDict = [entity externalRepresentation];
-            [serializedEntities addObject:entityDict];
+
+            if([entity isKindOfClass:[SNPLink class]]) {
+                [serializedLinks addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPMention class]]) {
+                [serializedMentions addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPHashtag class]]) {
+                [serializedHashtags addObject:entityDict];
+            }
+        }
+
+        if([serializedHashtags count] ||
+           [serializedLinks count] ||
+           [serializedMentions count]) {
+            NSMutableDictionary* entitiesDict = [NSMutableDictionary new];
+
+            if([serializedMentions count]) {
+                entitiesDict[@"mentions"] = serializedMentions;
+            }
+            if([serializedLinks count]) {
+                entitiesDict[@"links"] = serializedLinks;
+            }
+            if([serializedHashtags count]) {
+                entitiesDict[@"hashtags"] = serializedHashtags;
+            }
+
+            postDict[@"entities"] = entitiesDict;
         }
-        postDict[@"entities"] = serializedEntities;
     }
 
     NSError* error = nil;

File Snapper/Source/Shared/SNPDeletePostOperation.m

 
 #import "SNPDeletePostOperation.h"
 
+#import "SNPPost.h"
+
 #import "SNPAPIUtils.h"
 
 
         self.postId = postId;
         self.endpoint = [[SNPAPIUtils sharedAPIUtils] deletePostEndpointURL:postId];
         self.method = @"DELETE";
+        self.serializationRootClass = [SNPPost class];
     }
 
     return self;

File Snapper/Source/Shared/SNPUpdateUserOperation.m

 #import "SNPUser.h"
 #import "SNPAnnotation.h"
 #import "SNPEntity.h"
+#import "SNPMention.h"
+#import "SNPLink.h"
+#import "SNPHashtag.h"
 
 #import "SNPAPIUtils.h"
 
     NSMutableDictionary* descriptionDict = [NSMutableDictionary new];
     descriptionDict[@"text"] = _description;
     if(_descriptionEntities) {
-        NSMutableArray* serializedEntities = [NSMutableArray new];
-
+        NSMutableArray* serializedHashtags = [NSMutableArray new];
+        NSMutableArray* serializedLinks = [NSMutableArray new];
+        NSMutableArray* serializedMentions = [NSMutableArray new];
         for(SNPEntity* entity in _descriptionEntities) {
             NSDictionary* entityDict = [entity externalRepresentation];
-            [serializedEntities addObject:entityDict];
+
+            if([entity isKindOfClass:[SNPLink class]]) {
+                [serializedLinks addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPMention class]]) {
+                [serializedMentions addObject:entityDict];
+            }
+            else if([entity isKindOfClass:[SNPHashtag class]]) {
+                [serializedHashtags addObject:entityDict];
+            }
         }
 
-        descriptionDict[@"entities"] = serializedEntities;
+        if([serializedHashtags count] ||
+           [serializedLinks count] ||
+           [serializedMentions count]) {
+            NSMutableDictionary* entitiesDict = [NSMutableDictionary new];
+
+            if([serializedMentions count]) {
+                entitiesDict[@"mentions"] = serializedMentions;
+            }
+            if([serializedLinks count]) {
+                entitiesDict[@"links"] = serializedLinks;
+            }
+            if([serializedHashtags count]) {
+                entitiesDict[@"hashtags"] = serializedHashtags;
+            }
+
+            descriptionDict[@"entities"] = entitiesDict;
+        }
     }
     userDict[@"description"] = descriptionDict;