Messages display: Use local part of userId (instead of full userId) to apply 'bing' style on incoming messages.

This commit is contained in:
giomfo
2014-12-08 17:41:56 +01:00
parent 16ec008238
commit be142e4c7f
4 changed files with 27 additions and 6 deletions
+17
View File
@@ -238,6 +238,7 @@ static MatrixHandler *sharedHandler = nil;
- (void)logout {
// Reset access token (mxSession is closed by setter)
self.accessToken = nil;
self.userId = nil;
// Reset local storage of user's settings
self.userDisplayName = @"";
@@ -358,12 +359,28 @@ static MatrixHandler *sharedHandler = nil;
- (void)setUserId:(NSString *)inUserId {
if (inUserId.length) {
[[NSUserDefaults standardUserDefaults] setObject:inUserId forKey:@"userid"];
// Deduce local userid
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"localuserid"];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"@(.*):\\w+" options:NSRegularExpressionCaseInsensitive error:nil];
NSTextCheckingResult *match = [regex firstMatchInString:inUserId options:0 range:NSMakeRange(0, [inUserId length])];
if (match.numberOfRanges == 2) {
NSString* localId = [inUserId substringWithRange:[match rangeAtIndex:1]];
if (localId) {
[[NSUserDefaults standardUserDefaults] setObject:localId forKey:@"localuserid"];
}
}
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"userid"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"localuserid"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (NSString *)localPartFromUserId {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"localuserid"];
}
- (NSString *)accessToken {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"accesstoken"];
}