Add typescript methods for requesting the new backend
authorMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 11:00:51 +0000 (13:00 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 11:00:51 +0000 (13:00 +0200)
28 files changed:
ts/WoltLabSuite/Core/Api/Comments/CreateComment.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/DeleteComment.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/EditComment.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/EnableComment.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/RenderComment.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/RenderComments.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.ts [new file with mode: 0644]
ts/WoltLabSuite/Core/Api/Comments/UpdateComment.ts [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/CreateComment.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/DeleteComment.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EditComment.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EnableComment.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComment.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComments.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/UpdateComment.js [new file with mode: 0644]

diff --git a/ts/WoltLabSuite/Core/Api/Comments/CreateComment.ts b/ts/WoltLabSuite/Core/Api/Comments/CreateComment.ts
new file mode 100644 (file)
index 0000000..ae0cbd7
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * Creates a new comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+type Response = {
+  commentID: number;
+};
+
+export async function createComment(
+  objectTypeId: number,
+  objectId: number,
+  message: string,
+  guestToken: string = "",
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments`);
+
+  const payload = {
+    objectTypeID: objectTypeId,
+    objectID: objectId,
+    message,
+    guestToken,
+  };
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).post(payload).fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/DeleteComment.ts b/ts/WoltLabSuite/Core/Api/Comments/DeleteComment.ts
new file mode 100644 (file)
index 0000000..2f554c6
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * Deletes a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+export async function deleteComment(commentId: number): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}`).delete().fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/EditComment.ts b/ts/WoltLabSuite/Core/Api/Comments/EditComment.ts
new file mode 100644 (file)
index 0000000..57e31d6
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Gets the html code for the editing of a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+type Response = {
+  template: string;
+};
+
+export async function editComment(commentId: number): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/edit`);
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/EnableComment.ts b/ts/WoltLabSuite/Core/Api/Comments/EnableComment.ts
new file mode 100644 (file)
index 0000000..ec0d403
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * Enables a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+export async function enableComment(commentId: number): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/enable`)
+      .post()
+      .fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/RenderComment.ts b/ts/WoltLabSuite/Core/Api/Comments/RenderComment.ts
new file mode 100644 (file)
index 0000000..f68aaf0
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * Gets the html code for the rendering of a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+type Response = {
+  template: string;
+  response: string | undefined;
+};
+
+export async function renderComment(
+  commentId: number,
+  responseId: number | undefined = undefined,
+  messageOnly: boolean = false,
+  objectTypeId: number | undefined = undefined,
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/render`);
+  url.searchParams.set("messageOnly", messageOnly.toString());
+  if (responseId !== undefined) {
+    url.searchParams.set("responseID", responseId.toString());
+  }
+  if (objectTypeId !== undefined) {
+    url.searchParams.set("objectTypeID", objectTypeId.toString());
+  }
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/RenderComments.ts b/ts/WoltLabSuite/Core/Api/Comments/RenderComments.ts
new file mode 100644 (file)
index 0000000..da89fcb
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * Gets the html code for the rendering of comments.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+type Response = {
+  template: string;
+  lastCommentTime: number;
+};
+
+export async function renderComments(
+  objectTypeId: number,
+  objectId: number,
+  lastCommentTime: number = 0,
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/render`);
+  url.searchParams.set("objectTypeID", objectTypeId.toString());
+  url.searchParams.set("objectID", objectId.toString());
+  url.searchParams.set("lastCommentTime", lastCommentTime.toString());
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.ts
new file mode 100644 (file)
index 0000000..7a59427
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * Creates a new comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+type Response = {
+  responseID: number;
+};
+
+export async function createResponse(
+  commentId: number,
+  message: string,
+  guestToken: string = "",
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses`);
+
+  const payload = {
+    commentID: commentId,
+    message,
+    guestToken,
+  };
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).post(payload).fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.ts
new file mode 100644 (file)
index 0000000..546da6d
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * Deletes a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+export async function deleteResponse(responseId: number): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}`)
+      .delete()
+      .fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.ts
new file mode 100644 (file)
index 0000000..bc02af1
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Gets the html code for the editing of a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+type Response = {
+  template: string;
+};
+
+export async function editResponse(responseId: number): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/edit`);
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.ts
new file mode 100644 (file)
index 0000000..73cab4d
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * Enables a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+export async function enableResponse(responseId: number): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/enable`)
+      .post()
+      .fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.ts
new file mode 100644 (file)
index 0000000..6b4b554
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * Gets the html code for the rendering of a response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+type Response = {
+  template: string;
+};
+
+export async function renderResponse(
+  responseId: number,
+  messageOnly: boolean = false,
+  objectTypeId: number | undefined = undefined,
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/render`);
+  url.searchParams.set("messageOnly", messageOnly.toString());
+  if (objectTypeId !== undefined) {
+    url.searchParams.set("objectTypeID", objectTypeId.toString());
+  }
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.ts
new file mode 100644 (file)
index 0000000..c2c749a
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * Gets the html code for the rendering of responses.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+type Response = {
+  lastResponseTime: number;
+  lastResponseID: number;
+  template: string;
+};
+
+export async function renderResponses(
+  commentId: number,
+  lastResponseTime: number,
+  lastResponseId: number,
+  loadAllResponses: boolean,
+): Promise<ApiResult<Response>> {
+  const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/render`);
+  url.searchParams.set("commentID", commentId.toString());
+  url.searchParams.set("lastResponseTime", lastResponseTime.toString());
+  url.searchParams.set("lastResponseID", lastResponseId.toString());
+  url.searchParams.set("loadAllResponses", loadAllResponses.toString());
+
+  let response: Response;
+  try {
+    response = (await prepareRequest(url).get().fetchAsJson()) as Response;
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue(response);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.ts b/ts/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.ts
new file mode 100644 (file)
index 0000000..c385348
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Updates a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+export async function updateResponse(responseId: number, message: string): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}`)
+      .post({
+        message,
+      })
+      .fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/ts/WoltLabSuite/Core/Api/Comments/UpdateComment.ts b/ts/WoltLabSuite/Core/Api/Comments/UpdateComment.ts
new file mode 100644 (file)
index 0000000..ec16da6
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Updates a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+export async function updateComment(commentId: number, message: string): Promise<ApiResult<[]>> {
+  try {
+    await prepareRequest(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}`)
+      .post({
+        message,
+      })
+      .fetchAsJson();
+  } catch (e) {
+    return apiResultFromError(e);
+  }
+
+  return apiResultFromValue([]);
+}
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/CreateComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/CreateComment.js
new file mode 100644 (file)
index 0000000..1c6264d
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * Creates a new comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.createComment = void 0;
+    async function createComment(objectTypeId, objectId, message, guestToken = "") {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments`);
+        const payload = {
+            objectTypeID: objectTypeId,
+            objectID: objectId,
+            message,
+            guestToken,
+        };
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).post(payload).fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.createComment = createComment;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/DeleteComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/DeleteComment.js
new file mode 100644 (file)
index 0000000..083cda3
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * Deletes a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.deleteComment = void 0;
+    async function deleteComment(commentId) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}`).delete().fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.deleteComment = deleteComment;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EditComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EditComment.js
new file mode 100644 (file)
index 0000000..1cf11ef
--- /dev/null
@@ -0,0 +1,25 @@
+/**
+ * Gets the html code for the editing of a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.editComment = void 0;
+    async function editComment(commentId) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/edit`);
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.editComment = editComment;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EnableComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/EnableComment.js
new file mode 100644 (file)
index 0000000..7b243b7
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Enables a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.enableComment = void 0;
+    async function enableComment(commentId) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/enable`)
+                .post()
+                .fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.enableComment = enableComment;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComment.js
new file mode 100644 (file)
index 0000000..8d946b9
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * Gets the html code for the rendering of a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.renderComment = void 0;
+    async function renderComment(commentId, responseId = undefined, messageOnly = false, objectTypeId = undefined) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}/render`);
+        url.searchParams.set("messageOnly", messageOnly.toString());
+        if (responseId !== undefined) {
+            url.searchParams.set("responseID", responseId.toString());
+        }
+        if (objectTypeId !== undefined) {
+            url.searchParams.set("objectTypeID", objectTypeId.toString());
+        }
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.renderComment = renderComment;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComments.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/RenderComments.js
new file mode 100644 (file)
index 0000000..71231cd
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Gets the html code for the rendering of comments.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.renderComments = void 0;
+    async function renderComments(objectTypeId, objectId, lastCommentTime = 0) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/render`);
+        url.searchParams.set("objectTypeID", objectTypeId.toString());
+        url.searchParams.set("objectID", objectId.toString());
+        url.searchParams.set("lastCommentTime", lastCommentTime.toString());
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.renderComments = renderComments;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/CreateResponse.js
new file mode 100644 (file)
index 0000000..d367f9a
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Creates a new comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.createResponse = void 0;
+    async function createResponse(commentId, message, guestToken = "") {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses`);
+        const payload = {
+            commentID: commentId,
+            message,
+            guestToken,
+        };
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).post(payload).fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.createResponse = createResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/DeleteResponse.js
new file mode 100644 (file)
index 0000000..5de9ccf
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Deletes a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.deleteResponse = void 0;
+    async function deleteResponse(responseId) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}`)
+                .delete()
+                .fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.deleteResponse = deleteResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EditResponse.js
new file mode 100644 (file)
index 0000000..c3f2264
--- /dev/null
@@ -0,0 +1,25 @@
+/**
+ * Gets the html code for the editing of a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.editResponse = void 0;
+    async function editResponse(responseId) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/edit`);
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.editResponse = editResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/EnableResponse.js
new file mode 100644 (file)
index 0000000..7d5cf35
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Enables a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.enableResponse = void 0;
+    async function enableResponse(responseId) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/enable`)
+                .post()
+                .fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.enableResponse = enableResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponse.js
new file mode 100644 (file)
index 0000000..7f85c4a
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * Gets the html code for the rendering of a response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.renderResponse = void 0;
+    async function renderResponse(responseId, messageOnly = false, objectTypeId = undefined) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}/render`);
+        url.searchParams.set("messageOnly", messageOnly.toString());
+        if (objectTypeId !== undefined) {
+            url.searchParams.set("objectTypeID", objectTypeId.toString());
+        }
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.renderResponse = renderResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/RenderResponses.js
new file mode 100644 (file)
index 0000000..4ffc990
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * Gets the html code for the rendering of responses.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.renderResponses = void 0;
+    async function renderResponses(commentId, lastResponseTime, lastResponseId, loadAllResponses) {
+        const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/render`);
+        url.searchParams.set("commentID", commentId.toString());
+        url.searchParams.set("lastResponseTime", lastResponseTime.toString());
+        url.searchParams.set("lastResponseID", lastResponseId.toString());
+        url.searchParams.set("loadAllResponses", loadAllResponses.toString());
+        let response;
+        try {
+            response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)(response);
+    }
+    exports.renderResponses = renderResponses;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/Responses/UpdateResponse.js
new file mode 100644 (file)
index 0000000..cd19546
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Updates a comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.updateResponse = void 0;
+    async function updateResponse(responseId, message) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/responses/${responseId}`)
+                .post({
+                message,
+            })
+                .fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.updateResponse = updateResponse;
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/UpdateComment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Comments/UpdateComment.js
new file mode 100644 (file)
index 0000000..883348f
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Updates a comment.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.updateComment = void 0;
+    async function updateComment(commentId, message) {
+        try {
+            await (0, Backend_1.prepareRequest)(`${window.WSC_API_URL}index.php?api/rpc/core/comments/${commentId}`)
+                .post({
+                message,
+            })
+                .fetchAsJson();
+        }
+        catch (e) {
+            return (0, Result_1.apiResultFromError)(e);
+        }
+        return (0, Result_1.apiResultFromValue)([]);
+    }
+    exports.updateComment = updateComment;
+});