mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-27 22:18:52 +00:00
Can get conversation messages
This commit is contained in:
parent
653b066a3a
commit
830c871ed4
@ -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)
|
||||
|
@ -21,8 +21,9 @@ export interface AccountExportBuilder {
|
||||
likes: UserLike[];
|
||||
surveyResponses: SurveyResponse[];
|
||||
movies: Movie[];
|
||||
conversationMessages: ConversationMessage[];
|
||||
allConversationMessages: ConversationMessage[];
|
||||
conversations: Conversation[];
|
||||
conversationsMessages: Map<number, ConversationMessage[]>;
|
||||
}
|
||||
|
||||
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<number, ConversationMessage[]>;
|
||||
|
||||
public constructor(info: AccountExportBuilder) {
|
||||
for (const key in info) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<ConversationMessage[]> {
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user