mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 06:49:23 +00:00
Export all conversation messages
This commit is contained in:
parent
536df2931b
commit
58877e0100
@ -11,6 +11,7 @@ import { CommentsController } from "./CommentsController";
|
|||||||
import { LikesController } from "./LikesController";
|
import { LikesController } from "./LikesController";
|
||||||
import { SurveyController } from "./SurveyController";
|
import { SurveyController } from "./SurveyController";
|
||||||
import { MoviesController } from "./MoviesController";
|
import { MoviesController } from "./MoviesController";
|
||||||
|
import { ConversationsController } from "./ConversationsController";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account controller
|
* Account controller
|
||||||
@ -249,6 +250,9 @@ export class AccountController {
|
|||||||
|
|
||||||
// User movies
|
// User movies
|
||||||
movies: data.movies.map(MoviesController.MovieToAPI),
|
movies: data.movies.map(MoviesController.MovieToAPI),
|
||||||
|
|
||||||
|
// Conversations messages
|
||||||
|
all_conversation_messages: data.conversationMessages.map(ConversationsController.ConversationMessageToAPI)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ export class ConversationsController {
|
|||||||
*
|
*
|
||||||
* @param c Information about the conversation
|
* @param c Information about the conversation
|
||||||
*/
|
*/
|
||||||
private static ConversationMessageToAPI(c: ConversationMessage) : any {
|
public static ConversationMessageToAPI(c: ConversationMessage) : any {
|
||||||
return {
|
return {
|
||||||
ID: c.id,
|
ID: c.id,
|
||||||
ID_user: c.userID,
|
ID_user: c.userID,
|
||||||
|
@ -10,6 +10,7 @@ import { Comment } from "./Comment";
|
|||||||
import { UserLike } from "./UserLike";
|
import { UserLike } from "./UserLike";
|
||||||
import { SurveyResponse } from "./SurveyResponse";
|
import { SurveyResponse } from "./SurveyResponse";
|
||||||
import { Movie } from "./Movie";
|
import { Movie } from "./Movie";
|
||||||
|
import { ConversationMessage } from "./ConversationMessage";
|
||||||
|
|
||||||
export interface AccountExportBuilder {
|
export interface AccountExportBuilder {
|
||||||
userID: number;
|
userID: number;
|
||||||
@ -19,6 +20,7 @@ export interface AccountExportBuilder {
|
|||||||
likes: UserLike[];
|
likes: UserLike[];
|
||||||
surveyResponses: SurveyResponse[];
|
surveyResponses: SurveyResponse[];
|
||||||
movies: Movie[];
|
movies: Movie[];
|
||||||
|
conversationMessages: ConversationMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AccountExport implements AccountExportBuilder {
|
export class AccountExport implements AccountExportBuilder {
|
||||||
@ -29,6 +31,7 @@ export class AccountExport implements AccountExportBuilder {
|
|||||||
likes: UserLike[];
|
likes: UserLike[];
|
||||||
surveyResponses: SurveyResponse[];
|
surveyResponses: SurveyResponse[];
|
||||||
movies: Movie[];
|
movies: Movie[];
|
||||||
|
conversationMessages: ConversationMessage[];
|
||||||
|
|
||||||
public constructor(info: AccountExportBuilder) {
|
public constructor(info: AccountExportBuilder) {
|
||||||
for (const key in info) {
|
for (const key in info) {
|
||||||
|
@ -12,6 +12,7 @@ import { CommentsHelper } from "./CommentsHelper";
|
|||||||
import { LikesHelper } from "./LikesHelper";
|
import { LikesHelper } from "./LikesHelper";
|
||||||
import { SurveyHelper } from "./SurveyHelper";
|
import { SurveyHelper } from "./SurveyHelper";
|
||||||
import { MoviesHelper } from "./MoviesHelper";
|
import { MoviesHelper } from "./MoviesHelper";
|
||||||
|
import { ConversationsHelper } from "./ConversationsHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account helper
|
* Account helper
|
||||||
@ -406,6 +407,9 @@ export class AccountHelper {
|
|||||||
|
|
||||||
// User movies
|
// User movies
|
||||||
movies: await MoviesHelper.GetListUser(userID),
|
movies: await MoviesHelper.GetListUser(userID),
|
||||||
|
|
||||||
|
// Conversation messages
|
||||||
|
conversationMessages: await ConversationsHelper.ExportAllMessages(userID),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,6 +352,20 @@ export class ConversationsHelper {
|
|||||||
.map(m => this.DBToConversationMessage(convID, m)).reverse();
|
.map(m => this.DBToConversationMessage(convID, m)).reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export all the conversation messages of a given user
|
||||||
|
*
|
||||||
|
* @param userID Target user ID
|
||||||
|
*/
|
||||||
|
public static async ExportAllMessages(userID: number) : Promise<ConversationMessage[]> {
|
||||||
|
return (await DatabaseHelper.Query({
|
||||||
|
table: MESSAGES_TABLE,
|
||||||
|
where: {
|
||||||
|
user_id: userID
|
||||||
|
}
|
||||||
|
})).map(m => this.DBToConversationMessage(m.conv_id, m));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the user has seen the last messages of the conversation
|
* Mark the user has seen the last messages of the conversation
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user