Commit 7f9c590c authored by Kevin Reynaldo's avatar Kevin Reynaldo
Browse files

• Updated version to 0.2.2

• Updated TapTalk version to 1.7.0
parent 6546f376
......@@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "MeetTalk"
s.version = "0.2.1"
s.version = "0.2.2"
s.summary = "MeetTalk iOS SDK is an extension of TapTalk.io SDK, providing complete in-app chat SDK with the addition of voice and video call feature."
s.homepage = "https://taptalk.io"
......
......@@ -638,7 +638,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.1;
MARKETING_VERSION = 0.2.2;
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${SRCROOT}/MeetTalk/Supporting Files/MeetTalk.modulemap\"",
......@@ -714,7 +714,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.1;
MARKETING_VERSION = 0.2.2;
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${SRCROOT}/MeetTalk/Supporting Files/MeetTalk.modulemap\"",
......
......@@ -30,7 +30,7 @@ PODS:
- SDWebImage/Core (= 5.12.5)
- SDWebImage/Core (5.12.5)
- SocketRocket (0.6.0)
- TapTalk (1.6.2):
- TapTalk (1.7.0):
- AFNetworking (~> 4.0.0)
- GoogleMaps
- GooglePlaces
......@@ -74,7 +74,7 @@ SPEC CHECKSUMS:
Realm: 100df88a0faf5328f48477427e4b3e1a1598bae3
SDWebImage: 0905f1b7760fc8ac4198cae0036600d67478751e
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
TapTalk: 786093fbb49eff36c5cca15a0ac68744fdac58da
TapTalk: e20361c1779b2a199dc8fcce761b197336cf1350
ZSWTappableLabel: cff84c0a55e30f2141f7dac24e5903302a7e35ec
PODFILE CHECKSUM: d43f94260c87499244985a6517a8dd8b7e4a8f0a
......
../../../TapTalk/TapTalk/Managers/TAPAudioManager.h
\ No newline at end of file
../../../TapTalk/TapTalk/Views/UITableViewCells/TAPMyVoiceNoteBubbleTableViewCell.h
\ No newline at end of file
../../../TapTalk/TapTalk/Views/UITableViewCells/TAPYourVoiceNoteBubbleTableViewCell.h
\ No newline at end of file
../../../TapTalk/TapTalk/Managers/TAPAudioManager.h
\ No newline at end of file
../../../TapTalk/TapTalk/Views/UITableViewCells/TAPMyVoiceNoteBubbleTableViewCell.h
\ No newline at end of file
../../../TapTalk/TapTalk/Views/UITableViewCells/TAPYourVoiceNoteBubbleTableViewCell.h
\ No newline at end of file
......@@ -30,7 +30,7 @@ PODS:
- SDWebImage/Core (= 5.12.5)
- SDWebImage/Core (5.12.5)
- SocketRocket (0.6.0)
- TapTalk (1.6.2):
- TapTalk (1.7.0):
- AFNetworking (~> 4.0.0)
- GoogleMaps
- GooglePlaces
......@@ -74,7 +74,7 @@ SPEC CHECKSUMS:
Realm: 100df88a0faf5328f48477427e4b3e1a1598bae3
SDWebImage: 0905f1b7760fc8ac4198cae0036600d67478751e
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
TapTalk: 786093fbb49eff36c5cca15a0ac68744fdac58da
TapTalk: e20361c1779b2a199dc8fcce761b197336cf1350
ZSWTappableLabel: cff84c0a55e30f2141f7dac24e5903302a7e35ec
PODFILE CHECKSUM: d43f94260c87499244985a6517a8dd8b7e4a8f0a
......
This diff is collapsed.
......@@ -7,6 +7,7 @@
//
#import <UIKit/UIKit.h>
#import "TAPCountryModel.h"
NS_ASSUME_NONNULL_BEGIN
......
......@@ -7,6 +7,7 @@
//
#import <UIKit/UIKit.h>
#import "TAPMessageModel.h"
static const NSInteger kMaxCacheAge = 60 * 60 * 24 * 7; // 1 Week in Seconds
static const NSInteger kMaxDiskCountLimit = 1048576000; // 1GB in B
......
//
// TAPAudioManager.h
// TapTalk
//
// Created by TapTalk.io on 05/04/22.
//
#import <Foundation/Foundation.h>
@protocol TAPAudioManagerDelegate <NSObject>
@optional
- (void)finishAudioRecord:(NSURL *)url AVRecorder:(AVAudioRecorder *)avrecorder;
- (void)finishAudioPlay;
- (void)startAudioPlay:(NSTimeInterval)duration;
@end
@interface TAPAudioManager : NSObject
@property (weak, nonatomic) id<TAPAudioManagerDelegate> delegate;
+ (TAPAudioManager *)sharedManager;
- (BOOL)checkAudioPermissionAndSetup;
- (void)starRecordAudio;
- (void)stopRecordAudio;
- (void)playAudio:(NSString *)filePath;
- (NSTimeInterval)getPlayerCurrentTime;
- (BOOL)isPlaying;
- (void)pausePlayer;
- (void)resumePlayer;
- (void)stopPlayer;
- (void)setupPlayerAudio:(NSString *)filePath;
- (NSString *)getPlayerCurrentFilePath;
- (void)setPlayerCurrentTime:(NSTimeInterval)currentTime;
- (NSTimeInterval)getPlayerDuration;
@end
//
// TAPAudioManager.m
// TapTalk
//
// Created by TapTalk.io on 05/04/22.
//
#import "TAPAudioManager.h"
#import <AVFoundation/AVFoundation.h>
@interface TAPAudioManager ()<AVAudioRecorderDelegate, AVAudioPlayerDelegate>
@property (strong, nonatomic) AVAudioRecorder *recorder;
@property (strong, nonatomic) AVAudioPlayer *player;
@property (nonatomic) NSString *filePath;
@end
@implementation TAPAudioManager
#pragma mark - Lifecycle
+ (TAPAudioManager *)sharedManager {
static TAPAudioManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc] init];
});
return sharedManager;
}
- (id)init {
self = [super init];
if(self) {
}
return self;
}
#pragma mark - Delegate
#pragma mark - Audio Delegate
- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)avrecorder successfully:(BOOL)flag{
if ([self.delegate respondsToSelector:@selector(finishAudioRecord:AVRecorder:)]) {
[self.delegate finishAudioRecord:self.recorder.url AVRecorder:avrecorder];
}
}
- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[TAPDataManager setCurrentVoicePlayingFilePath:@""];
if ([self.delegate respondsToSelector:@selector(finishAudioPlay)]) {
[self.delegate finishAudioPlay];
}
}
#pragma mark - Custom Method
- (void)starRecordAudio {
if (self.player.playing) {
[self.player stop];
}
if (!self.recorder.recording) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[session setCategory :AVAudioSessionCategoryPlayAndRecord error:nil];
// Start recording
[self.recorder record];
}
else{
// Pause recording
[self.recorder pause];
}
}
- (void)stopRecordAudio {
[self.recorder stop];
}
- (void)stopPlayer {
[TAPDataManager setCurrentVoicePlayingFilePath:@""];
[self.player stop];
}
- (BOOL)isPlaying {
return self.player.isPlaying;
}
- (void)pausePlayer {
[TAPDataManager setCurrentVoicePlayingFilePath:@""];
[self.player pause];
}
- (void)resumePlayer {
[TAPDataManager setCurrentVoicePlayingFilePath:self.filePath];
if ([self.delegate respondsToSelector:@selector(startAudioPlay:)]) {
[self.delegate startAudioPlay:self.player.duration];
}
[self.player play];
}
- (void)playAudio:(NSString *)filePath {
self.filePath = filePath;
[TAPDataManager setCurrentVoicePlayingFilePath:filePath];
NSURL *url = [NSURL fileURLWithPath:filePath];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory :AVAudioSessionCategoryPlayback error:nil];
NSError *error;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url fileTypeHint:AVFileTypeMPEG4 error:&error];
[self.player setDelegate:self];
if ([self.delegate respondsToSelector:@selector(startAudioPlay:)]) {
[self.delegate startAudioPlay:self.player.duration];
}
[self.player play];
}
- (void)setupPlayerAudio:(NSString *)filePath {
self.filePath = filePath;
[TAPDataManager setCurrentVoicePlayingFilePath:filePath];
NSURL *url = [NSURL fileURLWithPath:filePath];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory :AVAudioSessionCategoryPlayback error:nil];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[self.player setDelegate:self];
}
- (void)setPlayerCurrentTime:(NSTimeInterval)currentTime{
self.player.currentTime = currentTime;
}
- (NSTimeInterval)getPlayerCurrentTime{
return self.player.currentTime;
}
- (NSTimeInterval)getPlayerDuration{
return self.player.duration;
}
- (NSString *)getPlayerCurrentFilePath{
return self.player.url.path;
}
- (BOOL)checkAudioPermissionAndSetup {
switch ([[AVAudioSession sharedInstance] recordPermission]) {
case AVAudioSessionRecordPermissionGranted:
[self setupAudioManager];
return YES;
break;
case AVAudioSessionRecordPermissionDenied:
return NO;
break;
case AVAudioSessionRecordPermissionUndetermined:
return NO;
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
NSLog(@"Permission granted");
}
else {
NSLog(@"Permission denied");
}
}];
break;
default:
return NO;
break;
}
}
- (void)setupAudioManager {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-d-H:m:s"];
NSDate *currentDate = [NSDate date];
NSString *dateString = [formatter stringFromDate:currentDate];
NSString *fileName = [NSString stringWithFormat:@"%@.m4a", dateString];
NSArray *pathComponents = [NSArray arrayWithObjects: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], fileName, nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *err = nil;
[session setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
// NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[session setActive:YES error:&err];
err = nil;
if(err){
// NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
// Initiate and prepare the recorder
self.recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
self.recorder.delegate = self;
self. recorder.meteringEnabled = YES;
[self.recorder prepareToRecord];
}
@end
......@@ -82,6 +82,12 @@ typedef NS_ENUM(NSInteger, TAPChatManagerQuoteActionType) {
- (void)sendVideoMessageWithPHAsset:(PHAsset *)asset caption:(NSString *)caption thumbnailImageData:(NSData *)thumbnailImageData room:(TAPRoomModel *)room successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage;
- (void)sendVideoMessageWithVideoAssetURL:(NSURL *)videoAssetURL caption:(NSString *)caption thumbnailImageData:(NSData *)thumbnailImageData;
- (void)sendVideoMessageWithVideoAssetURL:(NSURL *)videoAssetURL caption:(NSString *)caption thumbnailImageData:(NSData *)thumbnailImageData room:(TAPRoomModel *)room successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage;
- (void)sendVoiceMessageWithVoiceAssetURL:(TAPDataFileModel *)dataFile filePath:(NSString *)filePath fileURL:(NSURL *)fileURL;
- (void)sendVoiceMessageWithVoiceAssetURL:(TAPDataFileModel *)dataFile
filePath:(NSString *)filePath
fileURL:(NSURL *)fileURL
room:(TAPRoomModel *)room
successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage;
- (void)sendEmitFileMessage:(TAPMessageModel *)message;
- (void)sendProductMessage:(TAPMessageModel *)message;
- (void)sendLocationMessage:(CGFloat)latitude longitude:(CGFloat)longitude address:(NSString *)address;
......
......@@ -9,6 +9,7 @@
#import "TAPChatManager.h"
#import "TAPConnectionManager.h"
#import <TapTalk/Base64.h>
#import <CoreServices/UTType.h>
#define kCharacterLimit 4000
#define kMaximumRetryAttempt 10
......@@ -664,6 +665,143 @@
[[TAPChatManager sharedManager] notifySendMessageToDelegate:message];
}
- (void)sendVoiceMessageWithVoiceAssetURL:(TAPDataFileModel *)dataFile filePath:(NSString *)filePath fileURL:(NSURL *)fileURL {
TAPRoomModel *room = [TAPChatManager sharedManager].activeRoom;
[self sendVoiceMessageWithVoiceAssetURL:dataFile filePath:filePath fileURL:fileURL room:room successGenerateMessage:^(TAPMessageModel *message) {
}];
}
- (void)sendVoiceMessageWithVoiceAssetURL:(TAPDataFileModel *)dataFile
filePath:(NSString *)filePath
fileURL:(NSURL *)fileURL
room:(TAPRoomModel *)room
successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage {
/**
//Check if forward message exist, send forward message
[self checkAndSendForwardedMessageWithRoom:room];
caption = [TAPUtil nullToEmptyString:caption];
NSString *messageBodyCaption = [NSString string];
//Check contain caption or not
if ([caption isEqualToString:@""]) {
messageBodyCaption = NSLocalizedStringFromTableInBundle(@"🎥 Video", nil, [TAPUtil currentBundle], @"");
}
else {
messageBodyCaption = [NSString stringWithFormat:@"🎥 %@", caption];
}
AVAsset *videoAsset = [AVAsset assetWithURL:videoAssetURL]; //AS NOTE - get AVAsset via videoURLAsset
NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] init];
//AS NOTE - GET FILE SIZE
NSNumber *fileSizeValue = nil;
NSError *fileSizeError = nil;
NSNumber *videoAssetURLFileSize = nil;
[videoAssetURL getResourceValue:&fileSizeValue forKey:NSURLFileSizeKey
error:(&fileSizeError)];
if (fileSizeValue) {
NSLog(@"value for %@ is %@", videoAssetURL, fileSizeValue);
videoAssetURLFileSize = fileSizeValue;
}
else {
NSLog(@"error getting size for url %@ error was %@", videoAssetURL, fileSizeError);
videoAssetURLFileSize = [NSNumber numberWithFloat:0.0f];
}
Float64 voiceDurationFloat = floorf(CMTimeGetSeconds(videoAsset.duration));
Float64 voiceDurationInMilisecondsFloat = voiceDurationFloat * 1000; // in miliseconds
NSInteger voiceDurationInteger = (NSInteger)voiceDurationInMilisecondsFloat;
// NSURL *videoAssetURL = [(AVURLAsset *)videoAsset URL];
NSString *voiceAssetURLString = [videoAssetURL absoluteString];
voiceAssetURLString = [TAPUtil nullToEmptyString:voiceAssetURLString];
NSString *fileNameString = [voiceAssetURLString lastPathComponent];
fileNameString = [TAPUtil nullToEmptyString:fileNameString];
NSString *assetIdentifier = fileNameString;
assetIdentifier = [TAPUtil nullToEmptyString:assetIdentifier];
//Save asset to dictionary
[[TAPFileUploadManager sharedManager] saveToPendingUploadAssetDictionaryWithAVAsset:videoAsset];
//AS NOTE - GET MIME TYPE
NSString *mimeType = @"audio/m4a"; //AS NOTE - DEFAULT mimeType
NSString *extension = [videoAssetURL pathExtension];
NSString *exportedUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
NSString *mimeTypeUTI = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)exportedUTI, kUTTagClassMIMEType);
if (mimeTypeUTI != nil && ![mimeTypeUTI isEqualToString:@""]) {
mimeType = mimeTypeUTI;
}
[dataDictionary setObject:videoAssetURLFileSize forKey:@"size"];
[dataDictionary setObject:fileNameString forKey:@"fileName"];
[dataDictionary setObject:voiceAssetURLString forKey:@"filePath"];
[dataDictionary setObject:mimeType forKey:@"mediaType"];
// [dataDictionary setObject:asset forKey:@"asset"];
//[dataDictionary setObject:assetIdentifier forKey:@"assetIdentifier"];
//[dataDictionary setObject:voiceAssetURLString forKey:@"videoAssetURLString"];
//[dataDictionary setObject:caption forKey:@"caption"];
[dataDictionary setObject:[NSNumber numberWithInteger:voiceDurationInteger] forKey:@"duration"];
TAPMessageModel *message = [self createMessageModelWithRoom:room
body:messageBodyCaption
type:TAPChatMessageTypeVoice
messageData:dataDictionary];
successGenerateMessage(message);
//Add message to waiting upload file dictionary in ChatManager to prepare save to database
[[TAPChatManager sharedManager] addToWaitingUploadFileMessage:message];
[[TAPChatManager sharedManager] notifySendMessageToDelegate:message];
[[TAPFileUploadManager sharedManager] sendFileWithData:message];
*/
//Check if forward message exist, send forward message
[self checkAndSendForwardedMessageWithRoom:room];
NSString *fileName = dataFile.fileName;
fileName = [TAPUtil nullToEmptyString:fileName];
NSString *mediaType = dataFile.mediaType;
mediaType = [TAPUtil nullToEmptyString:mediaType];
NSNumber *size = dataFile.size;
NSString *messageBodyString = [NSString stringWithFormat:@"🎤 Voice"];
AVAsset *videoAsset = [AVAsset assetWithURL:fileURL]; //AS NOTE - get AVAsset via videoURLAsset
Float64 voiceDurationFloat = floorf(CMTimeGetSeconds(videoAsset.duration));
Float64 voiceDurationInMilisecondsFloat = voiceDurationFloat * 1000; // in miliseconds
NSInteger voiceDurationInteger = (NSInteger)voiceDurationInMilisecondsFloat;
NSNumber *voiceDurationNumber = [NSNumber numberWithInteger:voiceDurationInteger];
NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] init];
[dataDictionary setObject:filePath forKey:@"filePath"];
[dataDictionary setObject:fileName forKey:@"fileName"];
[dataDictionary setObject:mediaType forKey:@"mediaType"];
[dataDictionary setObject:size forKey:@"size"];
[dataDictionary setObject:voiceDurationNumber forKey:@"duration"];
TAPMessageModel *message = [self createMessageModelWithRoom:room
body:messageBodyString
type:TAPChatMessageTypeVoice
messageData:dataDictionary];
//Call block in TAPCoreMessageManager to handle things in TAPCore
successGenerateMessage(message);
//Add message to waiting upload file dictionary in ChatManager to prepare save to database
[[TAPChatManager sharedManager] addToWaitingUploadFileMessage:message];
[[TAPChatManager sharedManager] notifySendMessageToDelegate:message];
[[TAPFileUploadManager sharedManager] sendFileWithData:message];
}
- (void)sendLocationMessage:(CGFloat)latitude longitude:(CGFloat)longitude address:(NSString *)address {
TAPRoomModel *room = [TAPChatManager sharedManager].activeRoom;
[self sendLocationMessage:latitude longitude:longitude address:address room:room successGenerateMessage:^(TAPMessageModel *message) {
......
......@@ -148,6 +148,19 @@ NS_ASSUME_NONNULL_BEGIN
progress:(void (^)(TAPMessageModel *message, CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(TAPMessageModel * _Nullable message, NSError *error))failure;
- (void)sendVoiceMessageWithFileURI:(NSURL *)fileURI
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
progress:(void (^)(TAPMessageModel *message, CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(TAPMessageModel * _Nullable message, NSError *error))failure;
- (void)sendVoiceMessageWithFileURI:(NSURL *)fileURI
quotedMessage:(TAPMessageModel *)quotedMessage
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
progress:(void (^)(TAPMessageModel *message, CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(TAPMessageModel * _Nullable message, NSError *error))failure;
- (void)sendForwardedMessage:(TAPMessageModel *)messageToForward
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
......
......@@ -619,6 +619,8 @@
}];
}
- (void)sendFileMessageWithFileURI:(NSURL *)fileURI
quotedMessage:(TAPMessageModel *)quotedMessage
room:(TAPRoomModel *)room
......@@ -630,6 +632,78 @@
[self sendFileMessageWithFileURI:fileURI room:room start:start progress:progress success:success failure:failure];
}
- (void)sendVoiceMessageWithFileURI:(NSURL *)fileURI
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
progress:(void (^)(TAPMessageModel *message, CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(TAPMessageModel * _Nullable message, NSError *error))failure {
NSError *error = nil;
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateReadingItemAtURL:fileURI options:NSFileCoordinatorReadingImmediatelyAvailableMetadataOnly error:&error byAccessor:^(NSURL *newURL) {
NSError *err = nil;
NSNumber *fileSize;
if(![fileURI getPromisedItemResourceValue:&fileSize forKey:NSURLFileSizeKey error:&err]) {
NSString *errorMessage = NSLocalizedStringFromTableInBundle(@"Unable to get file data from URI", nil, [TAPUtil currentBundle], @"");
NSError *error = [[TAPCoreErrorManager sharedManager] generateLocalizedErrorWithErrorCode:90301 errorMessage:errorMessage];
failure(nil, error);
return;
} else {
TAPCoreConfigsModel *coreConfigs = [TAPDataManager getCoreConfigs];
NSNumber *maxFileSize = coreConfigs.chatMediaMaxFileSize;
NSInteger maxFileSizeInMB = [maxFileSize integerValue] / 1024 / 1024;
if ([fileSize doubleValue] > [maxFileSize doubleValue]) {
//File size is larger than max file size
NSString *errorMessage = [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"Selected file exceeded %ld MB maximum", nil, [TAPUtil currentBundle], @""), (long)maxFileSizeInMB];
NSError *error = [[TAPCoreErrorManager sharedManager] generateLocalizedErrorWithErrorCode:90302 errorMessage:errorMessage];
failure(nil, error);
return;
}
NSString *filePath = [fileURI absoluteString];
NSString *encodedFileName = [filePath lastPathComponent];
NSString *decodedFileName = [encodedFileName stringByRemovingPercentEncoding];
NSString *fileExtension = [fileURI pathExtension];
NSString *mimeType = [TAPUtil mimeTypeForFileWithExtension:fileExtension];
NSData *fileData = [NSData dataWithContentsOfURL:fileURI];
TAPDataFileModel *dataFile = [TAPDataFileModel new];
dataFile.fileName = decodedFileName;
dataFile.mediaType = mimeType;
dataFile.size = fileSize;
dataFile.fileData = fileData;
[[TAPChatManager sharedManager] sendVoiceMessageWithVoiceAssetURL:dataFile filePath:filePath fileURL:fileURI room:room successGenerateMessage:^(TAPMessageModel *message) {
NSMutableDictionary *blockTypeDictionary = [[NSMutableDictionary alloc] init];
void (^handlerProgress)(TAPMessageModel *, CGFloat, CGFloat) = [progress copy];
[blockTypeDictionary setObject:handlerProgress forKey:@"progressBlock"];
void (^handlerSuccess)(TAPMessageModel *) = [success copy];
[blockTypeDictionary setObject:handlerSuccess forKey:@"successBlock"];
void (^handlerFailure)(TAPMessageModel * _Nullable, NSError *) = [failure copy];
[blockTypeDictionary setObject:handlerFailure forKey:@"failureBlock"];
[self.blockDictionary setObject:blockTypeDictionary forKey:message.localID];
start(message);
}];
}
}];
}
- (void)sendVoiceMessageWithFileURI:(NSURL *)fileURI
quotedMessage:(TAPMessageModel *)quotedMessage
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
progress:(void (^)(TAPMessageModel *message, CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(TAPMessageModel * _Nullable message, NSError *error))failure {
[[TAPChatManager sharedManager] saveToQuotedMessage:quotedMessage userInfo:nil roomID:room.roomID];
[self sendVoiceMessageWithFileURI:fileURI room:room start:start progress:progress success:success failure:failure];
}
- (void)sendForwardedMessage:(TAPMessageModel *)messageToForward
room:(TAPRoomModel *)room
start:(void (^)(TAPMessageModel *message))start
......
......@@ -31,6 +31,8 @@
+ (TAPCoreConfigsModel *)getCoreConfigs;
+ (void)setUnreadRoomIDs:(NSArray *)roomIDs;
+ (NSArray *)getUnreadRoomIDs;
+ (void)setCurrentVoicePlayingFilePath:(NSString *)message;
+ (NSString *)getCurrentVoicePlayingFilePath;
+ (void)updateMessageToFailedWhenClosedInDatabase;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment