add CONTACT and CALL interactions in conversations

With those interactions, the conversation view is now displaying:
- Contact status update + invitations received and accepted.
- Call history with length of call if it was established successfully.

Change-Id: Ib467dea48550a0a7c618605cb709e97a9c932bc8
Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
diff --git a/src/MessagesVC.mm b/src/MessagesVC.mm
index aa751ba..6b73375 100644
--- a/src/MessagesVC.mm
+++ b/src/MessagesVC.mm
@@ -54,6 +54,9 @@
 
 @end
 
+// Tags for view
+NSInteger const GENERIC_INT_TEXT_TAG = 100;
+
 @implementation MessagesVC
 
 -(const lrc::api::conversation::Info*) getCurrentConversation
@@ -128,6 +131,18 @@
     [conversationView scrollToEndOfDocument:nil];
 }
 
+-(NSTableCellView*) makeGenericInteractionViewForTableView:(NSTableView*)tableView withText:(NSString*)text
+{
+    NSTableCellView* result = [tableView makeViewWithIdentifier:@"GenericInteractionView" owner:self];
+    NSTextField* textField = [result viewWithTag:GENERIC_INT_TEXT_TAG];
+
+    // TODO: Fix symbol in LRC
+    NSString* fixedString = [text stringByReplacingOccurrencesOfString:@"🕽" withString:@"📞"];
+    [textField setStringValue:fixedString];
+
+    return result;
+}
+
 -(IMTableCellView*) makeViewforTransferStatus:(lrc::api::interaction::Status)status type:(lrc::api::interaction::Type)type tableView:(NSTableView*)tableView
 {
     IMTableCellView* result;
@@ -197,31 +212,9 @@
     if (conv == nil)
         return nil;
 
-    // HACK HACK HACK HACK HACK
-    // The following code has to be replaced when every views are implemented for every interaction types
-    // This is an iterator which "jumps over" any interaction which is not a text or datatransfer one.
-    // It behaves as if interaction list was only containing text interactions.
-    std::map<uint64_t, lrc::api::interaction::Info>::const_iterator it;
+    auto it = conv->interactions.begin();
 
-    {
-        int msgCount = 0;
-        it = std::find_if(conv->interactions.begin(), conv->interactions.end(), [&msgCount, row](const std::pair<uint64_t, lrc::api::interaction::Info>& inter) {
-            if (inter.second.type == lrc::api::interaction::Type::TEXT
-                || inter.second.type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER
-                || inter.second.type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER) {
-                if (msgCount == row) {
-                    return true;
-                } else {
-                    msgCount++;
-                    return false;
-                }
-            }
-            return false;
-        });
-    }
-
-    if (it == conv->interactions.end())
-        return nil;
+    std::advance(it, row);
 
     IMTableCellView* result;
 
@@ -243,6 +236,9 @@
         case lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER:
             result = [self makeViewforTransferStatus:interaction.status type:interaction.type tableView:tableView];
             break;
+        case lrc::api::interaction::Type::CONTACT:
+        case lrc::api::interaction::Type::CALL:
+            return [self makeGenericInteractionViewForTableView:tableView withText:@(interaction.body.c_str())];
         default:  // If interaction is not of a known type
             return nil;
     }
@@ -290,13 +286,6 @@
     return result;
 }
 
