RCChatroomSeatsControl.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // RCChatroomSeatsControl.m
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2022/2/21.
  6. // Copyright © 2022 DayaMusic. All rights reserved.
  7. //
  8. #import "RCChatroomSeatsControl.h"
  9. @implementation RCChatroomSeatsControl
  10. - (NSData *)encode {
  11. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  12. if (self.userId) {
  13. [mutableDict setObject:self.userId forKey:@"userId"];
  14. } else {
  15. [mutableDict setObject:@"" forKey:@"userId"];
  16. }
  17. if (self.userName) {
  18. [mutableDict setObject:self.userName forKey:@"userName"];
  19. } else {
  20. [mutableDict setObject:@"" forKey:@"userName"];
  21. }
  22. [mutableDict setObject:@(self.seatBan) forKey:@"seatBan"];
  23. if (self.senderUserInfo) {
  24. [mutableDict setObject:[self encodeUserInfo:self.senderUserInfo] forKey:@"user"];
  25. }
  26. return [NSJSONSerialization dataWithJSONObject:mutableDict options:kNilOptions error:nil];
  27. }
  28. - (void)decodeWithData:(NSData *)data {
  29. if (data == nil) return;
  30. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
  31. NSDictionary *json = [[NSDictionary alloc] initWithDictionary:dictionary];
  32. if (json == nil) return;
  33. self.userId = [json ks_stringValueForKey:@"userId"];
  34. self.userName = [json ks_stringValueForKey:@"userName"];
  35. self.seatBan = [[json ks_stringValueForKey:@"seatBan"] boolValue];
  36. NSDictionary *userinfoDic = dictionary[@"user"];
  37. [self decodeUserInfo:userinfoDic];
  38. }
  39. + (NSString *)getObjectName {
  40. return @"RC:Chatroom:SeatsCtrl";
  41. }
  42. - (NSArray<NSString *> *)getSearchableWords {
  43. return nil;
  44. }
  45. + (RCMessagePersistent)persistentFlag {
  46. return MessagePersistent_NONE;
  47. }
  48. @end