Divide Conversation into ConversationInfos, ConversationMember, and ConversationSummary

- ConversationSummary is used to display ConversationList.
- Having the three separated will help managing queries.
- Adding ConversationSummary required to solve some inconsistencies in ConversationList, which was mixing contacts and conversations. ContactSearchResultList has been added as a quick fix . It will need more work.
- Some tools to uniformize conversation names have been introduced. They will need more work.

Note the diplaying of ConversationList is left broken in this commit.

Change-Id: I29337906cc43781a9c4790735490a6ee2cc51cb0
diff --git a/client/src/models/account.ts b/client/src/models/account.ts
index 60ac1d8..ae2299e 100644
--- a/client/src/models/account.ts
+++ b/client/src/models/account.ts
@@ -18,7 +18,6 @@
 import { AccountDetails, Devices, IAccount, VolatileDetails } from 'jami-web-common';
 
 import { Contact } from './contact';
-import { Conversation } from './conversation';
 
 export type AccountType = 'RING' | 'SIP';
 
@@ -30,8 +29,6 @@
   devices: Devices = {};
   contacts: Contact[] = [];
 
-  private _conversations: Record<string, Conversation> = {};
-
   constructor(id: string, details: AccountDetails, volatileDetails: VolatileDetails) {
     this.id = id;
     this.details = details;
@@ -79,19 +76,4 @@
   getDisplayNameNoFallback() {
     return this.details['Account.displayName'] ?? this.getRegisteredName();
   }
-
-  get conversations() {
-    return this._conversations;
-  }
-
-  addConversation(conversation: Conversation) {
-    if (conversation.id === undefined) {
-      throw new Error('Conversation ID cannot be undefined');
-    }
-    this._conversations[conversation.id] = conversation;
-  }
-
-  removeConversation(conversationId: string) {
-    delete this.conversations[conversationId];
-  }
 }
diff --git a/client/src/models/conversation-member.ts b/client/src/models/conversation-member.ts
new file mode 100644
index 0000000..b1b213d
--- /dev/null
+++ b/client/src/models/conversation-member.ts
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+import { ConversationMemberRole, IConversationMember } from 'jami-web-common';
+
+import { Contact } from './contact';
+
+export class ConversationMember implements IConversationMember {
+  readonly role;
+  readonly contact;
+
+  constructor(role: ConversationMemberRole | undefined, contact: Contact) {
+    this.role = role;
+    this.contact = contact;
+  }
+
+  static fromInterface(conversationMemberIterface: IConversationMember) {
+    return new ConversationMember(
+      conversationMemberIterface.role,
+      Contact.fromInterface(conversationMemberIterface.contact)
+    );
+  }
+
+  getDisplayName = () => {
+    return this.contact.getDisplayName();
+  };
+}
diff --git a/client/src/models/conversation.ts b/client/src/models/conversation.ts
deleted file mode 100644
index 484f166..0000000
--- a/client/src/models/conversation.ts
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2022 Savoir-faire Linux Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this program.  If not, see
- * <https://www.gnu.org/licenses/>.
- */
-import { ConversationInfos, IConversation, IConversationMember, Message } from 'jami-web-common';
-
-import { Contact } from './contact';
-
-export interface ConversationMember extends IConversationMember {
-  contact: Contact;
-}
-
-export class Conversation implements IConversation {
-  readonly id: string;
-  members: ConversationMember[];
-  messages: Message[] = [];
-  infos: ConversationInfos = {};
-
-  constructor(id: string, members?: ConversationMember[]) {
-    this.id = id;
-    this.members = members ?? [];
-  }
-
-  static fromInterface(conversationInterface: IConversation) {
-    const conversation = new Conversation(
-      conversationInterface.id,
-      conversationInterface.members.map((member) => {
-        const contact = Contact.fromInterface(member.contact);
-        return { contact } as ConversationMember;
-      })
-    );
-
-    conversation.messages = conversationInterface.messages;
-    conversation.infos = conversationInterface.infos;
-
-    return conversation;
-  }
-
-  static fromSingleContact(contact: Contact) {
-    return new Conversation('', [{ contact } as ConversationMember]);
-  }
-
-  getDisplayUri() {
-    return this.id ?? this.getFirstMember().contact.uri;
-  }
-
-  getDisplayName() {
-    if (this.members.length !== 0) {
-      return this.getFirstMember().contact.registeredName;
-    }
-    return this.getDisplayUri();
-  }
-
-  getDisplayNameNoFallback() {
-    if (this.members.length !== 0) {
-      return this.getFirstMember().contact.registeredName;
-    }
-  }
-
-  getFirstMember() {
-    return this.members[0];
-  }
-
-  addMessage(message: Message) {
-    if (this.messages.length === 0) {
-      this.messages.push(message);
-    } else if (message.id === this.messages[this.messages.length - 1].linearizedParent) {
-      this.messages.push(message);
-    } else if (message.linearizedParent === this.messages[0].id) {
-      this.messages.unshift(message);
-    } else {
-      console.log('Could not insert message', message.id);
-    }
-  }
-
-  addMessages(messages: Message[]) {
-    for (const message of messages) {
-      this.addMessage(message);
-    }
-  }
-}