From 664064316b6c9c4602f45ec98d532cbc38ea92ab Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Sat, 9 Nov 2019 17:20:34 -0500
Subject: [PATCH] conversations UI: fixes

- display time
- generated messages
- record file

Change-Id: I3bbbfd3143b3e3d8f645ce883c53f440772df358
---
 src/MessagesVC.mm   | 14 +++++---------
 src/RecordFileVC.mm |  5 -----
 src/SmartViewVC.mm  | 29 ++++++++++++++++++-----------
 3 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/MessagesVC.mm b/src/MessagesVC.mm
index 4250b1f3..e1df9cdf 100644
--- a/src/MessagesVC.mm
+++ b/src/MessagesVC.mm
@@ -312,7 +312,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
     NSTextField* timeField = [result viewWithTag:GENERIC_INT_TIME_TAG];
 
     // TODO: Fix symbol in LRC
-    NSString* fixedString = [text stringByReplacingOccurrencesOfString:@"🕽" withString:@"📞"];
+    NSString* fixedString = [[text stringByReplacingOccurrencesOfString:@"🕽" withString:@""] stringByReplacingOccurrencesOfString:@"📞"  withString:@""];
     [textField setStringValue:fixedString];
     [timeField setStringValue:time];
 
@@ -786,21 +786,17 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
     if ([[NSCalendar currentCalendar] compareDate:today
                                            toDate:msgTime
                                 toUnitGranularity:NSCalendarUnitYear]!= NSOrderedSame) {
-        return [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];
+        return [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterMediumStyle];
     }
-
     if ([[NSCalendar currentCalendar] compareDate:today
                                            toDate:msgTime
                                 toUnitGranularity:NSCalendarUnitDay]!= NSOrderedSame ||
         [[NSCalendar currentCalendar] compareDate:today
                                            toDate:msgTime
                                 toUnitGranularity:NSCalendarUnitMonth]!= NSOrderedSame) {
-            [dateFormatter setDateFormat:@"MMM dd, HH:mm"];
-            return [dateFormatter stringFromDate:msgTime];
-        }
-
-    [dateFormatter setDateFormat:@"HH:mm"];
-    return [dateFormatter stringFromDate:msgTime];
+            return [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
+    }
+     return [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
 }
 
 - (void) updateSendMessageHeight {
diff --git a/src/RecordFileVC.mm b/src/RecordFileVC.mm
index 013f5cc0..3d53a201 100644
--- a/src/RecordFileVC.mm
+++ b/src/RecordFileVC.mm
@@ -211,11 +211,6 @@ previewView, timeLabel, recordOnOffButton, sendButton, fileImage, infoLabel, tim
     [durationTimer invalidate];
     durationTimer = nil;
     [self setRecordedState];
-    if(isAudio) {
-        return;
-    }
-    std::string uri = [[@"file:///" stringByAppendingString: fileName] UTF8String];
-    avModel->setInputFile(uri);
 }
 
 -(void) startRecord {
diff --git a/src/SmartViewVC.mm b/src/SmartViewVC.mm
index d1b78f66..4eb1940a 100755
--- a/src/SmartViewVC.mm
+++ b/src/SmartViewVC.mm
@@ -523,19 +523,26 @@ NSInteger const REQUEST_SEG         = 1;
         [interactionSnippet setStringValue:lastInteractionSnippetFixedString];
 
         // last interaction date/time
-        std::time_t lastInteractionTimestamp = conversation.interactions[lastUid].timestamp;
-        std::time_t now = std::time(nullptr);
-        char interactionDay[64];
-        char nowDay[64];
-        std::strftime(interactionDay, sizeof(interactionDay), "%D", std::localtime(&lastInteractionTimestamp));
-        std::strftime(nowDay, sizeof(nowDay), "%D", std::localtime(&now));
-        if (std::string(interactionDay) == std::string(nowDay)) {
-            char interactionTime[64];
-            std::strftime(interactionTime, sizeof(interactionTime), "%R", std::localtime(&lastInteractionTimestamp));
-            [lastInteractionDate setStringValue:[NSString stringWithUTF8String:interactionTime]];
+        NSString *timeString = @"";
+        NSDate* msgTime = [NSDate dateWithTimeIntervalSince1970:conversation.interactions[lastUid].timestamp];
+        NSDate *today = [NSDate date];
+        NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
+        [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale currentLocale] localeIdentifier]]];
+        if ([[NSCalendar currentCalendar] compareDate:today
+                                               toDate:msgTime
+                                    toUnitGranularity:NSCalendarUnitYear]!= NSOrderedSame) {
+            timeString = [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle];
+        } else if ([[NSCalendar currentCalendar] compareDate:today
+                                                      toDate:msgTime
+                                           toUnitGranularity:NSCalendarUnitDay]!= NSOrderedSame ||
+                   [[NSCalendar currentCalendar] compareDate:today
+                                                      toDate:msgTime
+                                           toUnitGranularity:NSCalendarUnitMonth]!= NSOrderedSame) {
+            timeString = [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterNoStyle];
         } else {
-            [lastInteractionDate setStringValue:[NSString stringWithUTF8String:interactionDay]];
+            timeString = [NSDateFormatter localizedStringFromDate:msgTime dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
         }
+        [lastInteractionDate setStringValue:timeString];
     }
 
     return result;
-- 
GitLab