Sin descripción

MessageReadManager.m 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /************************************************************
  2. * * EaseMob CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of EaseMob Technologies.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from EaseMob Technologies.
  11. */
  12. #import "MessageReadManager.h"
  13. #import "EMCDDeviceManager.h"
  14. #import <SDWebImage/UIImageView+WebCache.h>
  15. static MessageReadManager *detailInstance = nil;
  16. @interface MessageReadManager()
  17. @property (strong, nonatomic) UIWindow *keyWindow;
  18. @property (strong, nonatomic) NSMutableArray *photos;
  19. @property (strong, nonatomic) UINavigationController *photoNavigationController;
  20. @property (strong, nonatomic) UIAlertView *textAlertView;
  21. @end
  22. @implementation MessageReadManager
  23. + (id)defaultManager
  24. {
  25. @synchronized(self){
  26. static dispatch_once_t pred;
  27. dispatch_once(&pred, ^{
  28. detailInstance = [[self alloc] init];
  29. });
  30. }
  31. return detailInstance;
  32. }
  33. #pragma mark - getter
  34. - (UIWindow *)keyWindow
  35. {
  36. if(_keyWindow == nil)
  37. {
  38. _keyWindow = [[UIApplication sharedApplication] keyWindow];
  39. }
  40. return _keyWindow;
  41. }
  42. - (NSMutableArray *)photos
  43. {
  44. if (_photos == nil) {
  45. _photos = [[NSMutableArray alloc] init];
  46. }
  47. return _photos;
  48. }
  49. - (UINavigationController *)photoNavigationController
  50. {
  51. if (_photoNavigationController == nil) {
  52. _photoNavigationController = [[UINavigationController alloc] init];
  53. _photoNavigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  54. }
  55. return _photoNavigationController;
  56. }
  57. #pragma mark - private
  58. #pragma mark - public
  59. - (void)showBrowserWithImages:(NSArray *)imageArray
  60. {
  61. }
  62. - (BOOL)prepareMessageAudioModel:(MessageModel *)messageModel
  63. updateViewCompletion:(void (^)(MessageModel *prevAudioModel, MessageModel *currentAudioModel))updateCompletion
  64. {
  65. BOOL isPrepare = NO;
  66. if(messageModel.type == EMMessageBodyTypeVoice)
  67. {
  68. MessageModel *prevAudioModel = self.audioMessageModel;
  69. MessageModel *currentAudioModel = messageModel;
  70. self.audioMessageModel = messageModel;
  71. BOOL isPlaying = messageModel.isPlaying;
  72. if (isPlaying) {
  73. messageModel.isPlaying = NO;
  74. self.audioMessageModel = nil;
  75. // prevAudioModel.isPlaying = NO;
  76. currentAudioModel = nil;
  77. [[EMCDDeviceManager sharedInstance] stopPlaying];
  78. }
  79. else {
  80. messageModel.isPlaying = YES;
  81. prevAudioModel.isPlaying = NO;
  82. isPrepare = YES;
  83. if (!messageModel.isPlayed) {
  84. messageModel.isPlayed = YES;
  85. EMMessage *chatMessage = messageModel.message;
  86. if (chatMessage.ext) {
  87. NSMutableDictionary *dict = [chatMessage.ext mutableCopy];
  88. if (![[dict objectForKey:@"isPlayed"] boolValue]) {
  89. [dict setObject:@YES forKey:@"isPlayed"];
  90. chatMessage.ext = dict;
  91. [[EMClient sharedClient].chatManager importMessages:@[chatMessage] completion:nil];
  92. }
  93. }
  94. }
  95. }
  96. if (updateCompletion) {
  97. updateCompletion(prevAudioModel, currentAudioModel);
  98. }
  99. }
  100. return isPrepare;
  101. }
  102. - (MessageModel *)stopMessageAudioModel
  103. {
  104. MessageModel *model = nil;
  105. if (self.audioMessageModel.type == EMMessageBodyTypeVoice) {
  106. if (self.audioMessageModel.isPlaying) {
  107. model = self.audioMessageModel;
  108. }
  109. self.audioMessageModel.isPlaying = NO;
  110. self.audioMessageModel = nil;
  111. }
  112. return model;
  113. }
  114. @end