diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index c317f13..4c69729 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -251,14 +251,21 @@ export class AccountController { // User movies movies: data.movies.map(MoviesController.MovieToAPI), - // Conversations messages - all_conversation_messages: data.conversationMessages.map(ConversationsController.ConversationMessageToAPI), + // All conversations messages + all_conversation_messages: data.allConversationMessages.map(ConversationsController.ConversationMessageToAPI), // Conversations list conversations_list: data.conversations.map(ConversationsController.ConversationToAPI), - + + // Conversation messages + conversation_messages: {} }; + // Fill conversation messages entry + for(const conv of data.conversations) { + out.conversation_messages[conv.id] = + data.conversationsMessages[conv.id].map(ConversationsController.ConversationMessageToAPI) + } // TODO : continue (additional user info) diff --git a/src/entities/AccountExport.ts b/src/entities/AccountExport.ts index bb57af7..9353a71 100644 --- a/src/entities/AccountExport.ts +++ b/src/entities/AccountExport.ts @@ -21,8 +21,9 @@ export interface AccountExportBuilder { likes: UserLike[]; surveyResponses: SurveyResponse[]; movies: Movie[]; - conversationMessages: ConversationMessage[]; + allConversationMessages: ConversationMessage[]; conversations: Conversation[]; + conversationsMessages: Map; } export class AccountExport implements AccountExportBuilder { @@ -33,8 +34,9 @@ export class AccountExport implements AccountExportBuilder { likes: UserLike[]; surveyResponses: SurveyResponse[]; movies: Movie[]; - conversationMessages: ConversationMessage[]; + allConversationMessages: ConversationMessage[]; conversations: Conversation[]; + conversationsMessages: Map; public constructor(info: AccountExportBuilder) { for (const key in info) { diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index 088f239..7671672 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -409,12 +409,21 @@ export class AccountHelper { movies: await MoviesHelper.GetListUser(userID), // Conversation messages - conversationMessages: await ConversationsHelper.ExportAllMessages(userID), + allConversationMessages: await ConversationsHelper.ExportAllMessages(userID), // Conversations list conversations: await ConversationsHelper.GetListUser(userID), + + // Conversations messages (completed after) + conversationsMessages: new Map() }) + // Process conversation messages + for(const conv of data.conversations) { + data.conversationsMessages[conv.id] + = await ConversationsHelper.GetAllMessages(conv.id); + } + // TODO : continue diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 0aacded..58dc28f 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -352,6 +352,20 @@ export class ConversationsHelper { .map(m => this.DBToConversationMessage(convID, m)).reverse(); } + /** + * Get (export) all the messages of a given conversation + * + * @param convID Target conversation ID + */ + public static async GetAllMessages(convID: number) : Promise { + return (await DatabaseHelper.Query({ + table: MESSAGES_TABLE, + where: { + conv_id: convID + }, + })).map(m => this.DBToConversationMessage(convID, m)); + } + /** * Export all the conversation messages of a given user *