Created
March 24, 2016 00:13
-
-
Save Rich86man/dcb91236950294c1e875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef NS_ENUM(NSUInteger, RoomState) { | |
RoomStateActive, | |
RoomStatePendingCompletion, | |
RoomStateCompleted | |
}; | |
@interface SCRoom : RLMObject | |
@property NSNumber<RLMInt> *serverId; | |
@property NSString *name; | |
@property NSString *providerName; | |
@property NSNumber<RLMInt> *roomUserId; | |
@property NSString *userName; | |
@property (readonly) NSArray <SCMessage> *messages; | |
@property NSDate *lastMessageDate; | |
@property (nullable) NSString *session; | |
@property (nullable) NSString *state; | |
@property (readonly) RoomState currentState; | |
@property (nullable) RLMArray<SCUser> *users; | |
@property (nullable) RLMArray<SCUser> *admins; | |
@end | |
RLM_ARRAY_TYPE(SCRoom) | |
@implementation SCRoom | |
+ (NSString *)primaryKey | |
{ | |
return @"serverId"; | |
} | |
- (NSArray<SCMessage> *)messages | |
{ | |
return (NSArray<SCMessage> *)[self linkingObjectsOfClass:@"SCMessage" forProperty:@"room"]; | |
} | |
- (RoomState)currentState | |
{ | |
//active, pending_completion, completed | |
if ([self.state isEqualToString:@"active"]) { | |
return RoomStateActive; | |
} else if ([self.state isEqualToString:@"pending_completion"]) { | |
return RoomStatePendingCompletion; | |
} else { | |
return RoomStateCompleted; | |
} | |
} | |
@end | |
@interface SCUser : RLMObject | |
@property NSNumber<RLMInt> *serverId; | |
@property NSString *name; | |
@property NSString *providerId; | |
@property (nullable) NSString *avatarURLString; | |
@property BOOL isOnline; | |
- (nullable NSURL *)avatarURL; | |
@end | |
@implementation SCUser | |
+ (NSString *)primaryKey | |
{ | |
return @"serverId"; | |
} | |
- (nullable NSURL *)avatarURL | |
{ | |
if (self.avatarURLString && ![self.avatarURLString isEqualToString:@"/images/thumb/missing.png"]) { | |
return [NSURL URLWithString:self.avatarURLString]; | |
} | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment