Skip to content

Commit 459c59f

Browse files
committed
better play sound
1 parent 2c5c575 commit 459c59f

File tree

1 file changed

+36
-173
lines changed

1 file changed

+36
-173
lines changed

Chat21UI/view/ChatMessagesVC.m

Lines changed: 36 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ -(void)setContainer {
293293
[containerTVC scrollToLastMessage:NO];
294294
}
295295

296-
297296
-(void)setupLabels {
298297
[self.sendButton setTitle:[ChatLocal translate:@"ChatSend"] forState:UIControlStateNormal];
299298
self.messageTextField.placeholder = [ChatLocal translate:@"digit message"];
@@ -329,44 +328,15 @@ -(void)setupConnectionStatus {
329328
[self offlineStatus];
330329
}
331330
}];
332-
// self.connectedHandle = [connectionStatusHandler observeEvent:ChatConnectionStatusEventConnected withCallback:^{
333-
// NSLog(@"connected");
334-
// [self connectedStatus];
335-
// }];
336-
// self.disconnectedHandle = [connectionStatusHandler observeEvent:ChatConnectionStatusEventDisconnected withCallback:^{
337-
// NSLog(@"not connected");
338-
// [self offlineStatus];
339-
// }];
340331
}
341-
342-
// // initial status UI
343-
// [self offlineStatus];
344-
//
345-
//// ChatManager *chat = [ChatManager getSharedInstance];
346-
// NSString *url = @"/.info/connected";
347-
// FIRDatabaseReference *rootRef = [[FIRDatabase database] reference];
348-
// self.connectedRef = [rootRef child:url];
349-
// self.connectedRefHandle = [self.connectedRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
350-
// if([snapshot.value boolValue]) {
351-
// NSLog(@"connected");
352-
// [self connectedStatus];
353-
// } else {
354-
// NSLog(@"not connected");
355-
// [self offlineStatus];
356-
// }
357-
// }];
358332
}
359333

360334
-(void)connectedStatus {
361335
self.usernameButton.hidden = NO;
362336
self.activityIndicator.hidden = YES;
363337
self.sendButton.enabled = YES;
364338
[self.activityIndicator stopAnimating];
365-
// if (self.group) {
366-
// self.statusLabel.text = [ChatUtil groupMembersAsStringForUI:self.group.members];
367-
// } else {
368339
[self onlineStatus];
369-
// }
370340
}
371341

372342
-(void)offlineStatus {
@@ -375,7 +345,6 @@ -(void)offlineStatus {
375345
self.sendButton.enabled = NO;
376346
[self.activityIndicator startAnimating];
377347
[self setSubTitle:[ChatLocal translate:@"ChatDisconnected"]];
378-
// self.statusLabel.text = NSLocalizedString(@"ChatDisconnected", nil);
379348
}
380349

381350
-(void)onlineStatus {
@@ -391,7 +360,6 @@ -(void)onlineStatus {
391360
last_online_status = [ChatLocal translate:@"offline"];
392361
}
393362
[self setSubTitle:last_online_status];
394-
// self.statusLabel.text = last_online_status;
395363
}
396364
}
397365

@@ -407,41 +375,8 @@ -(void)setupRecipientOnlineStatus {
407375
self.lastOnline = lastOnlineDate;
408376
[self onlineStatus];
409377
}];
410-
// [chatm.presenceHandler ]
411-
// // apps/{TENANT}/presence/{USERID}/connections
412-
// self.onlineRef = [ChatPresenceHandler onlineRefForUser:self.recipient.userId];
413-
// self.online_ref_handle = [self.onlineRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
414-
// if(snapshot.exists) {
415-
// NSLog(@"ONLINE: %@", snapshot);
416-
// self.online = YES;
417-
// [self onlineStatus];
418-
// } else {
419-
// self.online = NO;
420-
// [self onlineStatus];
421-
// }
422-
// }];
423-
424-
// LAST ONLINE
425-
426-
// apps/{TENANT}/presence/{USERID}/lastOnline
427-
// self.lastOnlineRef = [ChatPresenceHandler lastOnlineRefForUser:self.recipient.userId];
428-
// NSLog(@"last online ref: %@", self.lastOnlineRef);
429-
// self.last_online_ref_handle = [self.lastOnlineRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
430-
// [self snapshotDate:snapshot];
431-
// [self onlineStatus];
432-
// }];
433-
434-
435378
}
436379

