TUIGroupNoticeDataProvider.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // TUIGroupNoticeDataProvider.m
  3. // TUIGroup
  4. //
  5. // Created by harvy on 2022/1/12.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIGroupNoticeDataProvider.h"
  9. @interface TUIGroupNoticeDataProvider ()
  10. @property(nonatomic, strong) V2TIMGroupInfo *groupInfo;
  11. @end
  12. @implementation TUIGroupNoticeDataProvider
  13. - (void)getGroupInfo:(dispatch_block_t)callback {
  14. if (self.groupInfo && [self.groupInfo.groupID isEqual:self.groupID]) {
  15. if (callback) {
  16. callback();
  17. }
  18. return;
  19. }
  20. __weak typeof(self) weakSelf = self;
  21. [V2TIMManager.sharedInstance getGroupsInfo:@[ self.groupID ?: @"" ]
  22. succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
  23. V2TIMGroupInfoResult *result = groupResultList.firstObject;
  24. if (result && result.resultCode == 0) {
  25. weakSelf.groupInfo = result.info;
  26. }
  27. if (callback) {
  28. callback();
  29. }
  30. }
  31. fail:^(int code, NSString *desc) {
  32. if (callback) {
  33. callback();
  34. }
  35. }];
  36. }
  37. - (BOOL)canEditNotice {
  38. return self.groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN || self.groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_SUPER;
  39. }
  40. - (void)updateNotice:(NSString *)notice callback:(void (^)(int, NSString *))callback {
  41. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  42. info.groupID = self.groupID;
  43. info.notification = notice;
  44. __weak typeof(self) weakSelf = self;
  45. [V2TIMManager.sharedInstance setGroupInfo:info
  46. succ:^{
  47. if (callback) {
  48. callback(0, nil);
  49. }
  50. [weakSelf sendNoticeMessage:notice];
  51. }
  52. fail:^(int code, NSString *desc) {
  53. if (callback) {
  54. callback(code, desc);
  55. }
  56. }];
  57. }
  58. - (void)sendNoticeMessage:(NSString *)notice {
  59. if (notice.length == 0) {
  60. return;
  61. }
  62. }
  63. @end