adium/adium

5cd72bf325c6
Add support for server-sent outgoing messages (i.e. carbons on XMPP).
--- a/Plugins/Purple Service/CBPurpleAccount.m Thu May 23 22:01:14 2013 +0200
+++ b/Plugins/Purple Service/CBPurpleAccount.m Thu May 23 22:25:59 2013 +0200
@@ -1235,13 +1235,24 @@
{
AILogWithSignature(@"Message: %@ inChat: %@ fromListContact: %@ flags: %d date: %@", attributedMessage, chat, sourceContact, flags, date);
+ id source;
+ id destination;
+
+ if ((flags & PURPLE_MESSAGE_SEND) == PURPLE_MESSAGE_SEND) {
+ destination = [sourceContact.UID isEqualToString:self.UID]? (AIListObject *)self : (AIListObject *)sourceContact;
+ source = self;
+ } else {
+ source = [sourceContact.UID isEqualToString:self.UID]? (AIListObject *)self : (AIListObject *)sourceContact;
+ destination = self;
+ }
+
if ((flags & PURPLE_MESSAGE_DELAYED) == PURPLE_MESSAGE_DELAYED) {
// Display delayed messages as context.
AIContentContext *messageObject = [AIContentContext messageInChat:chat
- withSource:[sourceContact.UID isEqualToString:self.UID]? (AIListObject *)self : (AIListObject *)sourceContact
+ withSource:source
sourceNick:sourceNick
- destination:self
+ destination:destination
date:date
message:attributedMessage
autoreply:(flags & PURPLE_MESSAGE_AUTO_RESP) != 0];
@@ -1251,9 +1262,9 @@
} else {
AIContentMessage *messageObject = [AIContentMessage messageInChat:chat
- withSource:[sourceContact.UID isEqualToString:self.UID]? (AIListObject *)self : (AIListObject *)sourceContact
+ withSource:source
sourceNick:sourceNick
- destination:self
+ destination:destination
date:date
message:attributedMessage
autoreply:(flags & PURPLE_MESSAGE_AUTO_RESP) != 0];
--- a/Plugins/Purple Service/adiumPurpleConversation.m Thu May 23 22:01:14 2013 +0200
+++ b/Plugins/Purple Service/adiumPurpleConversation.m Thu May 23 22:25:59 2013 +0200
@@ -122,49 +122,53 @@
time_t mtime)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- //We only care about this if it does not have the PURPLE_MESSAGE_SEND flag, which is set if Purple is sending a sent message back to us
- if ((flags & PURPLE_MESSAGE_SEND) == 0) {
- if (flags & PURPLE_MESSAGE_NOTIFY) {
- // We received a notification (nudge or buzz). Send a notification of such.
- NSString *type, *messageString = [NSString stringWithUTF8String:message];
-
- // Determine what we're actually notifying about.
- if ([messageString rangeOfString:@"nudge" options:(NSCaseInsensitiveSearch | NSLiteralSearch)].location != NSNotFound) {
- type = @"Nudge";
- } else if ([messageString rangeOfString:@"buzz" options:(NSCaseInsensitiveSearch | NSLiteralSearch)].location != NSNotFound) {
- type = @"Buzz";
- } else {
- // Just call an unknown type a "notification"
- type = @"notification";
- }
-
- [[NSNotificationCenter defaultCenter] postNotificationName:Chat_NudgeBuzzOccured
- object:chatLookupFromConv(conv)
- userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- type, @"Type",
- nil]];
+
+ // We only care about this if it does not have the PURPLE_MESSAGE_SEND flag, which is set if Purple is sending a sent message back to us
+ // Or if it has both PURPLE_MESSAGE_SEND and PURPLE_MESSAGE_RECV: we received from the server a message that we supposedly sent ourselves.
+ if ((flags & PURPLE_MESSAGE_SEND) == PURPLE_MESSAGE_SEND && (flags & PURPLE_MESSAGE_RECV) == 0) {
+ [pool release];
+ return;
+ }
+
+ if (flags & PURPLE_MESSAGE_NOTIFY) {
+ // We received a notification (nudge or buzz). Send a notification of such.
+ NSString *type, *messageString = [NSString stringWithUTF8String:message];
+
+ // Determine what we're actually notifying about.
+ if ([messageString rangeOfString:@"nudge" options:(NSCaseInsensitiveSearch | NSLiteralSearch)].location != NSNotFound) {
+ type = @"Nudge";
+ } else if ([messageString rangeOfString:@"buzz" options:(NSCaseInsensitiveSearch | NSLiteralSearch)].location != NSNotFound) {
+ type = @"Buzz";
} else {
- NSDictionary *messageDict;
- CBPurpleAccount *adiumAccount = accountLookup(purple_conversation_get_account(conv));
- NSString *messageString;
- AIChat *chat;
-
- messageString = [NSString stringWithUTF8String:message];
- chat = chatLookupFromConv(conv);
-
- AILog(@"adiumPurpleConvWriteIm: Received %@ from %@", messageString, chat.listObject.UID);
-
- //Process any purple imgstore references into real HTML tags pointing to real images
- messageString = processPurpleImages(messageString, adiumAccount);
-
- messageDict = [NSDictionary dictionaryWithObjectsAndKeys:messageString,@"Message",
- [NSNumber numberWithInteger:flags],@"PurpleMessageFlags",
- [NSDate dateWithTimeIntervalSince1970:mtime],@"Date",nil];
-
- [adiumAccount receivedIMChatMessage:messageDict
- inChat:chat];
+ // Just call an unknown type a "notification"
+ type = @"notification";
}
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:Chat_NudgeBuzzOccured
+ object:chatLookupFromConv(conv)
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ type, @"Type",
+ nil]];
+ } else {
+ NSDictionary *messageDict;
+ CBPurpleAccount *adiumAccount = accountLookup(purple_conversation_get_account(conv));
+ NSString *messageString;
+ AIChat *chat;
+
+ messageString = [NSString stringWithUTF8String:message];
+ chat = chatLookupFromConv(conv);
+
+ AILog(@"adiumPurpleConvWriteIm: Received %@ from %@", messageString, chat.listObject.UID);
+
+ //Process any purple imgstore references into real HTML tags pointing to real images
+ messageString = processPurpleImages(messageString, adiumAccount);
+
+ messageDict = [NSDictionary dictionaryWithObjectsAndKeys:messageString,@"Message",
+ [NSNumber numberWithInteger:flags],@"PurpleMessageFlags",
+ [NSDate dateWithTimeIntervalSince1970:mtime],@"Date",nil];
+
+ [adiumAccount receivedIMChatMessage:messageDict
+ inChat:chat];
}
[pool drain];
}