Browse files

Added support for receiving uploads

  • Loading branch information...
1 parent abc10f2 commit 3965e8d25983fa76ff3f85af934426a682904ee0 @pmhood pmhood committed May 1, 2011
View
24 Source/MSCampfireAccount.m
@@ -306,6 +306,11 @@ - (void)didReceiveMessage:(NSDictionary *)message
NSNumber *contactId = [message objectForKey:@"user_id"];
[[_rooms objectForKey:roomId] addContactWithUID:[contactId integerValue]];
[chat addParticipatingListObject:[self contactWithUID:[contactId stringValue]] notify:NotifyNow];
+ } else if ([messageType isEqualTo:@"UploadMessage"]) {
+ // If this is an upload message, ask the engine to get the upload details
+ NSNumber *uploadId = [message objectForKey:@"id"];
+ NSNumber *roomId = [message objectForKey:@"room_id"];
+ [engine getUploadForId:[uploadId integerValue] inRoom:[roomId integerValue]];
} else {
NSLog(@"message = %@", message);
}
@@ -314,10 +319,27 @@ - (void)didReceiveMessage:(NSDictionary *)message
- (void)didReceiveInformationForAuthenticatedUser:(NSDictionary *)user
{
NSString *authenticatedUserIdAsString = [[user objectForKey:@"user"] objectForKey:@"id"];
- AILogWithSignature(@"auth string = %@", authenticatedUserIdAsString);
authenticatedUserId = [authenticatedUserIdAsString integerValue];
AILogWithSignature(@"Authenticated User ID = %d", authenticatedUserId);
}
+- (void)didReceiveUpload:(NSDictionary *)upload
+{
+ NSDictionary *data = [upload objectForKey:@"upload"];
+ NSNumber *contactId = [data objectForKey:@"user_id"];
+ NSAttributedString *msg = [[NSAttributedString alloc] initWithString:[data objectForKey:@"full_url"]];
+ NSNumber *roomId = [data objectForKey:@"room_id"];
+ AIChat *chat = [self chatWithName:[roomId stringValue]];
+
+ AIContentMessage *contentMessage = [AIContentMessage messageInChat:chat
+ withSource:[self contactWithUID:[contactId stringValue]]
+ destination:self
+ date:[NSDate date]
+ message:msg
+ autoreply:NO];
+
+ [adium.contentController receiveContentObject:contentMessage];
+}
+
@end
View
2 Source/MSCampfireEngine/MSCampfireEngine.h
@@ -18,6 +18,7 @@
- (void)didReceiveInformationForUser:(NSDictionary *)user;
- (void)didReceiveMessage:(NSDictionary *)message;
- (void)didReceiveInformationForAuthenticatedUser:(NSDictionary *)user;
+- (void)didReceiveUpload:(NSDictionary *)upload;
@end
@@ -38,6 +39,7 @@
- (void)joinRoom:(NSInteger)roomId;
- (void)leaveRoom:(NSInteger)roomId;
- (void)sendTextMessage:(NSString *)message toRoom:(NSInteger)roomId;
+- (void)getUploadForId:(NSInteger)uploadId inRoom:(NSInteger)roomId;
// Streaming API
- (void)startListeningForMessagesInRoom:(NSInteger)roomId;
View
13 Source/MSCampfireEngine/MSCampfireEngine.m
@@ -18,6 +18,7 @@
#define SPEAK @"speak"
#define USER_INFORMATION @"user information"
#define AUTHENTICATED_USER_INFORMATION @"authenticated user information"
+#define UPLOAD_INFORMATION @"upload information"
@interface MSCampfireEngine (Private)
@@ -84,6 +85,12 @@ - (void)getInformationForAuthenticatedUser
[self startRequestWithMethod:@"GET" path:path streaming:NO key:path userInfo:AUTHENTICATED_USER_INFORMATION];
}
+- (void)getUploadForId:(NSInteger)uploadId inRoom:(NSInteger)roomId
+{
+ NSString *path = [NSString stringWithFormat:@"/room/%d/messages/%d/upload.json", roomId, uploadId];
+ [self startRequestWithMethod:@"GET" path:path streaming:NO key:path userInfo:UPLOAD_INFORMATION];
+}
+
- (void)joinRoom:(NSInteger)roomId
{
NSString *path = [NSString stringWithFormat:@"/room/%d/join.xml", roomId];
@@ -203,6 +210,12 @@ - (void)connection:(MSHTTPConnection *)connection didReceiveBody:(NSString *)bod
[delegate didReceiveInformationForAuthenticatedUser:d];
}
AILogWithSignature(@"auth information = %@", body);
+ } else if([[connection identifier] isEqualTo:UPLOAD_INFORMATION]) {
+ if ([delegate respondsToSelector:@selector(didReceiveUpload:)]) {
+ NSDictionary *d = [body JSONValue];
+ [delegate didReceiveUpload:d];
+ }
+ AILogWithSignature(@"upload information = %@", body);
}
else if ([[connection identifier] respondsToSelector:@selector(objectForKey:)]) {

0 comments on commit 3965e8d

Please sign in to comment.