2
0

WFCUShareMessageView.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.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 = @"给朋友留言";
  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. [[WFCCIMService sharedWFCIMService] send:conversation content:self.message.content success:^(long long messageUid, long long timestamp) {
  41. if (textMsg) {
  42. [[WFCCIMService sharedWFCIMService] send:conversation content:textMsg success:^(long long messageUid, long long timestamp) {
  43. dispatch_async(dispatch_get_main_queue(), ^{
  44. if (forwardDone) {
  45. forwardDone(YES);
  46. }
  47. });
  48. } error:^(int error_code) {
  49. dispatch_async(dispatch_get_main_queue(), ^{
  50. if (forwardDone) {
  51. forwardDone(NO);
  52. }
  53. });
  54. }];
  55. } else {
  56. dispatch_async(dispatch_get_main_queue(), ^{
  57. if (forwardDone) {
  58. forwardDone(YES);
  59. }
  60. });
  61. }
  62. } error:^(int error_code) {
  63. dispatch_async(dispatch_get_main_queue(), ^{
  64. if (forwardDone) {
  65. forwardDone(NO);
  66. }
  67. });
  68. }];
  69. }
  70. - (IBAction)cancelAction:(id)sender {
  71. [self hideView];
  72. }
  73. - (void)setConversation:(WFCCConversation *)conversation {
  74. [self updateUI];
  75. _conversation = conversation;
  76. NSString *name;
  77. NSString *portrait;
  78. if (conversation.type == Single_Type) {
  79. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:conversation.target refresh:NO];
  80. if (userInfo) {
  81. name = userInfo.displayName;
  82. portrait = userInfo.portrait;
  83. } else {
  84. name = [NSString stringWithFormat:@"用户<%@>", conversation.target];
  85. }
  86. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:portrait] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  87. } else if (conversation.type == Group_Type) {
  88. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:conversation.target refresh:NO];
  89. if (groupInfo) {
  90. name = groupInfo.name;
  91. portrait = groupInfo.portrait;
  92. } else {
  93. name = [NSString stringWithFormat:@"群组<%@>", conversation.target];
  94. }
  95. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:portrait] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  96. } else if (conversation.type == Channel_Type) {
  97. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:conversation.target refresh:NO];
  98. if (channelInfo) {
  99. name = channelInfo.name;
  100. portrait = channelInfo.portrait;
  101. } else {
  102. name = [NSString stringWithFormat:@"群组<%@>", conversation.target];
  103. }
  104. [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:portrait] placeholderImage:[UIImage imageNamed:@"channel_default_portrait"]];
  105. }
  106. self.nameLabel.text = name;
  107. }
  108. - (void)setMessage:(WFCCMessage *)message {
  109. _message = message;
  110. self.digestLabel.text = [message.content digest];
  111. }
  112. @end