-- (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row
-{
-    if (IMTableCellView* cellView = [tableView viewAtColumn:0 row:row makeIfNecessary:NO]) {
-        [self.selectionManager registerTextView:cellView.msgView withUniqueIdentifier:@(row).stringValue];
-    }
-}
-
 - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
 {
     double someWidth = tableView.frame.size.width * 0.7;
@@ -306,37 +295,18 @@
     if (conv == nil)
         return 0;
 
-    // HACK HACK HACK HACK HACK
-    // The following code has to be replaced when every views are implemented for every interaction types
-    // This is an iterator which "jumps over" any interaction which is not a text or datatransfer one.
-    // It behaves as if interaction list was only containing text interactions.
-    std::map<uint64_t, lrc::api::interaction::Info>::const_iterator it;
+    auto it = conv->interactions.begin();
 
-    {
-        int msgCount = 0;
-        it = std::find_if(conv->interactions.begin(), conv->interactions.end(), [&msgCount, row](const std::pair<uint64_t, lrc::api::interaction::Info>& inter) {
-            if (inter.second.type == lrc::api::interaction::Type::TEXT
-                || inter.second.type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER
-                || inter.second.type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER) {
-                if (msgCount == row) {
-                    return true;
-                } else {
-                    msgCount++;
-                    return false;
-                }
-            }
-            return false;
-        });
-    }
-
-    if (it == conv->interactions.end())
-        return 0;
+    std::advance(it, row);
 
     auto& interaction = it->second;
 
     if(interaction.type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER || interaction.type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER)
         return 52.0;
 
+    if(interaction.type == lrc::api::interaction::Type::CONTACT || interaction.type == lrc::api::interaction::Type::CALL)
+        return 27.0;
+
     // TODO Implement interactions other than messages
     if(interaction.type != lrc::api::interaction::Type::TEXT) {
         return 0;
@@ -372,24 +342,10 @@
 {
     auto* conv = [self getCurrentConversation];
 
-    if (conv) {
-        int count;
-        count = std::count_if(conv->interactions.begin(), conv->interactions.end(), [](const std::pair<uint64_t, lrc::api::interaction::Info>& inter) {
-            return inter.second.type == lrc::api::interaction::Type::TEXT
-            || inter.second.type == lrc::api::interaction::Type::INCOMING_DATA_TRANSFER
-            || inter.second.type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER;
-        });
-        NSLog(@"$$$ Interaction count: %d", count);
-        return count;
-    }
-    return 0;
-
-#if 0
-    // TODO: Replace above code by the following one when every interaction types implemented
-    if (conv_) {
-        return conv_->interactions.size();
-    }
-#endif
+    if (conv)
+        return conv->interactions.size();
+    else
+        return 0;
 }
 
 #pragma mark - Text formatting
diff --git a/ui/Base.lproj/Conversation.xib b/ui/Base.lproj/Conversation.xib
index b10e49a..492e83b 100644
--- a/ui/Base.lproj/Conversation.xib
+++ b/ui/Base.lproj/Conversation.xib
@@ -23,20 +23,20 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView wantsLayer="YES" id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="798" height="586"/>
+            <rect key="frame" x="0.0" y="0.0" width="798" height="828"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <customView verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="EJD-f8-Xqd">
-                    <rect key="frame" x="0.0" y="51" width="798" height="477"/>
+                    <rect key="frame" x="0.0" y="51" width="798" height="719"/>
                     <subviews>
                         <scrollView verticalCompressionResistancePriority="250" borderType="none" autohidesScrollers="YES" horizontalLineScroll="62" horizontalPageScroll="10" verticalLineScroll="62" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" scrollerKnobStyle="dark" translatesAutoresizingMaskIntoConstraints="NO" id="Ez2-Rf-DZN">
-                            <rect key="frame" x="49" y="0.0" width="700" height="477"/>
+                            <rect key="frame" x="49" y="0.0" width="700" height="719"/>
                             <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="ofC-Bs-tHR">
-                                <rect key="frame" x="0.0" y="0.0" width="700" height="477"/>
+                                <rect key="frame" x="0.0" y="0.0" width="700" height="719"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 <subviews>
                                     <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" autosaveColumns="NO" rowHeight="60" rowSizeStyle="automatic" viewBased="YES" id="bOO-CW-S21">
-                                        <rect key="frame" x="0.0" y="0.0" width="700" height="477"/>
+                                        <rect key="frame" x="0.0" y="0.0" width="700" height="719"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <size key="intercellSpacing" width="3" height="2"/>
                                         <color key="backgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
@@ -446,6 +446,33 @@
                                                             <outlet property="statusLabel" destination="YQ5-ba-kO1" id="0Xu-ui-RrM"/>
                                                         </connections>
                                                     </tableCellView>
+                                                    <tableCellView identifier="GenericInteractionView" misplaced="YES" id="pNa-Do-cpO" userLabel="GenericInteractionView">
+                                                        <rect key="frame" x="1" y="435" width="697" height="22"/>
+                                                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                                                        <subviews>
+                                                            <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" tag="100" translatesAutoresizingMaskIntoConstraints="NO" id="35p-WS-DUv" userLabel="ContactInteractionLabel">
+                                                                <rect key="frame" x="330" y="6" width="37" height="17"/>
+                                                                <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="jRF-Jm-tK5">
+                                                                    <font key="font" metaFont="systemLight" size="13"/>
+                                                                    <color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
+                                                                    <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                                                </textFieldCell>
+                                                            </textField>
+                                                            <box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="aUR-Zb-1Ry">
+                                                                <rect key="frame" x="174" y="-2" width="350" height="5"/>
+                                                                <constraints>
+                                                                    <constraint firstAttribute="width" constant="350" id="gh1-og-RNm"/>
+                                                                </constraints>
+                                                            </box>
+                                                        </subviews>
+                                                        <constraints>
+                                                            <constraint firstItem="aUR-Zb-1Ry" firstAttribute="centerX" secondItem="pNa-Do-cpO" secondAttribute="centerX" id="3cU-kJ-UWV"/>
+                                                            <constraint firstItem="aUR-Zb-1Ry" firstAttribute="top" secondItem="35p-WS-DUv" secondAttribute="bottom" constant="5" id="GM2-QF-lCd"/>
+                                                            <constraint firstItem="35p-WS-DUv" firstAttribute="top" secondItem="pNa-Do-cpO" secondAttribute="top" constant="5" id="Sph-s4-1Fc"/>
+                                                            <constraint firstAttribute="bottom" secondItem="aUR-Zb-1Ry" secondAttribute="bottom" id="fJU-4m-Wz2"/>
+                                                            <constraint firstItem="35p-WS-DUv" firstAttribute="centerX" secondItem="pNa-Do-cpO" secondAttribute="centerX" id="im5-bF-xb1"/>
+                                                        </constraints>
+                                                    </tableCellView>
                                                 </prototypeCellViews>
                                             </tableColumn>
                                         </tableColumns>
@@ -476,10 +503,10 @@
                     </constraints>
                 </customView>
                 <box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Sn1-dJ-QCw">
-                    <rect key="frame" x="20" y="525" width="758" height="5"/>
+                    <rect key="frame" x="20" y="767" width="758" height="5"/>
                 </box>
                 <button toolTip="Record" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ooq-vs-Xt1" customClass="HoverButton">
-                    <rect key="frame" x="20" y="537" width="40" height="40"/>
+                    <rect key="frame" x="20" y="779" width="40" height="40"/>
                     <constraints>
                         <constraint firstAttribute="height" constant="40" id="69o-49-0QB"/>
                         <constraint firstAttribute="width" constant="40" id="ImE-zq-KIj"/>
@@ -578,7 +605,7 @@
                     </connections>
                 </customView>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ucx-6g-eJw">
-                    <rect key="frame" x="68" y="533" width="39" height="48"/>
+                    <rect key="frame" x="68" y="775" width="39" height="48"/>
                     <textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" sendsActionOnEndEditing="YES" alignment="left" placeholderString="Title" id="HnC-1N-RmR">
                         <font key="font" metaFont="system" size="18"/>
                         <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -586,7 +613,7 @@
                     </textFieldCell>
                 </textField>
                 <button verticalHuggingPriority="750" tag="400" translatesAutoresizingMaskIntoConstraints="NO" id="cFH-d7-Erh" userLabel="Call Button" customClass="IconButton">
-                    <rect key="frame" x="738" y="537" width="40" height="40"/>
+                    <rect key="frame" x="738" y="779" width="40" height="40"/>
                     <constraints>
                         <constraint firstAttribute="width" constant="40" id="4jd-jn-RY1"/>
                         <constraint firstAttribute="height" constant="40" id="DMa-Lq-2Tk"/>
@@ -600,7 +627,7 @@
                     </connections>
                 </button>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SQT-Vf-Lhr" userLabel="IdLabel">
-                    <rect key="frame" x="68" y="537" width="275" height="18"/>
+                    <rect key="frame" x="68" y="779" width="275" height="18"/>
                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="ID" id="rW7-RD-TBM">
                         <font key="font" metaFont="systemLight" size="12"/>
                         <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -631,7 +658,7 @@
                 <constraint firstItem="Rth-di-Tls" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="qz7-sE-9Ml"/>
                 <constraint firstItem="ucx-6g-eJw" firstAttribute="centerY" secondItem="ooq-vs-Xt1" secondAttribute="centerY" id="uTp-kU-NmC" userLabel="centeredTitle"/>
             </constraints>
-            <point key="canvasLocation" x="514" y="354"/>
+            <point key="canvasLocation" x="514" y="475"/>
         </customView>
         <userDefaultsController representsSharedInstance="YES" id="Zjc-KB-CJZ"/>
         <viewController id="iH6-17-JsM" customClass="MessagesVC">
diff --git a/ui/Base.lproj/CurrentCall.xib b/ui/Base.lproj/CurrentCall.xib
index d4704fb..42101f5 100644
--- a/ui/Base.lproj/CurrentCall.xib
+++ b/ui/Base.lproj/CurrentCall.xib
@@ -3,6 +3,7 @@
     <dependencies>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+        <capability name="system font weights other than Regular or Bold" minToolsVersion="7.0"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="CurrentCallVC">
@@ -1077,6 +1078,33 @@
                                                                     <outlet property="statusLabel" destination="c5d-Vg-wak" id="PXv-Zh-A8v"/>
                                                                 </connections>
                                                             </tableCellView>
+                                                            <tableCellView identifier="GenericInteractionView" misplaced="YES" id="0tt-a5-Dex" userLabel="GenericInteractionView">
+                                                                <rect key="frame" x="1" y="435" width="369" height="22"/>
+                                                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                                                                <subviews>
+                                                                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" tag="100" translatesAutoresizingMaskIntoConstraints="NO" id="Wyd-h8-NpR" userLabel="ContactInteractionLabel">
+                                                                        <rect key="frame" x="166" y="6" width="37" height="17"/>
+                                                                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="GBy-HF-JeP">
+                                                                            <font key="font" metaFont="systemLight" size="13"/>
+                                                                            <color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
+                                                                            <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                                                        </textFieldCell>
+                                                                    </textField>
+                                                                    <box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="gW2-ug-GL4">
+                                                                        <rect key="frame" x="60" y="-2" width="250" height="5"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="width" constant="250" id="Erp-iC-ICa"/>
+                                                                        </constraints>
+                                                                    </box>
+                                                                </subviews>
+                                                                <constraints>
+                                                                    <constraint firstItem="Wyd-h8-NpR" firstAttribute="top" secondItem="0tt-a5-Dex" secondAttribute="top" constant="5" id="MmK-0A-KJH"/>
+                                                                    <constraint firstAttribute="bottom" secondItem="gW2-ug-GL4" secondAttribute="bottom" id="UkS-g6-Nc5"/>
+                                                                    <constraint firstItem="Wyd-h8-NpR" firstAttribute="centerX" secondItem="0tt-a5-Dex" secondAttribute="centerX" id="X7O-3d-Apd"/>
+                                                                    <constraint firstItem="gW2-ug-GL4" firstAttribute="centerX" secondItem="0tt-a5-Dex" secondAttribute="centerX" id="ly5-vL-ZG9"/>
+                                                                    <constraint firstItem="gW2-ug-GL4" firstAttribute="top" secondItem="Wyd-h8-NpR" secondAttribute="bottom" constant="5" id="tYg-hG-6z1"/>
+                                                                </constraints>
+                                                            </tableCellView>
                                                         </prototypeCellViews>
                                                     </tableColumn>
                                                 </tableColumns>