123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /************************************************************
- * * EaseMob CONFIDENTIAL
- * __________________
- * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
- *
- * NOTICE: All information contained herein is, and remains
- * the property of EaseMob Technologies.
- * Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained
- * from EaseMob Technologies.
- */
- #import "MessageReadManager.h"
- #import "EMCDDeviceManager.h"
- #import <SDWebImage/UIImageView+WebCache.h>
- static MessageReadManager *detailInstance = nil;
- @interface MessageReadManager()
- @property (strong, nonatomic) UIWindow *keyWindow;
- @property (strong, nonatomic) NSMutableArray *photos;
- @property (strong, nonatomic) UINavigationController *photoNavigationController;
- @property (strong, nonatomic) UIAlertView *textAlertView;
- @end
- @implementation MessageReadManager
- + (id)defaultManager
- {
- @synchronized(self){
- static dispatch_once_t pred;
- dispatch_once(&pred, ^{
- detailInstance = [[self alloc] init];
- });
- }
-
- return detailInstance;
- }
- #pragma mark - getter
- - (UIWindow *)keyWindow
- {
- if(_keyWindow == nil)
- {
- _keyWindow = [[UIApplication sharedApplication] keyWindow];
- }
-
- return _keyWindow;
- }
- - (NSMutableArray *)photos
- {
- if (_photos == nil) {
- _photos = [[NSMutableArray alloc] init];
- }
-
- return _photos;
- }
- - (UINavigationController *)photoNavigationController
- {
- if (_photoNavigationController == nil) {
- _photoNavigationController = [[UINavigationController alloc] init];
- _photoNavigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- }
-
- return _photoNavigationController;
- }
- #pragma mark - private
- #pragma mark - public
- - (void)showBrowserWithImages:(NSArray *)imageArray
- {
-
- }
- - (BOOL)prepareMessageAudioModel:(MessageModel *)messageModel
- updateViewCompletion:(void (^)(MessageModel *prevAudioModel, MessageModel *currentAudioModel))updateCompletion
- {
- BOOL isPrepare = NO;
-
- if(messageModel.type == EMMessageBodyTypeVoice)
- {
- MessageModel *prevAudioModel = self.audioMessageModel;
- MessageModel *currentAudioModel = messageModel;
- self.audioMessageModel = messageModel;
-
- BOOL isPlaying = messageModel.isPlaying;
- if (isPlaying) {
- messageModel.isPlaying = NO;
- self.audioMessageModel = nil;
- // prevAudioModel.isPlaying = NO;
- currentAudioModel = nil;
-
- [[EMCDDeviceManager sharedInstance] stopPlaying];
- }
- else {
- messageModel.isPlaying = YES;
- prevAudioModel.isPlaying = NO;
- isPrepare = YES;
-
- if (!messageModel.isPlayed) {
- messageModel.isPlayed = YES;
- EMMessage *chatMessage = messageModel.message;
- if (chatMessage.ext) {
- NSMutableDictionary *dict = [chatMessage.ext mutableCopy];
- if (![[dict objectForKey:@"isPlayed"] boolValue]) {
- [dict setObject:@YES forKey:@"isPlayed"];
- chatMessage.ext = dict;
- [[EMClient sharedClient].chatManager importMessages:@[chatMessage] completion:nil];
- }
- }
- }
- }
-
- if (updateCompletion) {
- updateCompletion(prevAudioModel, currentAudioModel);
- }
- }
-
- return isPrepare;
- }
- - (MessageModel *)stopMessageAudioModel
- {
- MessageModel *model = nil;
- if (self.audioMessageModel.type == EMMessageBodyTypeVoice) {
- if (self.audioMessageModel.isPlaying) {
- model = self.audioMessageModel;
- }
- self.audioMessageModel.isPlaying = NO;
- self.audioMessageModel = nil;
- }
-
- return model;
- }
- @end
|