mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Move method postConversationId
This commit is contained in:
parent
d17ef3c9b2
commit
f69271d42f
@ -66,7 +66,7 @@ export class ConversationsController {
|
|||||||
* @param handler
|
* @param handler
|
||||||
*/
|
*/
|
||||||
public static async GetInfoSingle(handler: RequestHandler) {
|
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());
|
const conv = await ConversationsHelper.GetSingle(conversationID, handler.getUserId());
|
||||||
|
|
||||||
if(!conv)
|
if(!conv)
|
||||||
@ -81,7 +81,7 @@ export class ConversationsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async UpdateSettings(h: RequestHandler) : Promise<void> {
|
public static async UpdateSettings(h: RequestHandler) : Promise<void> {
|
||||||
const convID = await this.GetPostConversationId("conversationID", h);
|
const convID = await h.postConversationId("conversationID");
|
||||||
|
|
||||||
// Update following state, if required
|
// Update following state, if required
|
||||||
if(h.hasPostParameter("following")) {
|
if(h.hasPostParameter("following")) {
|
||||||
@ -218,7 +218,7 @@ export class ConversationsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async RefreshSingleConversation(h: RequestHandler) {
|
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 lastMessageID = h.postInt("last_message_id");
|
||||||
|
|
||||||
const messages = lastMessageID == 0 ?
|
const messages = lastMessageID == 0 ?
|
||||||
@ -241,7 +241,7 @@ export class ConversationsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async SendMessage(h: RequestHandler) {
|
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));
|
const message = removeHTMLNodes(h.postString("message", 0));
|
||||||
let imagePath = "";
|
let imagePath = "";
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ export class ConversationsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async GetOlderMessages(h: RequestHandler) {
|
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;
|
const maxID = h.postInt("oldest_message_id") - 1;
|
||||||
|
|
||||||
let limit = h.postInt("limit");
|
let limit = h.postInt("limit");
|
||||||
@ -312,7 +312,7 @@ export class ConversationsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async DeleteConversation(h: RequestHandler) {
|
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);
|
await ConversationsHelper.RemoveUserFromConversation(h.getUserId(), convID);
|
||||||
|
|
||||||
@ -356,22 +356,6 @@ export class ConversationsController {
|
|||||||
h.success("Conversation message has been successfully deleted!");
|
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<number> {
|
|
||||||
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
|
* Turn a conversation object into an API entry
|
||||||
*
|
*
|
||||||
|
@ -14,6 +14,7 @@ import { PostsHelper } from "../helpers/PostsHelper";
|
|||||||
import { PostAccessLevel } from "./Post";
|
import { PostAccessLevel } from "./Post";
|
||||||
import { CommentsHelper } from "../helpers/CommentsHelper";
|
import { CommentsHelper } from "../helpers/CommentsHelper";
|
||||||
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
||||||
|
import { ConversationsHelper } from "../helpers/ConversationsHelper";
|
||||||
|
|
||||||
export abstract class BaseRequestsHandler {
|
export abstract class BaseRequestsHandler {
|
||||||
|
|
||||||
@ -387,4 +388,20 @@ export abstract class BaseRequestsHandler {
|
|||||||
if(!await AccountHelper.CheckUserPassword(this.getUserId(), password))
|
if(!await AccountHelper.CheckUserPassword(this.getUserId(), password))
|
||||||
this.error(401, "Invalid 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<number> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user