Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Using prefixesMap to discover modes of users in a channel.

  • Loading branch information...
commit 0d37c5259cc0fdfa5e3616558c5d9d26c4e6a128 1 parent 85e5697
Konstantin Merenkov authored
View
22 Classes/IRC/IRCClient.m
@@ -3373,19 +3373,21 @@ - (void)receiveNumericReply:(IRCMessage*)m
for (NSString* nick in ary) {
if (!nick.length) continue;
UniChar u = [nick characterAtIndex:0];
- char op = ' ';
- if (u == '@' || u == '~' || u == '&' || u == '%' || u == '+') {
- op = u;
+ NSString *str_u = [NSString stringWithFormat:@"%C", u];
+ UniChar mode = [isupport userModeByPrefix:str_u];
+
+ IRCUser* m = [[IRCUser new] autorelease];
+
+ if (mode) {
nick = [nick substringFromIndex:1];
+ m.q = mode == 'q';
+ m.a = mode == 'a';
+ m.o = mode == 'o';
+ m.h = mode == 'h';
+ m.v = mode == 'v';
}
-
- IRCUser* m = [[IRCUser new] autorelease];
+
m.nick = nick;
- m.q = op == '~';
- m.a = op == '&';
- m.o = op == '@' || m.q;
- m.h = op == '%';
- m.v = op == '+';
m.isMyself = [nick isEqualNoCase:myNick];
[c addMember:m reload:NO];
if ([myNick isEqualNoCase:nick]) {
View
2  Classes/IRC/IRCISupportInfo.h
@@ -22,7 +22,7 @@
- (void)reset;
- (void)update:(NSString*)s;
- (NSArray*)parseMode:(NSString*)s;
-- (NSString*)modeForPrefix:(NSString*)p;
+- (UniChar)userModeByPrefix:(NSString*)p;
@end
View
12 Classes/IRC/IRCISupportInfo.m
@@ -67,6 +67,7 @@ - (void)reset
prefixesMap = [[NSMutableDictionary alloc] initWithCapacity:6];
// The problem is that with a dictionary I cannot make the following rule:
// if q and not o then still o
+ // NOTE what if I don't need to?
[prefixesMap setObject:@"~" forKey:@"q"];
[prefixesMap setObject:@"!" forKey:@"o"];
[prefixesMap setObject:@"&" forKey:@"o"];
@@ -192,8 +193,8 @@ - (void)parsePrefix:(NSString*)str
UniChar m = [ms characterAtIndex:i];
[self setValue:OP_VALUE forMode:m];
UniChar p = [ps characterAtIndex:i];
- [prefixesMap setObject:[NSString stringWithFormat:@"%C",m]
- forKey:[NSString stringWithFormat:@"%C",p]];
+ [prefixesMap setObject:[NSString stringWithFormat:@"%C", m]
+ forKey:[NSString stringWithFormat:@"%C", p]];
}
}
}
@@ -239,9 +240,12 @@ - (int)valueForMode:(unsigned char)m
return 0;
}
-- (NSString*)modeForPrefix:(NSString*)p
+- (UniChar)userModeByPrefix:(NSString*)p
{
- return [prefixesMap objectForKey:p];
+ NSString *obj = [prefixesMap objectForKey:p];
+ if ((obj != nil) && obj.length)
+ return (UniChar)[obj characterAtIndex:0];
+ return nil;
}
Please sign in to comment.
Something went wrong with that request. Please try again.