437-
//-(void)snapshotDate:(FIRDataSnapshot *)snapshot {
438-
// if (!snapshot.exists) {
439-
// return;
440-
// }
441-
// self.lastOnline = [NSDate dateWithTimeIntervalSince1970:[snapshot.value longValue]/1000];
442-
//}
443-
444-
445380
// ************************
446381
// *** ONLINE / OFFLINE ***
447382
// ************************
@@ -514,23 +449,12 @@ -(void)chatTitleButtonPressed {
514449
}
515450

516451
-(void)goToProfile:(UIButton*)sender {
517-
//NSLog(@"goToProfile");
518-
// self.profileVC = (SHPHomeProfileTVC *)[self.applicationContext getVariable:@"profileVC"];
519452
NSLog(@"RECIPIENT FULL NAME: %@", self.recipient.fullname);
520453
if (self.group) {
521454
[self performSegueWithIdentifier:@"GroupInfo" sender:self];
522455
} else {
523456
if (![ChatUIManager getInstance].pushProfileCallback) {
524457
NSLog(@"Default profile view not implemented.");
525-
// self.profileSB = [UIStoryboard storyboardWithName:@"Profile" bundle:nil];
526-
// self.profileNC = [self.profileSB instantiateViewControllerWithIdentifier:@"navigationProfile"];
527-
// SHPHomeProfileTVC *profileVC = (SHPHomeProfileTVC *)[[self.profileNC viewControllers] objectAtIndex:0];
528-
// ChatUser *authorProfile = [[ChatUser alloc] init];
529-
// authorProfile.userId = self.recipient.userId;
530-
// authorProfile.fullname = self.recipient.fullname;
531-
// profileVC.otherUser = authorProfile;
532-
// NSLog(@"self.profileVC.otherUser %@ fullname: %@", profileVC.otherUser.userId, profileVC.otherUser.fullname);
533-
// [self.navigationController pushViewController:profileVC animated:YES];
534458
}
535459
else {
536460
ChatUser *user = [[ChatUser alloc] init];
@@ -559,7 +483,6 @@ -(void)initConversationHandler {
559483
[handler connect];
560484
[self subscribeForMessages:handler];
561485
self.conversationHandler = handler;
562-
// [self configureIfImGroupMember];
563486
}
564487

565488
-(void)configureIfImGroupMember {
@@ -574,19 +497,8 @@ -(void)configureIfImGroupMember {
574497
}
575498
}
576499

577-
//-(void)didFinishInitConversationHandler:(ChatConversationHandler *)handler error:(NSError *)error {
578-
// if (!error) {
579-
// NSLog(@"ChatConversationHandler Initialization finished with success.");
580-
// } else {
581-
// NSLog(@"ChatConversationHandler Initialization finished with error: %@", error);
582-
// }
583-
//}
584-
//---------------------------------------------------//
585-
//START FUNCTIONS
586-
//---------------------------------------------------//
587-
588500
//---------------------------------------------------//
589-
//INIZIO GESTIONE KEYBOARD
501+
// KEYBOARD HANDLING
590502
//---------------------------------------------------//
591503
-(void)backgroundTapToDismissKB:(BOOL)activate
592504
{
@@ -643,42 +555,6 @@ - (IBAction)addContentAction:(id)sender {
643555
// [self presentViewController:view animated:YES completion:nil];
644556
}
645557

646-
//-(void)openDropbox {
647-
// [[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypePreview
648-
// fromViewController:self completion:^(NSArray *results)
649-
// {
650-
// if ([results count]) {
651-
// // Process results from Chooser
652-
// DBChooserResult *r = results[0];
653-
// // NSLog(@"r.name %@", r.name);
654-
// // NSLog(@"r.link %@", r.link);
655-
// // NSLog(@"r.size %lld", r.size);
656-
// // NSLog(@"r.iconURL %@", r.iconURL);
657-
// NSDictionary *thumbs = r.thumbnails;
658-
// // if (thumbs) {
659-
// // NSArray*keys=[thumbs allKeys];
660-
// // for (NSObject *k in keys) {
661-
// // NSLog(@"r.thumb[%@]: %@", k, thumbs[k]);
662-
// // }
663-
// // NSLog(@"r.thumbs.64x64px %@", thumbs[@"64x64"]);
664-
// // NSLog(@"r.thumbs.200x200px %@", thumbs[@"200x200"]);
665-
// // NSLog(@"r.thumbs.640x480px %@", thumbs[@"640x480"]);
666-
// // } else {
667-
// // NSLog(@"No r.thumbs");
668-
// // }
669-
// [self sendDropboxMessage:r.name link:[r.link absoluteString] size:[NSNumber numberWithLongLong:r.size] iconURL:[r.iconURL absoluteString] thumbs:thumbs];
670-
// } else {
671-
// // User canceled the action
672-
// NSLog(@"Action canceled");
673-
// }
674-
// }];
675-
//}
676-
677-
//-(void)selectedDocument:(AlfrescoNode *)document {
678-
// NSLog(@"Document selected %@ url: %@", document.name, [DocNavigatorTVC documentURLByNode:document]);
679-
// [self sendAlfrescoMessage:document.name link:[DocNavigatorTVC documentURLByNode:document]];
680-
//}
681-
682558
-(void)dismissKeyboardFromTableView:(BOOL)activated {
683559
// NSLog(@"DISMISSING");
684560
[self backgroundTapToDismissKB:activated];
@@ -752,9 +628,7 @@ -(void)keyboardWasShown:(NSNotification*)aNotification
752628
[self.view layoutIfNeeded];
753629
[containerTVC scrollToLastMessage:YES];
754630
}];
755-
/////
756631
}
757-
758632
}
759633

760634
-(void) keyboardWillHide:(NSNotification*)aNotification
@@ -774,13 +648,11 @@ -(void) keyboardWillHide:(NSNotification*)aNotification
774648
self.layoutContraintBottomBarMessageBottomView.constant = 0;
775649
[self.view layoutIfNeeded];
776650
}];
777-
/////
778651
keyboardShow = NO;
779652
//END ANIMATION VIEW
780-
781653
}
782654
//---------------------------------------------------//
783-
//FINE GESTIONE KEYBOARD
655+
// END KEYBOARD HANDLING
784656
//---------------------------------------------------//
785657

