WFCUShareMessageView.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // ShareMessageView.m
  3. // TYAlertControllerDemo
  4. //
  5. // Created by tanyang on 15/10/26.
  6. // Copyright © 2015年 tanyang. All rights reserved.
  7. //
  8. #import "WFCUShareMessageView.h"
  9. #import "UIView+TYAlertView.h"
  10. #import "UITextView+Placeholder.h"
  11. #import <SDWebImage/SDWebImage.h>
  12. @interface WFCUShareMessageView ()
  13. @property (weak, nonatomic) IBOutlet UIImageView *portraitImageView;
  14. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *digestLabel;
  16. @property (weak, nonatomic) IBOutlet UITextView *messageTextView;
  17. @property (weak, nonatomic) IBOutlet UIView *digestBackgrouView;
  18. @end
  19. @implementation WFCUShareMessageView
  20. - (void)updateUI {
  21. self.digestBackgrouView.clipsToBounds = YES;
  22. self.digestBackgrouView.layer.masksToBounds = YES;
  23. self.digestBackgrouView.layer.cornerRadius = 8.f;
  24. self.messageTextView.placeholder = WFCString(@"LeaveMessage");
  25. self.messageTextView.layer.masksToBounds = YES;
  26. self.messageTextView.layer.cornerRadius = 8.f;
  27. self.messageTextView.contentInset = UIEdgeInsetsMake(2, 8, 2, 2);
  28. self.messageTextView.layer.borderWidth = 0.5f;
  29. self.messageTextView.layer.borderColor = [[UIColor greenColor] CGColor];
  30. }
  31. - (IBAction)sendAction:(id)sender {
  32. [self hideView];
  33. WFCCTextMessageContent *textMsg;
  34. if (self.messageTextView.text.length) {
  35. textMsg = [[WFCCTextMessageContent alloc] init];
  36. textMsg.text = self.messageTextView.text;
  37. }
  38. __strong WFCCConversation *conversation = self.conversation;
  39. __strong void (^forwardDone)(BOOL success) = self.forwardDone;
  40. if (self.message) {
  41. [[WFCCIMService sharedWFCIMService] send:conversation content:self.message.content success:^(long long messageUid, long long timestamp) {
  42. if (textMsg) {
  43. [[WFCCIMService sharedWFCIMService] send:conversation content:textMsg success:^(long long messageUid, long long timestamp) {
  44. dispatch_async(dispatch_get_main_queue(), ^{
  45. if (forwardDone) {
  46. forwardDone(YES);
  47. }
  48. });
  49. } error:^(int error_code) {
  50. dispatch_async(dispatch_get_main_queue(), ^{
  51. if (forwardDone) {
  52. forwardDone(NO);
  53. }
  54. });
  55. }];
  56. } else {
  57. dispatch_async(dispatch_get_main_queue(), ^{
  58. if (forwardDone) {
  59. forwardDone(YES);
  60. }
  61. });
  62. }
  63. } error:^(int error_code) {
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. if (forwardDone) {
  66. forwardDone(NO);
  67. }
  68. });
  69. }];
  70. } else {
  71. for (WFCCMessage *msg in self.messages) {
  72. [[WFCCIMService sharedWFCIMService] send:conversation content:msg.content success:^(long long messageUid, long long timestamp) {
  73. } error:^(int error_code) {
  74. }];
  75. [NSThread sleepForTimeInterval:0.1];
  76. }
  77. if (textMsg) {
  78. [[WFCCIMService sharedWFCIMService] send:conversation content:textMsg success:^(long long messageUid, long long timestamp) {
  79. dispatch_async(dispatch_get_main_queue(), ^{
  80. if (forwardDone) {
  81. forwardDone(YES);
  82. }
  83. });
  84. } error:^(int error_code) {
  85. dispatch_async(dispatch_get_main_queue(), ^{
  86. if (forwardDone) {
  87. forwardDone(NO);
  88. }
  89. });
  90. }];
  91. } else {
  92. if (forwardDone) {
  93. forwardDone(YES);
  94. }
  95. }
  96. }
  97. }
  98. - (IBAction)cancelAction:(id)sender {
  99. [self hideView];
  100. }
  101. - (void)setConversation:(WFCCConversation *)conversation {
  102. [self updateUI];
  103. _conversation = conversation;
  104. NSString *name;
  105. NSString *portrait;
  106. if (conversation.type == Single_Type) {
  107. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:conversation.target refresh:NO];
  108. if (userInfo) {
  109. name = userInfo.displayName;
  110. portrait = userInfo.portrait;
  111. } else {
  112. name = [NSString stringWithFormat:@"%@<%@>", WFCString(@"User"), conversation.target];
  113. }
  114. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  115. } else if (conversation.type == Group_Type) {
  116. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:conversation.target refresh:NO];
  117. if (groupInfo) {
  118. name = groupInfo.name;
  119. portrait = groupInfo.portrait;
  120. } else {
  121. name = WFCString(@"GroupChat");
  122. }
  123. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  124. } else if (conversation.type == Channel_Type) {
  125. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:conversation.target refresh:NO];
  126. if (channelInfo) {
  127. name = channelInfo.name;
  128. portrait = channelInfo.portrait;
  129. } else {
  130. name = WFCString(@"Channel");
  131. }
  132. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"channel_default_portrait"]];
  133. }
  134. self.nameLabel.text = name;
  135. }
  136. - (void)setMessage:(WFCCMessage *)message {
  137. _message = message;
  138. if (message) {
  139. self.digestLabel.text = [message.content digest:message];
  140. }
  141. }
  142. - (void)setMessages:(NSArray<WFCCMessage *> *)messages {
  143. _messages = messages;
  144. if (messages.count) {
  145. self.digestLabel.text = [NSString stringWithFormat:@"[逐条转发]共%d条消息", messages.count];
  146. }
  147. }
  148. @end