| 82 | | //TODO: check first if the user already has an icon, no need to do this over and over again. also: check for buddies. |
|---|
| 83 | | [self addAvatarToUser:[(JVChatRoomMember *)[message sender] user]]; |
|---|
| | 78 | //NSLog(@"Avatar Support: -- %@ (class), user: %@/%@: %@ (class)", [[[message sender] class] description], [[(JVChatRoomMember *)[message sender] user] serverAddress], [[(JVChatRoomMember *)[message sender] user] nickname], [[[[message sender] user] class] description]); |
|---|
| | 79 | |
|---|
| | 80 | //TODO: check for buddies, unless this works for them too (doesnt, *.quakenet.org bug) |
|---|
| | 81 | if ([[[(JVChatRoomMember *)[message sender] user] attributes] objectForKey:@"MVChatUserPictureAttribute"] == nil) |
|---|
| | 82 | { |
|---|
| | 83 | //NSLog(@"Avatar Support: -- nil: %@", [[[[(JVChatRoomMember *)[message sender] user] attributes] objectForKey:@"MVChatUserPictureAttribute"] description]); |
|---|
| | 84 | [self addAvatarToUser:[(JVChatRoomMember *)[message sender] user]]; |
|---|
| | 85 | } |
|---|
| | 86 | else |
|---|
| | 87 | { |
|---|
| | 88 | //NSLog(@"Avatar Support: -- nicht nil: %@", [[[[(JVChatRoomMember *)[message sender] user] attributes] objectForKey:@"MVChatUserPictureAttribute"] description]); |
|---|
| | 89 | //TODO: remove this |
|---|
| | 90 | [[JVNotificationController defaultController] performNotification:@"JVPluginNotification" withContextInfo:[NSDictionary dictionaryWithObjectsAndKeys:[[[(JVChatRoomMember *)[message sender] user] attributes] objectForKey:@"MVChatUserPictureAttribute"],@"image",@"Avatar Support",@"title",[NSString stringWithFormat:@"%@ already has an Avatar.", [[(JVChatRoomMember *)[message sender] user] nickname]],@"description",nil]]; |
|---|
| | 91 | } |
|---|
| | 92 | } |
|---|
| | 93 | else |
|---|
| | 94 | { |
|---|
| | 95 | //TODO: this is for direct chats, see comment #1 above |
|---|
| | 96 | //NSLog(@"Avatar Support: -- %@/%@: %@ (class)", [(MVChatUser *)[message sender] serverAddress], [(MVChatUser *)[message sender] nickname], [[[message sender] class] description]); |
|---|
| | 97 | |
|---|
| | 98 | //TODO: check for buddies, unless this works for them too (doesnt) |
|---|
| | 99 | if ([[(MVChatUser *)[message sender] attributes] objectForKey:@"MVChatUserPictureAttribute"] == nil) |
|---|
| | 100 | { |
|---|
| | 101 | //NSLog(@"Avatar Support: -- nil: %@", [[[(MVChatUser *)[message sender] attributes] objectForKey:@"MVChatUserPictureAttribute"] description]); |
|---|
| | 102 | [self addAvatarToUser:(MVChatUser *)[message sender]]; |
|---|
| | 103 | } |
|---|
| | 104 | else |
|---|
| | 105 | { |
|---|
| | 106 | //NSLog(@"Avatar Support: --nicht nil: %@", [[[(MVChatUser *)[message sender] attributes] objectForKey:@"MVChatUserPictureAttribute"] description]); |
|---|
| | 107 | //TODO: remove this |
|---|
| | 108 | [[JVNotificationController defaultController] performNotification:@"JVPluginNotification" withContextInfo:[NSDictionary dictionaryWithObjectsAndKeys:[[(MVChatUser *)[message sender] attributes] objectForKey:@"MVChatUserPictureAttribute"],@"image",@"Avatar Support",@"title",[NSString stringWithFormat:@"%@ already has an Avatar.", [(MVChatUser *)[message sender] nickname]],@"description",nil]]; |
|---|
| | 109 | } |
|---|
| 95 | | - (BOOL) processSubcodeRequest:(NSString *)command withArguments:(NSData *)arguments fromUser:(MVChatUser *)user |
|---|
| 96 | | { |
|---|
| 97 | | //TODO: remove NSLog |
|---|
| 98 | | // NSLog([@"AVATAR: Subcode Request: " stringByAppendingString:command]); |
|---|
| 99 | | // NSLog([user nickname]); |
|---|
| 100 | | |
|---|
| | 121 | - (BOOL) processSubcodeRequest:(NSString *)command withArguments:(NSData *)arguments fromUser:(MVChatUser *)chatUser |
|---|
| | 122 | { |
|---|
| | 123 | if ([[command uppercaseString] isEqualToString:@"AVATEST"]) |
|---|
| | 124 | { |
|---|
| | 125 | //TODO: remove NSLog |
|---|
| | 126 | NSLog(@"Avatar Support: <- Bogus request event for %@.", [chatUser nickname]); |
|---|
| | 127 | [self requestAvatarFromUser:chatUser]; |
|---|
| | 128 | return YES; |
|---|
| | 129 | } |
|---|
| 103 | | if (arguments) |
|---|
| 104 | | { |
|---|
| 105 | | NSLog(@"das war ein angebot von %@", [user nickname]); |
|---|
| | 132 | //TODO: remove NSLog |
|---|
| | 133 | NSLog(@"Avatar Support: -> request by %@.", [chatUser nickname]); |
|---|
| | 134 | // if (weWantToSendAvatarToUser:chatUser) |
|---|
| | 135 | // { |
|---|
| | 136 | [self offerAvatarToUser:chatUser]; |
|---|
| | 137 | return YES; |
|---|
| | 138 | // } |
|---|
| | 139 | } |
|---|
| | 140 | return NO; |
|---|
| | 141 | } |
|---|
| | 142 | |
|---|
| | 143 | - (BOOL) processSubcodeReply:(NSString *)command withArguments:(NSData *)arguments fromUser:(MVChatUser *)chatUser |
|---|
| | 144 | { |
|---|
| | 145 | if ([[command uppercaseString] isEqualToString:AKAvatarSupportCTCPCommand]) |
|---|
| | 146 | { |
|---|
| | 147 | NSArray *argumentArray = [[[[NSString alloc] initWithData:arguments encoding:[[chatUser connection] encoding]] autorelease] componentsSeparatedByString:@" "]; |
|---|
| | 148 | |
|---|
| | 149 | //TODO: remove NSLog |
|---|
| | 150 | NSLog(@"Avatar Support: <- reply from %@ with arguments %@.", [chatUser nickname], [argumentArray description]); |
|---|
| | 151 | |
|---|
| | 152 | // if (weWantToReceiveAvatarFromUser:chatUser) |
|---|
| | 153 | // { |
|---|
| | 154 | //NSLog(@"Avatar Support: <- accepting avatar from %@.", [chatUser nickname]); |
|---|
| | 155 | NSImage *receivedImage = [NSImage alloc]; |
|---|
| 107 | | NSArray *argumentArray = [[[[NSString alloc] initWithData:arguments encoding:[[user connection] encoding]] autorelease] componentsSeparatedByString:@" "]; |
|---|
| 108 | | NSLog(@"Arguments: %@",[argumentArray description]); |
|---|
| 109 | | // if (weWantToReceiveAvatarFromUser:user) |
|---|
| | 157 | //TODO: do some checks first: filezise, evil filetypes... |
|---|
| | 158 | if ([receivedImage initWithContentsOfURL:[NSURL URLWithString:[argumentArray objectAtIndex:0]]]) |
|---|
| | 159 | { |
|---|
| | 160 | [self saveAvatar:receivedImage forUser:chatUser]; |
|---|
| | 161 | [self addAvatarToUser:chatUser]; |
|---|
| | 162 | [[JVNotificationController defaultController] performNotification:@"JVPluginNotification" withContextInfo:[NSDictionary dictionaryWithObjectsAndKeys:[[chatUser attributes] objectForKey:@"MVChatUserPictureAttribute"],@"image",@"Avatar Support",@"title",[NSString stringWithFormat:@"Received Avatar from user %@.", [chatUser nickname]],@"description",nil]]; |
|---|
| | 163 | return YES; |
|---|
| | 164 | } |
|---|
| | 165 | // else |
|---|
| 123 | | // if (filesizeisokay) |
|---|
| 124 | | // { |
|---|
| 125 | | //NSLog(@"DCC Filetransfer required"); |
|---|
| 126 | | //[18:39] <xenon> there is, just dont add it to the MVFileTransferManager |
|---|
| 127 | | //MVFileTransferController |
|---|
| 128 | | //MVFileTransfer |
|---|
| 129 | | //filetransfer <- requestAvatarFromUser:user |
|---|
| 130 | | //filetransferdelegate: [self addAvatarToUser:user]; |
|---|
| 131 | | // } |
|---|
| | 169 | //NSLog(@"Avatar Support: <- dcc file transfer request for %@ required.", [chatUser nickname]); |
|---|
| | 170 | //[18:39] <xenon> there is, just dont add it to the MVFileTransferManager |
|---|
| | 171 | //MVFileTransferController |
|---|
| | 172 | //MVFileTransfer |
|---|
| | 173 | //filetransfer <- requestAvatarFromUser:chatUser |
|---|
| | 174 | //filetransferdelegate: [self addAvatarToUser:chatUser]; |
|---|
| | 175 | //return YES; |
|---|
| 169 | | //TODO: Remove this test output of the image |
|---|
| 170 | | NSAlert *alert = [[[NSAlert alloc] init] autorelease]; |
|---|
| 171 | | [alert addButtonWithTitle:@"OK"]; |
|---|
| 172 | | [alert setMessageText:@"Added avatar to user"]; |
|---|
| 173 | | [alert setInformativeText:[chatUser nickname]]; |
|---|
| 174 | | [alert setIcon:[self avatarForUser:chatUser]]; |
|---|
| 175 | | [alert setAlertStyle:NSInformationalAlertStyle]; |
|---|
| 176 | | [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil]; |
|---|
| 177 | | } |
|---|
| 178 | | } |
|---|
| 179 | | |
|---|
| 180 | | - (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo |
|---|
| 181 | | { |
|---|
| 182 | | //TODO: remove this here and in the header, just for testing |
|---|
| | 219 | //TODO: remove this later, its enough to growl on "received avatar" |
|---|
| | 220 | [[JVNotificationController defaultController] performNotification:@"JVPluginNotification" withContextInfo:[NSDictionary dictionaryWithObjectsAndKeys:[[chatUser attributes] objectForKey:@"MVChatUserPictureAttribute"],@"image",@"Avatar Support",@"title",[NSString stringWithFormat:@"Avatar added for user %@.", [chatUser nickname]],@"description",nil]]; |
|---|
| | 221 | } |
|---|