786658
-(NSString*)formatDateMessage:(int)numberDaysBetweenChats message:(ChatMessage*)message row:(CGFloat)row {
@@ -815,9 +687,6 @@ - (IBAction)sendAction:(id)sender {
815687
}
816688

817689
-(void)sendMessage:(NSString *)text {
818-
// [DocChatUtil firebaseAuth:self.applicationContext.loggedUser.username password:self.applicationContext.loggedUser.password completion:^(NSError *error) {
819-
// NSLog(@"CONNECTED!!!!");
820-
// }];
821690
[self sendMessage:text attributes:nil];
822691
}
823692

@@ -842,38 +711,38 @@ -(void)sendMessage:(NSString *)text attributes:(NSDictionary *)attributes {
842711
}
843712
}
844713

845-
-(void)sendDropboxMessage:(NSString *)name link:(NSString *)link size:(NSNumber *)size iconURL:(NSString *)iconURL thumbs:(NSDictionary *)thumbs {
846-
847-
// check: if in a group, are you still a member?
848-
if (self.group) {
849-
if ([self.group isMember:self.me.userId]) {
850-
} else {
851-
[self hideBottomView:YES];
852-
[self.messageTextField resignFirstResponder];
853-
return;
854-
}
855-
}
856-
857-
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
858-
NSLog(@"dropbox.link: %@", link);
859-
NSLog(@"dropbox.size: %@", size);
860-
NSLog(@"dropbox.iconurl: %@", iconURL);
861-
862-
[attributes setValue:link forKey:@"link"];
863-
[attributes setValue:size forKey:@"size"];
864-
[attributes setValue:iconURL forKey:@"iconURL"];
865-
if (thumbs) {
866-
NSArray*keys=[thumbs allKeys];
867-
for (NSString *k in keys) {
868-
NSURL *turl = (NSURL *)thumbs[k];
869-
[attributes setValue:[turl absoluteString] forKey:k];
870-
}
871-
}
872-
NSString *text = [NSString stringWithFormat:@"%@ %@", name, link];
873-
[self.conversationHandler sendTextMessage:text attributes:attributes completion:^(ChatMessage *message, NSError *error) {
874-
NSLog(@"Dropbox message %@ successfully sent. ID: %@", message.text, message.messageId);
875-
}];
876-
}
714+
//-(void)sendDropboxMessage:(NSString *)name link:(NSString *)link size:(NSNumber *)size iconURL:(NSString *)iconURL thumbs:(NSDictionary *)thumbs {
715+
//
716+
// // check: if in a group, are you still a member?
717+
// if (self.group) {
718+
// if ([self.group isMember:self.me.userId]) {
719+
// } else {
720+
// [self hideBottomView:YES];
721+
// [self.messageTextField resignFirstResponder];
722+
// return;
723+
// }
724+
// }
725+
//
726+
// NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
727+
// NSLog(@"dropbox.link: %@", link);
728+
// NSLog(@"dropbox.size: %@", size);
729+
// NSLog(@"dropbox.iconurl: %@", iconURL);
730+
//
731+
// [attributes setValue:link forKey:@"link"];
732+
// [attributes setValue:size forKey:@"size"];
733+
// [attributes setValue:iconURL forKey:@"iconURL"];
734+
// if (thumbs) {
735+
// NSArray*keys=[thumbs allKeys];
736+
// for (NSString *k in keys) {
737+
// NSURL *turl = (NSURL *)thumbs[k];
738+
// [attributes setValue:[turl absoluteString] forKey:k];
739+
// }
740+
// }
741+
// NSString *text = [NSString stringWithFormat:@"%@ %@", name, link];
742+
// [self.conversationHandler sendTextMessage:text attributes:attributes completion:^(ChatMessage *message, NSError *error) {
743+
// NSLog(@"Dropbox message %@ successfully sent. ID: %@", message.text, message.messageId);
744+
// }];
745+
//}
877746

