5 // Created by Evan Schoenberg on 9/10/05.
8 #import "AdiumChatEvents.h"
9 #import <Adium/AIContactAlertsControllerProtocol.h>
10 #import <Adium/AIChat.h>
11 #import <Adium/AIListContact.h>
12 #import <Adium/AIListObject.h>
13 #import <AIUtilities/AIImageAdditions.h>
14 #import <Adium/AIListGroup.h>
16 @implementation AdiumChatEvents
19 * @brief Our parent controller loaded
21 * Register the events we generate with the contactAlertsController.
22 * Assumption: The contactAlertController already loaded
24 - (void)controllerDidLoad
26 //Register the events we generate
27 [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_JOINED_CHAT
29 inGroup:AIMessageEventHandlerGroup
31 [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_LEFT_CHAT
33 inGroup:AIMessageEventHandlerGroup
35 [[adium contactAlertsController] registerEventID:CONTENT_GROUP_CHAT_INVITE
37 inGroup:AIMessageEventHandlerGroup
42 * @brief A group chat added a contact
44 - (void)chat:(AIChat *)chat addedListContact:(AIListContact *)inContact
46 [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_JOINED_CHAT
47 forListObject:inContact
48 userInfo:[NSDictionary dictionaryWithObject:chat
50 previouslyPerformedActionIDs:nil];
54 * @brief A group chat removed a contact
56 - (void)chat:(AIChat *)chat removedListContact:(AIListContact *)inContact
58 [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_LEFT_CHAT
59 forListObject:inContact
60 userInfo:[NSDictionary dictionaryWithObject:chat
62 previouslyPerformedActionIDs:nil];
65 #pragma mark Event descriptions
66 - (NSString *)shortDescriptionForEventID:(NSString *)eventID
68 NSString *description;
70 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
71 description = AILocalizedString(@"Joins a group chat",nil);
72 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
73 description = AILocalizedString(@"Leaves a group chat",nil);
74 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
75 description = AILocalizedString(@"Invites you to a group chat",nil);
83 - (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
85 NSString *description;
87 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
88 description = AILocalizedString(@"Contact joins a group chat",nil);
89 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
90 description = AILocalizedString(@"Contact leaves a group chat",nil);
91 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
92 description = AILocalizedString(@"Contact invites you to a group chat",nil);
100 //Evan: This exists because old X(tras) relied upon matching the description of event IDs, and I don't feel like making
101 //a converter for old packs. If anyone wants to fix this situation, please feel free :)
102 - (NSString *)englishGlobalShortDescriptionForEventID:(NSString *)eventID
104 NSString *description;
106 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
107 description = @"Contact Joins";
108 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
109 description = @"Contact Leaves";
110 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
111 description = @"Contact Invites You to Chat";
119 - (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
121 NSString *description = nil;
127 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
128 format = AILocalizedString(@"When %@ joins a group chat",nil);
129 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
130 format = AILocalizedString(@"When %@ leaves a group chat",nil);
131 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
132 format = AILocalizedString(@"When %@ invites you to a group chat",nil);
138 name = ([listObject isKindOfClass:[AIListGroup class]] ?
139 [NSString stringWithFormat:AILocalizedString(@"a member of %@",nil),[listObject displayName]] :
140 [listObject displayName]);
142 description = [NSString stringWithFormat:format, name];
146 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
147 description = AILocalizedString(@"When a contact joins a group chat",nil);
148 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
149 description = AILocalizedString(@"When a contact leaves a group chat",nil);
150 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
151 description = AILocalizedString(@"When a contact invites you to a group chat",nil);
158 - (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
159 listObject:(AIListObject *)listObject
160 userInfo:(id)userInfo
161 includeSubject:(BOOL)includeSubject
163 NSString *description = nil;
166 NSParameterAssert([userInfo isKindOfClass:[NSDictionary class]]);
168 chat = [(NSDictionary *)userInfo objectForKey:@"AIChat"];
170 if (includeSubject) {
171 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
172 description = [NSString stringWithFormat:
173 AILocalizedString(@"%@ joined %@","Contact joined Chat Name"),
174 [listObject displayName],
177 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
178 description = [NSString stringWithFormat:
179 AILocalizedString(@"%@ left %@","Contact left Chat Name"),
180 [listObject displayName],
182 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
183 description = [NSString stringWithFormat:
184 AILocalizedString(@"%@ left %@","Contact left Chat Name"),
185 [listObject displayName],
187 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
188 description = [NSString stringWithFormat:
189 AILocalizedString(@"%@ invites you to a group chat","Contact invites you to a group chat"),
190 [listObject displayName],
195 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
196 description = [NSString stringWithFormat:
197 AILocalizedString(@"joined %@","Contact joined Chat Name"),
200 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
201 description = [NSString stringWithFormat:
202 AILocalizedString(@"left %@","Contact left Chat Name"),
204 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
205 description = [NSString stringWithFormat:
206 AILocalizedString(@"invites you to a group chat","Contact left Chat Name"),
213 - (NSImage *)imageForEventID:(NSString *)eventID
215 static NSImage *eventImage = nil;
216 if (!eventImage) eventImage = [[NSImage imageNamed:@"message" forClass:[self class]] retain];