diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 1f1c024..37008dd 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -66,7 +66,7 @@ export class ConversationsController { * @param handler */ public static async GetInfoSingle(handler: RequestHandler) { - const conversationID = await this.GetPostConversationId("conversationID", handler); + const conversationID = await handler.postConversationId("conversationID"); const conv = await ConversationsHelper.GetSingle(conversationID, handler.getUserId()); if(!conv) @@ -81,7 +81,7 @@ export class ConversationsController { * @param h Request handler */ public static async UpdateSettings(h: RequestHandler) : Promise { - const convID = await this.GetPostConversationId("conversationID", h); + const convID = await h.postConversationId("conversationID"); // Update following state, if required if(h.hasPostParameter("following")) { @@ -218,7 +218,7 @@ export class ConversationsController { * @param h Request handler */ public static async RefreshSingleConversation(h: RequestHandler) { - const convID = await this.GetPostConversationId("conversationID", h); + const convID = await h.postConversationId("conversationID"); const lastMessageID = h.postInt("last_message_id"); const messages = lastMessageID == 0 ? @@ -241,7 +241,7 @@ export class ConversationsController { * @param h Request handler */ public static async SendMessage(h: RequestHandler) { - const convID = await this.GetPostConversationId("conversationID", h); + const convID = await h.postConversationId("conversationID"); const message = removeHTMLNodes(h.postString("message", 0)); let imagePath = ""; @@ -271,7 +271,7 @@ export class ConversationsController { * @param h Request handler */ public static async GetOlderMessages(h: RequestHandler) { - const convID = await this.GetPostConversationId("conversationID", h); + const convID = await h.postConversationId("conversationID"); const maxID = h.postInt("oldest_message_id") - 1; let limit = h.postInt("limit"); @@ -312,7 +312,7 @@ export class ConversationsController { * @param h Request handler */ public static async DeleteConversation(h: RequestHandler) { - const convID = await this.GetPostConversationId("conversationID", h); + const convID = await h.postConversationId("conversationID"); await ConversationsHelper.RemoveUserFromConversation(h.getUserId(), convID); @@ -356,22 +356,6 @@ export class ConversationsController { h.success("Conversation message has been successfully deleted!"); } - /** - * Get and return safely a conversation ID specified in a $_POST Request - * - * @param name The name of the POST field containing the ID of the conversation - * @param handler - */ - private static async GetPostConversationId(name : string, handler: RequestHandler) : Promise { - const convID = handler.postInt(name); - - // Check out whether the user belongs to the conversation or not - if(!await ConversationsHelper.DoesUsersBelongsTo(handler.getUserId(), convID)) - handler.error(401, "You are not allowed to perform queries on this conversation!"); - - return convID; - } - /** * Turn a conversation object into an API entry * diff --git a/src/entities/BaseRequestsHandler.ts b/src/entities/BaseRequestsHandler.ts index 208fc28..b960c08 100644 --- a/src/entities/BaseRequestsHandler.ts +++ b/src/entities/BaseRequestsHandler.ts @@ -14,6 +14,7 @@ import { PostsHelper } from "../helpers/PostsHelper"; import { PostAccessLevel } from "./Post"; import { CommentsHelper } from "../helpers/CommentsHelper"; import { checkVirtualDirectory } from "../utils/VirtualDirsUtils"; +import { ConversationsHelper } from "../helpers/ConversationsHelper"; export abstract class BaseRequestsHandler { @@ -387,4 +388,20 @@ export abstract class BaseRequestsHandler { if(!await AccountHelper.CheckUserPassword(this.getUserId(), password)) this.error(401, "Invalid password!"); } + + /** + * Get and return safely a conversation ID specified in a $_POST Request + * + * @param name The name of the POST field containing the ID of the conversation + * @param handler + */ + public async postConversationId(name : string) : Promise { + const convID = this.postInt(name); + + // Check out whether the user belongs to the conversation or not + if(!await ConversationsHelper.DoesUsersBelongsTo(this.getUserId(), convID)) + this.error(401, "You are not allowed to perform queries on this conversation!"); + + return convID; + } } \ No newline at end of file