mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 06:49:23 +00:00
Can get conversation messages
This commit is contained in:
parent
653b066a3a
commit
830c871ed4
@ -251,14 +251,21 @@ export class AccountController {
|
|||||||
// User movies
|
// User movies
|
||||||
movies: data.movies.map(MoviesController.MovieToAPI),
|
movies: data.movies.map(MoviesController.MovieToAPI),
|
||||||
|
|
||||||
// Conversations messages
|
// All conversations messages
|
||||||
all_conversation_messages: data.conversationMessages.map(ConversationsController.ConversationMessageToAPI),
|
all_conversation_messages: data.allConversationMessages.map(ConversationsController.ConversationMessageToAPI),
|
||||||
|
|
||||||
// Conversations list
|
// Conversations list
|
||||||
conversations_list: data.conversations.map(ConversationsController.ConversationToAPI),
|
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)
|
// TODO : continue (additional user info)
|
||||||
|
@ -21,8 +21,9 @@ export interface AccountExportBuilder {
|
|||||||
likes: UserLike[];
|
likes: UserLike[];
|
||||||
surveyResponses: SurveyResponse[];
|
surveyResponses: SurveyResponse[];
|
||||||
movies: Movie[];
|
movies: Movie[];
|
||||||
conversationMessages: ConversationMessage[];
|
allConversationMessages: ConversationMessage[];
|
||||||
conversations: Conversation[];
|
conversations: Conversation[];
|
||||||
|
conversationsMessages: Map<number, ConversationMessage[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AccountExport implements AccountExportBuilder {
|
export class AccountExport implements AccountExportBuilder {
|
||||||
@ -33,8 +34,9 @@ export class AccountExport implements AccountExportBuilder {
|
|||||||
likes: UserLike[];
|
likes: UserLike[];
|
||||||
surveyResponses: SurveyResponse[];
|
surveyResponses: SurveyResponse[];
|
||||||
movies: Movie[];
|
movies: Movie[];
|
||||||
conversationMessages: ConversationMessage[];
|
allConversationMessages: ConversationMessage[];
|
||||||
conversations: Conversation[];
|
conversations: Conversation[];
|
||||||
|
conversationsMessages: Map<number, ConversationMessage[]>;
|
||||||
|
|
||||||
public constructor(info: AccountExportBuilder) {
|
public constructor(info: AccountExportBuilder) {
|
||||||
for (const key in info) {
|
for (const key in info) {
|
||||||
|
@ -409,12 +409,21 @@ export class AccountHelper {
|
|||||||
movies: await MoviesHelper.GetListUser(userID),
|
movies: await MoviesHelper.GetListUser(userID),
|
||||||
|
|
||||||
// Conversation messages
|
// Conversation messages
|
||||||
conversationMessages: await ConversationsHelper.ExportAllMessages(userID),
|
allConversationMessages: await ConversationsHelper.ExportAllMessages(userID),
|
||||||
|
|
||||||
// Conversations list
|
// Conversations list
|
||||||
conversations: await ConversationsHelper.GetListUser(userID),
|
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
|
// TODO : continue
|
||||||
|
|
||||||
|
@ -352,6 +352,20 @@ export class ConversationsHelper {
|
|||||||
.map(m => this.DBToConversationMessage(convID, m)).reverse();
|
.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
|
* Export all the conversation messages of a given user
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user