2010-09-30 22:52:12 -05:00
|
|
|
//
|
|
|
|
// MGMVoiceSMS.m
|
|
|
|
// VoiceMob
|
|
|
|
//
|
|
|
|
// Created by Mr. Gecko on 9/30/10.
|
2013-07-20 06:56:17 -05:00
|
|
|
// Copyright (c) 2011 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
|
2010-09-30 22:52:12 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "MGMVoiceSMS.h"
|
|
|
|
#import "MGMVoiceUser.h"
|
2010-10-02 22:00:01 -05:00
|
|
|
#import "MGMAccountController.h"
|
|
|
|
#import "MGMController.h"
|
|
|
|
#import "MGMSMSTextView.h"
|
|
|
|
#import "MGMInboxMessageView.h"
|
2010-09-30 22:52:12 -05:00
|
|
|
#import "MGMVMAddons.h"
|
2010-10-01 22:03:15 -05:00
|
|
|
#import <VoiceBase/VoiceBase.h>
|
2013-07-20 06:56:17 -05:00
|
|
|
#import <MGMUsers/MGMUsers.h>
|
|
|
|
|
|
|
|
NSString * const MGMSMSDB = @"sms.db";
|
2010-09-30 22:52:12 -05:00
|
|
|
|
2010-10-02 22:00:01 -05:00
|
|
|
NSString * const MGMMessageViewText = @"MGMMessageViewText";
|
|
|
|
NSString * const MGMKeyboardBounds = @"UIKeyboardBoundsUserInfoKey";
|
|
|
|
|
|
|
|
NSString * const MGMMessageCellIdentifier = @"MGMMessageCellIdentifier";
|
|
|
|
|
|
|
|
const float updateTimeInterval = 300.0;
|
|
|
|
|
2010-09-30 22:52:12 -05:00
|
|
|
@implementation MGMVoiceSMS
|
|
|
|
+ (id)tabWithVoiceUser:(MGMVoiceUser *)theVoiceUser {
|
|
|
|
return [[[self alloc] initWithVoiceUser:theVoiceUser] autorelease];
|
|
|
|
}
|
|
|
|
- (id)initWithVoiceUser:(MGMVoiceUser *)theVoiceUser {
|
2013-07-20 06:56:17 -05:00
|
|
|
if ((self = [super init])) {
|
2010-09-30 22:52:12 -05:00
|
|
|
voiceUser = theVoiceUser;
|
2010-10-02 22:00:01 -05:00
|
|
|
|
|
|
|
messageItems = [[NSArray arrayWithObjects:[[[UIBarButtonItem alloc] initWithTitle:@"Messages" style:UIBarButtonItemStyleBordered target:self action:@selector(showMessages:)] autorelease], [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL] autorelease], [[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:[voiceUser accountController] action:@selector(showSettings:)] autorelease], nil] retain];
|
|
|
|
|
2013-07-20 06:56:17 -05:00
|
|
|
messagesItems = [[NSArray arrayWithObjects:[[[UIBarButtonItem alloc] initWithTitle:@"Accounts" style:UIBarButtonItemStyleBordered target:[voiceUser accountController] action:@selector(showAccounts:)] autorelease], [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL] autorelease], [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMulti:)] autorelease], nil] retain];
|
|
|
|
|
2010-10-02 22:00:01 -05:00
|
|
|
SMSMessages = [NSMutableArray new];
|
|
|
|
currentSMSMessage = -1;
|
|
|
|
updateTimer = [[NSTimer scheduledTimerWithTimeInterval:updateTimeInterval target:self selector:@selector(update) userInfo:nil repeats:YES] retain];
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (void)dealloc {
|
2013-07-20 06:56:17 -05:00
|
|
|
#if releaseDebug
|
|
|
|
NSLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
2010-09-30 22:52:12 -05:00
|
|
|
[self releaseView];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messageItems release];
|
|
|
|
[messagesItems release];
|
|
|
|
[SMSMessages release];
|
|
|
|
[lastDate release];
|
|
|
|
[updateTimer invalidate];
|
|
|
|
[updateTimer release];
|
2010-09-30 22:52:12 -05:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MGMVoiceUser *)voiceUser {
|
|
|
|
return voiceUser;
|
|
|
|
}
|
2010-10-02 22:00:01 -05:00
|
|
|
- (MGMThemeManager *)themeManager {
|
|
|
|
return [[[voiceUser accountController] controller] themeManager];
|
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (NSString *)title {
|
|
|
|
if (currentSMSMessage!=-1)
|
|
|
|
return [[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMIPhoneNumber] readableNumber];
|
|
|
|
return [voiceUser title];
|
|
|
|
}
|
2010-09-30 22:52:12 -05:00
|
|
|
|
|
|
|
- (UIView *)view {
|
2010-10-01 22:03:15 -05:00
|
|
|
if (messageView==nil) {
|
2010-09-30 22:52:12 -05:00
|
|
|
if (![[NSBundle mainBundle] loadNibNamed:[[UIDevice currentDevice] appendDeviceSuffixToString:@"VoiceSMS"] owner:self options:nil]) {
|
|
|
|
NSLog(@"Unable to load Voice SMS");
|
|
|
|
} else {
|
2013-07-20 06:56:17 -05:00
|
|
|
if ([SMSMessages count]<=0 && [[NSFileManager defaultManager] fileExistsAtPath:[[[voiceUser user] supportPath] stringByAppendingPathComponent:MGMSMSDB]])
|
|
|
|
[SMSMessages addObjectsFromArray:[NSArray arrayWithContentsOfFile:[[[voiceUser user] supportPath] stringByAppendingPathComponent:MGMSMSDB]]];
|
|
|
|
|
2010-10-02 22:00:01 -05:00
|
|
|
[SMSTextCountField setHidden:YES];
|
|
|
|
[SMSView setDelegate:self];
|
|
|
|
if (currentSMSMessage!=-1) {
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
|
|
|
[[voiceUser accountController] setItems:messageItems animated:YES];
|
|
|
|
} else {
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setItems:messagesItems animated:YES];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
NSNotificationCenter *notifications = [NSNotificationCenter defaultCenter];
|
|
|
|
[notifications addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
[notifications addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
|
|
|
}
|
2010-10-02 22:00:01 -05:00
|
|
|
if (currentSMSMessage!=-1)
|
|
|
|
return messageView;
|
|
|
|
return messagesTable;
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
|
|
|
- (void)releaseView {
|
2013-07-20 06:56:17 -05:00
|
|
|
#if releaseDebug
|
|
|
|
NSLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
2010-10-02 22:00:01 -05:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messagesTable release];
|
|
|
|
messagesTable = nil;
|
2010-10-01 22:03:15 -05:00
|
|
|
if (messageView!=nil) {
|
2010-10-02 22:00:01 -05:00
|
|
|
if (currentSMSMessage!=-1) {
|
2013-07-20 06:56:17 -05:00
|
|
|
NSMutableDictionary *messageInfo = [NSMutableDictionary dictionaryWithDictionary:[SMSMessages objectAtIndex:currentSMSMessage]];
|
2010-10-02 22:00:01 -05:00
|
|
|
[messageInfo setObject:[SMSTextView text] forKey:MGMMessageViewText];
|
|
|
|
[SMSMessages replaceObjectAtIndex:currentSMSMessage withObject:messageInfo];
|
|
|
|
}
|
2010-10-01 22:03:15 -05:00
|
|
|
[messageView release];
|
|
|
|
messageView = nil;
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
[SMSView release];
|
|
|
|
SMSView = nil;
|
|
|
|
[SMSBottomView release];
|
|
|
|
SMSBottomView = nil;
|
|
|
|
[SMSTextView release];
|
|
|
|
SMSTextView = nil;
|
|
|
|
[SMSTextCountField release];
|
|
|
|
SMSTextCountField = nil;
|
|
|
|
[SMSSendButton release];
|
|
|
|
SMSSendButton = nil;
|
|
|
|
[SMSMessages writeToFile:[[[voiceUser user] supportPath] stringByAppendingPathComponent:MGMSMSDB] atomically:YES];
|
|
|
|
[SMSMessages removeAllObjects];
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
2010-10-02 22:00:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
- (void)update {
|
|
|
|
if ([SMSMessages count]>0)
|
|
|
|
[self checkSMSMessages];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)checkSMSMessages {
|
|
|
|
[[[voiceUser instance] inbox] getSMSForPage:1 delegate:self];
|
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (void)inbox:(MGMDelegateInfo *)theInfo didFailWithError:(NSError *)theError instance:(MGMInstance *)theInstance {
|
2010-10-02 22:00:01 -05:00
|
|
|
NSLog(@"SMS Error: %@ for instance: %@", theError, theInstance);
|
|
|
|
}
|
|
|
|
- (void)inboxGotInfo:(NSArray *)theMessages instance:(MGMInstance *)theInstance {
|
2013-07-20 06:56:17 -05:00
|
|
|
[updateTimer invalidate];
|
|
|
|
[updateTimer release];
|
|
|
|
updateTimer = [[NSTimer scheduledTimerWithTimeInterval:updateTimeInterval target:self selector:@selector(update) userInfo:nil repeats:YES] retain];
|
2010-10-02 22:00:01 -05:00
|
|
|
NSDate *newestDate = [NSDate distantPast];
|
|
|
|
BOOL newMessage = NO;
|
|
|
|
BOOL newTab = NO;
|
|
|
|
for (unsigned int i=0; i<[theMessages count]; i++) {
|
|
|
|
if (lastDate==nil || (![lastDate isEqual:[[theMessages objectAtIndex:i] objectForKey:MGMITime]] && [lastDate earlierDate:[[theMessages objectAtIndex:i] objectForKey:MGMITime]]==lastDate)) {
|
|
|
|
NSMutableDictionary *messageInfo = [NSMutableDictionary dictionaryWithDictionary:[theMessages objectAtIndex:i]];
|
|
|
|
[messageInfo setObject:[[theInstance contacts] nameForNumber:[messageInfo objectForKey:MGMIPhoneNumber]] forKey:MGMTInName];
|
|
|
|
[messageInfo setObject:[theInstance userNumber] forKey:MGMTUserNumber];
|
|
|
|
BOOL tab = NO;
|
|
|
|
for (unsigned int m=0; m<[SMSMessages count]; m++) {
|
|
|
|
if ([[[SMSMessages objectAtIndex:m] objectForKey:MGMIPhoneNumber] isEqual:[messageInfo objectForKey:MGMIPhoneNumber]] && ([[[SMSMessages objectAtIndex:m] objectForKey:MGMIID] isEqual:[messageInfo objectForKey:MGMIID]] || [[[SMSMessages objectAtIndex:m] objectForKey:MGMIID] isEqual:@""])) {
|
|
|
|
tab = YES;
|
|
|
|
if ([self updateMessage:m messageInfo:messageInfo])
|
|
|
|
newMessage = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (![[[theMessages objectAtIndex:i] objectForKey:MGMIRead] boolValue]) {
|
|
|
|
newMessage = YES;
|
|
|
|
if (!tab) {
|
|
|
|
newTab = YES;
|
|
|
|
[SMSMessages addObject:messageInfo];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ([newestDate earlierDate:[[theMessages objectAtIndex:i] objectForKey:MGMITime]]==newestDate)
|
|
|
|
newestDate = [[theMessages objectAtIndex:i] objectForKey:MGMITime];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newMessage) {
|
2013-07-20 06:56:17 -05:00
|
|
|
[lastDate release];
|
2010-10-02 22:00:01 -05:00
|
|
|
lastDate = [newestDate copy];
|
|
|
|
[[self themeManager] playSound:MGMTSSMSMessage];
|
|
|
|
if (currentSMSMessage==-1 && messagesTable!=nil)
|
|
|
|
[messagesTable reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (void)messageWithNumber:(NSString *)theNumber instance:(MGMInstance *)theInstance {
|
|
|
|
if (currentSMSMessage!=-1 && SMSTextView!=nil) {
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:currentSMSMessage] mutableCopy];
|
|
|
|
[messageInfo setObject:[SMSTextView text] forKey:MGMMessageViewText];
|
|
|
|
[SMSMessages replaceObjectAtIndex:currentSMSMessage withObject:messageInfo];
|
|
|
|
[messageInfo release];
|
|
|
|
[SMSTextView setText:@""];
|
|
|
|
[self textViewDidChange:SMSTextView];
|
|
|
|
currentSMSMessage = -1;
|
|
|
|
[SMSView loadHTMLString:@"" baseURL:nil];
|
|
|
|
}
|
|
|
|
[self view];
|
|
|
|
NSMutableDictionary *messageInfo = [NSMutableDictionary dictionary];
|
|
|
|
[messageInfo setObject:[NSArray array] forKey:MGMIMessages];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messageInfo setObject:[NSNumber numberWithInt:MGMISMSOutType] forKey:MGMIType];
|
2010-10-02 22:00:01 -05:00
|
|
|
[messageInfo setObject:[NSDate date] forKey:MGMITime];
|
|
|
|
[messageInfo setObject:[[theInstance contacts] nameForNumber:theNumber] forKey:MGMTInName];
|
|
|
|
[messageInfo setObject:theNumber forKey:MGMIPhoneNumber];
|
|
|
|
[messageInfo setObject:[theInstance userNumber] forKey:MGMTUserNumber];
|
|
|
|
[messageInfo setObject:@"" forKey:MGMIID];
|
|
|
|
[messageInfo setObject:[NSNumber numberWithBool:YES] forKey:MGMIRead];
|
|
|
|
BOOL window = NO;
|
|
|
|
for (unsigned int m=0; m<[SMSMessages count]; m++) {
|
|
|
|
if ([[[SMSMessages objectAtIndex:m] objectForKey:MGMIPhoneNumber] isEqual:[messageInfo objectForKey:MGMIPhoneNumber]] && [[[SMSMessages objectAtIndex:m] objectForKey:MGMIID] isEqual:@""]) {
|
|
|
|
window = YES;
|
|
|
|
currentSMSMessage = m;
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
2013-07-20 06:56:17 -05:00
|
|
|
UITabBarItem *thisTab = [[[voiceUser tabBar] items] objectAtIndex:MGMVUSMSTabIndex];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabBar] setSelectedItem:thisTab];
|
|
|
|
[voiceUser tabBar:[voiceUser tabBar] didSelectItem:thisTab];
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect viewFrame = [messageView frame];
|
|
|
|
viewFrame.size = [[voiceUser tabView] frame].size;
|
|
|
|
[messageView setFrame:viewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabView] addSubview:messageView];
|
|
|
|
[messagesTable removeFromSuperview];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!window) {
|
|
|
|
[SMSMessages addObject:messageInfo];
|
|
|
|
[messagesTable reloadData];
|
|
|
|
currentSMSMessage = [SMSMessages count]-1;
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
2013-07-20 06:56:17 -05:00
|
|
|
UITabBarItem *thisTab = [[[voiceUser tabBar] items] objectAtIndex:MGMVUSMSTabIndex];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabBar] setSelectedItem:thisTab];
|
|
|
|
[voiceUser tabBar:[voiceUser tabBar] didSelectItem:thisTab];
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect viewFrame = [messageView frame];
|
|
|
|
viewFrame.size = [[voiceUser tabView] frame].size;
|
|
|
|
[messageView setFrame:viewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabView] addSubview:messageView];
|
|
|
|
[messagesTable removeFromSuperview];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
|
|
|
[[voiceUser accountController] setItems:messageItems animated:YES];
|
|
|
|
}
|
|
|
|
- (void)messageWithData:(NSDictionary *)theData instance:(MGMInstance *)theInstance {
|
|
|
|
if (currentSMSMessage!=-1 && SMSTextView!=nil) {
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:currentSMSMessage] mutableCopy];
|
|
|
|
[messageInfo setObject:[SMSTextView text] forKey:MGMMessageViewText];
|
|
|
|
[SMSMessages replaceObjectAtIndex:currentSMSMessage withObject:messageInfo];
|
|
|
|
[messageInfo release];
|
|
|
|
[SMSTextView setText:@""];
|
|
|
|
[self textViewDidChange:SMSTextView];
|
|
|
|
currentSMSMessage = -1;
|
|
|
|
[SMSView loadHTMLString:@"" baseURL:nil];
|
|
|
|
}
|
|
|
|
[self view];
|
2013-07-20 06:56:17 -05:00
|
|
|
NSMutableDictionary *messageInfo = [[theData mutableCopy] autorelease];
|
2010-10-02 22:00:01 -05:00
|
|
|
[messageInfo setObject:[[theInstance contacts] nameForNumber:[messageInfo objectForKey:MGMIPhoneNumber]] forKey:MGMTInName];
|
|
|
|
[messageInfo setObject:[theInstance userNumber] forKey:MGMTUserNumber];
|
|
|
|
BOOL window = NO;
|
|
|
|
for (unsigned int m=0; m<[SMSMessages count]; m++) {
|
|
|
|
if ([[[SMSMessages objectAtIndex:m] objectForKey:MGMIPhoneNumber] isEqual:[messageInfo objectForKey:MGMIPhoneNumber]] && ([[[SMSMessages objectAtIndex:m] objectForKey:MGMIID] isEqual:[messageInfo objectForKey:MGMIID]] || [[[SMSMessages objectAtIndex:m] objectForKey:MGMIID] isEqual:@""])) {
|
|
|
|
window = YES;
|
|
|
|
[self updateMessage:m messageInfo:messageInfo];
|
|
|
|
currentSMSMessage = m;
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
2013-07-20 06:56:17 -05:00
|
|
|
UITabBarItem *thisTab = [[[voiceUser tabBar] items] objectAtIndex:MGMVUSMSTabIndex];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabBar] setSelectedItem:thisTab];
|
|
|
|
[voiceUser tabBar:[voiceUser tabBar] didSelectItem:thisTab];
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect viewFrame = [messageView frame];
|
|
|
|
viewFrame.size = [[voiceUser tabView] frame].size;
|
|
|
|
[messageView setFrame:viewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabView] addSubview:messageView];
|
|
|
|
[messagesTable removeFromSuperview];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!window) {
|
|
|
|
[SMSMessages addObject:messageInfo];
|
|
|
|
[messagesTable reloadData];
|
|
|
|
currentSMSMessage = [SMSMessages count]-1;
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
2013-07-20 06:56:17 -05:00
|
|
|
UITabBarItem *thisTab = [[[voiceUser tabBar] items] objectAtIndex:MGMVUSMSTabIndex];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabBar] setSelectedItem:thisTab];
|
|
|
|
[voiceUser tabBar:[voiceUser tabBar] didSelectItem:thisTab];
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect viewFrame = [messageView frame];
|
|
|
|
viewFrame.size = [[voiceUser tabView] frame].size;
|
|
|
|
[messageView setFrame:viewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
[[voiceUser tabView] addSubview:messageView];
|
|
|
|
[messagesTable removeFromSuperview];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
|
|
|
[[voiceUser accountController] setItems:messageItems animated:YES];
|
|
|
|
}
|
|
|
|
|
2013-07-20 06:56:17 -05:00
|
|
|
- (IBAction)showMulti:(id)sender {
|
|
|
|
[[[voiceUser accountController] controller] showMultiSMSWithInstance:[voiceUser instance]];
|
|
|
|
}
|
|
|
|
|
2010-10-02 22:00:01 -05:00
|
|
|
- (IBAction)showMessages:(id)sender {
|
|
|
|
if (sendingMessage) {
|
2013-07-20 06:56:17 -05:00
|
|
|
UIAlertView *alert = [[UIAlertView new] autorelease];
|
|
|
|
[alert setTitle:@"Sending a SMS Message"];
|
|
|
|
[alert setMessage:@"Your SMS Message is currently being sent, please wait for it to be sent."];
|
|
|
|
[alert addButtonWithTitle:MGMOkButtonTitle];
|
|
|
|
[alert show];
|
2010-10-02 22:00:01 -05:00
|
|
|
} else if (marking) {
|
|
|
|
|
|
|
|
} else if (![[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMIRead] boolValue]) {
|
|
|
|
marking = YES;
|
|
|
|
[[[voiceUser instance] inbox] markEntries:[NSArray arrayWithObject:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMIID]] read:YES delegate:self];
|
|
|
|
} else {
|
|
|
|
[messagesTable reloadData];
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect outViewFrame = [messageView frame];
|
2010-10-02 22:00:01 -05:00
|
|
|
CGRect inViewFrame = [messagesTable frame];
|
2013-07-20 06:56:17 -05:00
|
|
|
inViewFrame.size = outViewFrame.size;
|
2010-10-02 22:00:01 -05:00
|
|
|
inViewFrame.origin.x = -inViewFrame.size.width;
|
|
|
|
[messagesTable setFrame:inViewFrame];
|
|
|
|
[[voiceUser tabView] addSubview:messagesTable];
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:0.5];
|
|
|
|
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
|
|
|
|
[UIView setAnimationDelegate:self];
|
|
|
|
[UIView setAnimationDidStopSelector:@selector(messagesAnimationDidStop:finished:context:)];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messagesTable setFrame:outViewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
outViewFrame.origin.x = +outViewFrame.size.width;
|
|
|
|
[messageView setFrame:outViewFrame];
|
|
|
|
[UIView commitAnimations];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setItems:messagesItems animated:YES];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (void)mark:(MGMDelegateInfo *)theInfo didFailWithError:(NSError *)theError instance:(MGMInstance *)theInstance {
|
2010-10-02 22:00:01 -05:00
|
|
|
marking = NO;
|
2013-07-20 06:56:17 -05:00
|
|
|
UIAlertView *alert = [[UIAlertView new] autorelease];
|
|
|
|
[alert setTitle:@"Error marking as read"];
|
|
|
|
[alert setMessage:[theError localizedDescription]];
|
|
|
|
[alert addButtonWithTitle:MGMOkButtonTitle];
|
|
|
|
[alert show];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (void)markDidFinish:(MGMDelegateInfo *)theInfo instance:(MGMInstance *)theInstance {
|
2010-10-02 22:00:01 -05:00
|
|
|
marking = NO;
|
|
|
|
[self setMessage:currentSMSMessage read:YES];
|
|
|
|
[self showMessages:self];
|
|
|
|
}
|
|
|
|
- (void)messagesAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
|
|
|
|
[messageView removeFromSuperview];
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:currentSMSMessage] mutableCopy];
|
|
|
|
[messageInfo setObject:[SMSTextView text] forKey:MGMMessageViewText];
|
|
|
|
[SMSMessages replaceObjectAtIndex:currentSMSMessage withObject:messageInfo];
|
|
|
|
[messageInfo release];
|
|
|
|
[SMSTextView setText:@""];
|
|
|
|
[self textViewDidChange:SMSTextView];
|
|
|
|
currentSMSMessage = -1;
|
|
|
|
[SMSView loadHTMLString:@"" baseURL:nil];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return [SMSMessages count];
|
|
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
MGMInboxMessageView *cell = (MGMInboxMessageView *)[messagesTable dequeueReusableCellWithIdentifier:MGMMessageCellIdentifier];
|
|
|
|
if (cell==nil) {
|
|
|
|
cell = [[[MGMInboxMessageView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MGMMessageCellIdentifier] autorelease];
|
|
|
|
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
|
|
|
|
[cell setInstance:[voiceUser instance]];
|
|
|
|
}
|
|
|
|
[cell setMessageData:[SMSMessages objectAtIndex:[indexPath indexAtPosition:1]]];
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
- (BOOL)tableView:(UITableView *)theTableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)theTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return UITableViewCellEditingStyleDelete;
|
|
|
|
}
|
|
|
|
- (NSString *)tableView:(UITableView *)theTableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return @"Close";
|
|
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)theTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
[SMSMessages removeObjectAtIndex:[indexPath indexAtPosition:1]];
|
|
|
|
[messagesTable reloadData];
|
|
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
currentSMSMessage = [indexPath indexAtPosition:1];
|
|
|
|
if ([[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]!=nil)
|
|
|
|
[SMSTextView setText:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMMessageViewText]];
|
|
|
|
[self buildHTML];
|
|
|
|
[[messageItems objectAtIndex:0] setEnabled:NO];
|
|
|
|
[[voiceUser accountController] setItems:messageItems animated:YES];
|
|
|
|
|
2013-07-20 06:56:17 -05:00
|
|
|
CGRect outViewFrame = [messagesTable frame];
|
2010-10-02 22:00:01 -05:00
|
|
|
CGRect inViewFrame = [messageView frame];
|
2013-07-20 06:56:17 -05:00
|
|
|
inViewFrame.size = outViewFrame.size;
|
2010-10-02 22:00:01 -05:00
|
|
|
inViewFrame.origin.x = +inViewFrame.size.width;
|
|
|
|
[messageView setFrame:inViewFrame];
|
|
|
|
[[voiceUser tabView] addSubview:messageView];
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:0.5];
|
|
|
|
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
|
|
|
|
[UIView setAnimationDelegate:self];
|
|
|
|
[UIView setAnimationDidStopSelector:@selector(messageAnimationDidStop:finished:context:)];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messageView setFrame:outViewFrame];
|
2010-10-02 22:00:01 -05:00
|
|
|
outViewFrame.origin.x = -outViewFrame.size.width;
|
|
|
|
[messagesTable setFrame:outViewFrame];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
|
|
|
- (void)messageAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
|
|
|
|
[messagesTable removeFromSuperview];
|
|
|
|
[messagesTable deselectRowAtIndexPath:[messagesTable indexPathForSelectedRow] animated:NO];
|
|
|
|
[[messageItems objectAtIndex:0] setEnabled:YES];
|
2013-07-20 06:56:17 -05:00
|
|
|
[[voiceUser accountController] setTitle:[self title]];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMessage:(int)theMessage read:(BOOL)isRead {
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:theMessage] mutableCopy];
|
|
|
|
[messageInfo setObject:[NSNumber numberWithBool:isRead] forKey:MGMIRead];
|
|
|
|
[SMSMessages replaceObjectAtIndex:theMessage withObject:messageInfo];
|
|
|
|
[messageInfo release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)updateMessage:(int)theMessage messageInfo:(NSDictionary *)theMessageInfo {
|
|
|
|
BOOL newIncomingMessages = NO;
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:theMessage] mutableCopy];
|
|
|
|
if (![[theMessageInfo objectForKey:MGMITime] isEqual:[messageInfo objectForKey:MGMITime]]) {
|
|
|
|
NSMutableDictionary *inMessageInfo = [theMessageInfo mutableCopy];
|
|
|
|
[inMessageInfo removeObjectForKey:MGMIMessages];
|
|
|
|
[messageInfo addEntriesFromDictionary:inMessageInfo];
|
|
|
|
[inMessageInfo release];
|
|
|
|
[self setMessage:theMessage read:[[messageInfo objectForKey:MGMIRead] boolValue]];
|
|
|
|
NSArray *theMessages = [theMessageInfo objectForKey:MGMIMessages];
|
|
|
|
|
|
|
|
if (theMessage!=currentSMSMessage) {
|
|
|
|
[messageInfo setObject:theMessages forKey:MGMIMessages];
|
|
|
|
[SMSMessages replaceObjectAtIndex:theMessage withObject:messageInfo];
|
|
|
|
} else {
|
|
|
|
NSMutableArray *messages = [[messageInfo objectForKey:MGMIMessages] mutableCopy];
|
|
|
|
BOOL rebuild = [[[[self themeManager] variant] objectForKey:MGMTRebuild] boolValue];
|
|
|
|
BOOL newMessages = NO;
|
|
|
|
for (unsigned int i=[messages count]; i<[theMessages count]; i++) {
|
|
|
|
newMessages = YES;
|
|
|
|
[messages addObject:[theMessages objectAtIndex:i]];
|
|
|
|
|
|
|
|
if (![[[theMessages objectAtIndex:i] objectForKey:MGMIYou] boolValue])
|
|
|
|
newIncomingMessages = YES;
|
|
|
|
if (!rebuild) {
|
|
|
|
[messageInfo setObject:messages forKey:MGMIMessages];
|
|
|
|
[self addMessage:[messages lastObject] withInfo:messageInfo];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rebuild)
|
|
|
|
[messageInfo setObject:messages forKey:MGMIMessages];
|
|
|
|
[messages release];
|
|
|
|
|
|
|
|
[SMSMessages replaceObjectAtIndex:theMessage withObject:messageInfo];
|
|
|
|
|
|
|
|
if (newMessages && rebuild) {
|
|
|
|
NSLog(@"Rebuilding HTML!");
|
|
|
|
[self buildHTML];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[messageInfo release];
|
|
|
|
return newIncomingMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyboardWillShow:(NSNotification *)theNotification {
|
|
|
|
CGSize keyboardSize = CGSizeZero;
|
|
|
|
if ([[theNotification userInfo] objectForKey:MGMKeyboardBounds]!=nil)
|
|
|
|
keyboardSize = [[[theNotification userInfo] objectForKey:MGMKeyboardBounds] CGRectValue].size;
|
|
|
|
else
|
|
|
|
keyboardSize = [[[theNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
|
|
|
|
keyboardSize.height -= 49.0;
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:0.1358];
|
|
|
|
[UIView setAnimationDelay:0.1642];
|
|
|
|
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
|
|
|
|
CGRect SMSBottomFrame = [SMSBottomView frame];
|
|
|
|
SMSBottomFrame.origin.y -= keyboardSize.height;
|
|
|
|
[SMSBottomView setFrame:SMSBottomFrame];
|
|
|
|
CGRect SMSViewFrame = [SMSView frame];
|
|
|
|
SMSViewFrame.size.height -= keyboardSize.height;
|
|
|
|
SMSViewStartFrame = SMSViewFrame;
|
|
|
|
[SMSView setFrame:SMSViewFrame];
|
|
|
|
UIScrollView *SMSScrollView = [[SMSView subviews] objectAtIndex:0];
|
|
|
|
[SMSScrollView setContentInset:UIEdgeInsetsZero];
|
|
|
|
[SMSScrollView setScrollIndicatorInsets:UIEdgeInsetsZero];
|
|
|
|
[SMSScrollView scrollRectToVisible:CGRectMake(0, [SMSScrollView contentSize].height-44, 320, 44) animated:YES];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
|
|
|
- (void)textViewDidChange:(UITextView *)textView {
|
|
|
|
CGFloat newHeight = [SMSTextView contentSize].height+3;
|
|
|
|
if ([SMSTextView contentSize].height<40.0 || [SMSTextView contentSize].height<=55.0)
|
|
|
|
newHeight = 40.0;
|
|
|
|
if (newHeight>124.0)
|
|
|
|
newHeight = 124.0;
|
|
|
|
if (newHeight!=[SMSBottomView frame].size.height) {
|
|
|
|
if (newHeight==40.0)
|
|
|
|
[SMSTextCountField setHidden:YES];
|
|
|
|
else
|
|
|
|
[SMSTextCountField setHidden:NO];
|
|
|
|
CGRect SMSBottomFrame = [SMSBottomView frame];
|
|
|
|
CGFloat heightDifference = SMSBottomFrame.size.height-newHeight;
|
|
|
|
SMSBottomFrame.origin.y += heightDifference;
|
|
|
|
SMSBottomFrame.size.height = newHeight;
|
|
|
|
[SMSBottomView setFrame:SMSBottomFrame];
|
|
|
|
CGRect SMSViewFrame = [SMSView frame];
|
|
|
|
SMSViewFrame.size.height = ([messageView frame].size.height-SMSBottomFrame.size.height)-(heightDifference<0 ? 166 : 167);
|
|
|
|
[SMSView setFrame:SMSViewFrame];
|
|
|
|
UIScrollView *SMSScrollView = [[SMSView subviews] objectAtIndex:0];
|
|
|
|
[SMSScrollView setContentInset:UIEdgeInsetsZero];
|
|
|
|
[SMSScrollView setScrollIndicatorInsets:UIEdgeInsetsZero];
|
2013-07-20 06:56:17 -05:00
|
|
|
if (heightDifference<0)
|
2010-10-02 22:00:01 -05:00
|
|
|
[SMSScrollView scrollRectToVisible:CGRectMake(0, [SMSScrollView contentSize].height-44, 320, 44) animated:NO];
|
|
|
|
}
|
|
|
|
if (![SMSTextCountField isHidden])
|
|
|
|
[SMSTextCountField setText:[[NSNumber numberWithInt:160-[[SMSTextView text] length]] stringValue]];
|
|
|
|
}
|
|
|
|
- (void)keyboardWillHide:(NSNotification *)theNotification {
|
|
|
|
CGSize keyboardSize = CGSizeZero;
|
|
|
|
if ([[theNotification userInfo] objectForKey:MGMKeyboardBounds]!=nil)
|
|
|
|
keyboardSize = [[[theNotification userInfo] objectForKey:MGMKeyboardBounds] CGRectValue].size;
|
|
|
|
else
|
|
|
|
keyboardSize = [[[theNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
|
|
|
|
keyboardSize.height -= 49.0;
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:0.256];
|
|
|
|
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
|
|
|
|
CGRect SMSBottomFrame = [SMSBottomView frame];
|
|
|
|
SMSBottomFrame.origin.y += keyboardSize.height;
|
|
|
|
[SMSBottomView setFrame:SMSBottomFrame];
|
|
|
|
CGRect SMSViewFrame = [SMSView frame];
|
|
|
|
CGFloat SMSViewHeightDifference = SMSViewFrame.size.height-SMSViewStartFrame.size.height;
|
|
|
|
SMSViewFrame.size.height += keyboardSize.height;
|
|
|
|
[SMSView setFrame:SMSViewFrame];
|
|
|
|
UIScrollView *SMSScrollView = [[SMSView subviews] objectAtIndex:0];
|
|
|
|
UIEdgeInsets SMSScrollContentInset = [SMSScrollView contentInset];
|
2013-07-20 06:56:17 -05:00
|
|
|
//SMSScrollContentInset.bottom -= (keyboardSize.height-SMSBottomFrame.size.height)-SMSViewHeightDifference;
|
2010-10-02 22:00:01 -05:00
|
|
|
[SMSScrollView setContentInset:SMSScrollContentInset];
|
|
|
|
UIEdgeInsets SMSScrollInset = [SMSScrollView scrollIndicatorInsets];
|
|
|
|
SMSScrollInset.bottom += (keyboardSize.height-SMSBottomFrame.size.height)-SMSViewHeightDifference;
|
|
|
|
[SMSScrollView setScrollIndicatorInsets:SMSScrollContentInset];
|
|
|
|
[SMSScrollView scrollRectToVisible:CGRectMake(0, [SMSScrollView contentSize].height-44, 320, 44) animated:YES];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)buildHTML {
|
|
|
|
NSDictionary *messageInfo = [SMSMessages objectAtIndex:currentSMSMessage];
|
|
|
|
NSString *yPhotoPath = [[[voiceUser instance] contacts] cachedPhotoForNumber:[messageInfo objectForKey:MGMTUserNumber]];
|
|
|
|
if (yPhotoPath==nil)
|
|
|
|
yPhotoPath = [[[self themeManager] outgoingIconPath] filePath];
|
|
|
|
NSString *tPhotoPath = [[[voiceUser instance] contacts] cachedPhotoForNumber:[messageInfo objectForKey:MGMIPhoneNumber]];
|
|
|
|
if (tPhotoPath==nil)
|
|
|
|
tPhotoPath = [[[self themeManager] incomingIconPath] filePath];
|
|
|
|
NSArray *messages = [messageInfo objectForKey:MGMIMessages];
|
|
|
|
NSMutableArray *messageArray = [NSMutableArray array];
|
|
|
|
for (unsigned int i=0; i<[messages count]; i++) {
|
|
|
|
NSMutableDictionary *message = [NSMutableDictionary dictionaryWithDictionary:[messages objectAtIndex:i]];
|
|
|
|
[message setObject:[[NSNumber numberWithInt:i] stringValue] forKey:MGMIID];
|
|
|
|
if ([[message objectForKey:MGMIYou] boolValue]) {
|
|
|
|
[message setObject:yPhotoPath forKey:MGMTPhoto];
|
|
|
|
[message setObject:NSFullUserName() forKey:MGMTName];
|
|
|
|
[message setObject:[messageInfo objectForKey:MGMTUserNumber] forKey:MGMIPhoneNumber];
|
|
|
|
} else {
|
|
|
|
[message setObject:tPhotoPath forKey:MGMTPhoto];
|
|
|
|
[message setObject:[messageInfo objectForKey:MGMTInName] forKey:MGMTName];
|
|
|
|
[message setObject:[messageInfo objectForKey:MGMIPhoneNumber] forKey:MGMIPhoneNumber];
|
|
|
|
}
|
|
|
|
[messageArray addObject:message];
|
2013-07-20 06:56:17 -05:00
|
|
|
}
|
|
|
|
NSString *html = [[self themeManager] buildHTMLWithMessages:messageArray messageInfo:messageInfo];
|
2010-10-02 22:00:01 -05:00
|
|
|
[SMSView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[self themeManager] currentThemeVariantPath]]];
|
|
|
|
}
|
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
|
|
|
[SMSView stringByEvaluatingJavaScriptFromString:@"scrollToBottom();"];
|
|
|
|
}
|
|
|
|
- (void)addMessage:(NSDictionary *)theMessage withInfo:(NSMutableDictionary *)theMessageInfo {
|
2013-07-20 06:56:17 -05:00
|
|
|
NSArray *messages = [theMessageInfo objectForKey:MGMIMessages];
|
2010-10-02 22:00:01 -05:00
|
|
|
NSString *yPhotoPath = [[[voiceUser instance] contacts] cachedPhotoForNumber:[theMessageInfo objectForKey:MGMTUserNumber]];
|
|
|
|
if (yPhotoPath==nil)
|
|
|
|
yPhotoPath = [[[self themeManager] outgoingIconPath] filePath];
|
|
|
|
NSString *tPhotoPath = [[[voiceUser instance] contacts] cachedPhotoForNumber:[theMessageInfo objectForKey:MGMIPhoneNumber]];
|
|
|
|
if (tPhotoPath==nil)
|
|
|
|
tPhotoPath = [[[self themeManager] incomingIconPath] filePath];
|
|
|
|
NSMutableDictionary *message = [NSMutableDictionary dictionaryWithDictionary:theMessage];
|
|
|
|
[message setObject:[[NSNumber numberWithInt:[messages count]-1] stringValue] forKey:MGMIID];
|
2013-07-20 06:56:17 -05:00
|
|
|
NSMutableArray *classes = [NSMutableArray array];
|
2010-10-02 22:00:01 -05:00
|
|
|
int type = 1;
|
|
|
|
if ([[message objectForKey:MGMIYou] boolValue]) {
|
2013-07-20 06:56:17 -05:00
|
|
|
[classes addObject:MGMTCOutgoing];
|
2010-10-02 22:00:01 -05:00
|
|
|
type = (([[message objectForKey:MGMIID] intValue]==0 || ![[[messages objectAtIndex:[[message objectForKey:MGMIID] intValue]-1] objectForKey:MGMIYou] boolValue]) ? 1 : 2);
|
2013-07-20 06:56:17 -05:00
|
|
|
if (type==2)
|
|
|
|
[classes addObject:MGMTCNext];
|
2010-10-02 22:00:01 -05:00
|
|
|
[message setObject:yPhotoPath forKey:MGMTPhoto];
|
|
|
|
[message setObject:NSFullUserName() forKey:MGMTName];
|
|
|
|
[message setObject:[theMessageInfo objectForKey:MGMTUserNumber] forKey:MGMIPhoneNumber];
|
|
|
|
} else {
|
2013-07-20 06:56:17 -05:00
|
|
|
[classes addObject:MGMTCIncoming];
|
2010-10-02 22:00:01 -05:00
|
|
|
type = (([[message objectForKey:MGMIID] intValue]==0 || [[[messages objectAtIndex:[[message objectForKey:MGMIID] intValue]-1] objectForKey:MGMIYou] boolValue]) ? 3 : 4);
|
2013-07-20 06:56:17 -05:00
|
|
|
if (type==4)
|
|
|
|
[classes addObject:MGMTCNext];
|
2010-10-02 22:00:01 -05:00
|
|
|
[message setObject:tPhotoPath forKey:MGMTPhoto];
|
|
|
|
[message setObject:[theMessageInfo objectForKey:MGMTInName] forKey:MGMTName];
|
|
|
|
[message setObject:[theMessageInfo objectForKey:MGMIPhoneNumber] forKey:MGMIPhoneNumber];
|
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
[classes addObject:MGMTCMessage];
|
|
|
|
if (![[NSUserDefaults standardUserDefaults] boolForKey:MGMTShowIcons])
|
|
|
|
[classes addObject:MGMTCHideIcons];
|
2010-10-02 22:00:01 -05:00
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter new] autorelease];
|
|
|
|
[formatter setDateFormat:[[[self themeManager] variant] objectForKey:MGMTDate]];
|
2013-07-20 06:56:17 -05:00
|
|
|
[SMSView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"newMessage('%@', '%@', '%@', %@, '%@', '%@', '%@', %d, '%@');", [[[self themeManager] htmlTextFromMessage:message] javascriptEscape], [[message objectForKey:MGMTPhoto] javascriptEscape], [[message objectForKey:MGMITime] javascriptEscape], [message objectForKey:MGMIID], [[message objectForKey:MGMTName] javascriptEscape], [[[message objectForKey:MGMIPhoneNumber] readableNumber] javascriptEscape], [formatter stringFromDate:[theMessageInfo objectForKey:MGMITime]], type, [classes componentsJoinedByString:@" "]]];
|
2010-10-02 22:00:01 -05:00
|
|
|
[SMSView stringByEvaluatingJavaScriptFromString:@"scrollToBottom();"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)sendMessage:(id)sender {
|
|
|
|
if ([[SMSTextView text] isEqual:@""])
|
|
|
|
return;
|
|
|
|
sendingMessage = YES;
|
|
|
|
[SMSSendButton setEnabled:NO];
|
|
|
|
[[[voiceUser instance] inbox] sendMessage:[SMSTextView text] phoneNumbers:[NSArray arrayWithObject:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMIPhoneNumber]] smsID:[[SMSMessages objectAtIndex:currentSMSMessage] objectForKey:MGMIID] delegate:self];
|
|
|
|
[SMSTextView setText:@""];
|
|
|
|
[self textViewDidChange:SMSTextView];
|
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (void)message:(MGMDelegateInfo *)theInfo didFailWithError:(NSError *)theError instance:(MGMInstance *)theInstance {
|
2010-10-02 22:00:01 -05:00
|
|
|
sendingMessage = NO;
|
|
|
|
[SMSSendButton setEnabled:YES];
|
2013-07-20 06:56:17 -05:00
|
|
|
[SMSTextView setText:[[theInfo message] stringByAppendingFormat:@" %@", [SMSTextView text]]];
|
2010-10-02 22:00:01 -05:00
|
|
|
[self textViewDidChange:SMSTextView];
|
|
|
|
[SMSTextView becomeFirstResponder];
|
2013-07-20 06:56:17 -05:00
|
|
|
UIAlertView *alert = [[UIAlertView new] autorelease];
|
|
|
|
[alert setTitle:@"Error sending a SMS Message"];
|
|
|
|
[alert setMessage:[theError localizedDescription]];
|
|
|
|
[alert addButtonWithTitle:MGMOkButtonTitle];
|
|
|
|
[alert show];
|
2010-10-02 22:00:01 -05:00
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
- (void)messageDidFinish:(MGMDelegateInfo *)theInfo instance:(MGMInstance *)theInstance {
|
2010-10-02 22:00:01 -05:00
|
|
|
sendingMessage = NO;
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter new] autorelease];
|
|
|
|
[formatter setDateFormat:@"h:mm a"];
|
|
|
|
NSMutableDictionary *messageInfo = [[SMSMessages objectAtIndex:currentSMSMessage] mutableCopy];
|
|
|
|
NSMutableArray *messages = [[messageInfo objectForKey:MGMIMessages] mutableCopy];
|
2013-07-20 06:56:17 -05:00
|
|
|
NSDictionary *message = [NSDictionary dictionaryWithObjectsAndKeys:[theInfo message], MGMIText, [formatter stringFromDate:[NSDate date]], MGMITime, [NSNumber numberWithBool:YES], MGMIYou, nil];
|
2010-10-02 22:00:01 -05:00
|
|
|
[messages addObject:message];
|
|
|
|
[messageInfo setObject:messages forKey:MGMIMessages];
|
|
|
|
[messageInfo setObject:[NSDate date] forKey:MGMITime];
|
|
|
|
[SMSMessages replaceObjectAtIndex:currentSMSMessage withObject:messageInfo];
|
|
|
|
if ([[[[self themeManager] variant] objectForKey:MGMTRebuild] boolValue]) {
|
|
|
|
[self buildHTML];
|
|
|
|
} else {
|
|
|
|
[self addMessage:message withInfo:messageInfo];
|
|
|
|
}
|
|
|
|
[messages release];
|
|
|
|
[messageInfo release];
|
|
|
|
[SMSSendButton setEnabled:YES];
|
|
|
|
[SMSTextView becomeFirstResponder];
|
|
|
|
[self setMessage:currentSMSMessage read:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)shouldClose {
|
|
|
|
return (!sendingMessage);
|
|
|
|
}
|
2010-09-30 22:52:12 -05:00
|
|
|
@end
|