2
0

WFCUConferenceCommandContent.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // WFCUConferenceCommandContent.m
  3. // WFChatUIKit
  4. //
  5. // Created by Heavyrain on 2022/10/02.
  6. // Copyright © 2022 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUConferenceCommandContent.h"
  9. @implementation WFCUConferenceCommandContent
  10. + (instancetype)commandOfType:(WFCUConferenceCommandType)type conference:(NSString *)conferenceId {
  11. WFCUConferenceCommandContent *command = [[WFCUConferenceCommandContent alloc] init];
  12. command.type = type;
  13. command.conferenceId = conferenceId;
  14. return command;
  15. }
  16. -(WFCCMessagePayload *)encode {
  17. WFCCMessagePayload *payload = [super encode];
  18. payload.content = self.conferenceId;
  19. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  20. [dataDict setObject:@(self.type) forKey:@"t"];
  21. if (self.boolValue) {
  22. [dataDict setObject:@(YES) forKey:@"b"];
  23. }
  24. if (self.targetUserId.length) {
  25. [dataDict setObject:self.targetUserId forKey:@"u"];
  26. }
  27. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  28. options:kNilOptions
  29. error:nil];
  30. return payload;
  31. }
  32. -(void)decode:(WFCCMessagePayload *)payload {
  33. self.conferenceId = payload.content;
  34. NSError *__error = nil;
  35. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  36. options:kNilOptions
  37. error:&__error];
  38. if (!__error) {
  39. self.type = [dictionary[@"t"] integerValue];
  40. self.boolValue = [dictionary[@"b"] boolValue];
  41. self.targetUserId = dictionary[@"u"];
  42. }
  43. }
  44. + (int)getContentType {
  45. return VOIP_CONTENT_CONFERENCE_COMMAND;
  46. }
  47. + (int)getContentFlags {
  48. return WFCCPersistFlag_TRANSPARENT;
  49. }
  50. + (void)load {
  51. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  52. }
  53. @end