878747
-(void)messageUpdated:(ChatMessage *)message {
879748
[containerTVC reloadDataTableView];
@@ -884,17 +753,12 @@ -(void)messageDeleted:(ChatMessage *)message {
884753
}
885754

886755
-(void)messageReceived:(ChatMessage *)message {
887-
// SE MESSAGGIO.TIMESTAMP < "1 SEC FA" MOSTRA SUBITO. SE MESSAGGIO >= 1 SEC FA IMPOSTA UN TIMER. SE ARRIVA UN ALTRO MESSAGGIO DURANTE IL TIMER FAI RIPARTIRE IL TIMER. AFTER THE TIMER ENDS, RELOAD TABLE.
888-
889-
// double now = [[NSDate alloc] init].timeIntervalSince1970;
890-
// self.lastMessageArrivedTime = now;
891-
892-
if (!self.messagesArriving) {
893-
NSLog(@"MESSAGE ARRIVED. RENDERING.");
756+
if (!self.messagesArriving) { // self.messagesArriving = YES => bulk messages update
894757
[self startNewMessageTimer];
895758
self.messagesArriving = YES;
896759
// fist message always shown
897760
[self renderMessages];
761+
[self playSound];
898762
}
899763
else {
900764
NSLog(@"MESSAGES STILL ARRIVING, NOT RENDERING!");
@@ -921,7 +785,6 @@ -(void)endNewMessageTimer {
921785

922786
-(void)renderMessages {
923787
dispatch_async(dispatch_get_main_queue(), ^{
924-
[self playSound];
925788
[containerTVC reloadDataTableViewOnIndex:self.conversationHandler.messages.count - 1];
926789
[containerTVC scrollToLastMessage:NO];
927790
// [self scrollTo];

0 commit comments

Comments
 (0)