2022-08-11 01:36:53 +03:00
|
|
|
import request from "./request.js";
|
2022-08-11 17:55:48 +03:00
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
// THREAD:
|
|
|
|
|
2022-08-31 16:05:23 +03:00
|
|
|
window.edit_thread = async function (id) {
|
2022-08-29 19:31:59 +03:00
|
|
|
const title = prompt("Enter new title!");
|
2022-08-31 16:05:23 +03:00
|
|
|
const res = await request(`/api/threads/${id}/`, "PATCH", { title });
|
2022-08-29 19:31:59 +03:00
|
|
|
if (res.error) return;
|
|
|
|
alert(`Thread updated`);
|
|
|
|
document.getElementById("title").innerHTML = title;
|
|
|
|
|
|
|
|
}
|
2022-08-29 21:32:57 +03:00
|
|
|
window.delete_thread = async function (id) {
|
|
|
|
const res = await request(`/api/threads/${id}/`, "DELETE");
|
|
|
|
if (res.error) return;
|
|
|
|
alert(`Thread deleted`);
|
|
|
|
location.reload();
|
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 21:32:57 +03:00
|
|
|
window.undelete_thread = async function (id) {
|
|
|
|
const res = await request(`/api/threads/${id}/undelete`);
|
2022-08-29 19:31:59 +03:00
|
|
|
if (res.error) return;
|
2022-08-29 21:32:57 +03:00
|
|
|
alert(`Thread undeleted`);
|
2022-08-29 16:26:34 +03:00
|
|
|
location.reload();
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
|
|
|
|
// MESSAGES:
|
|
|
|
window.send_edit = async function (id) {
|
|
|
|
const message = document.getElementById(`message-${id}`);
|
|
|
|
const content = message.querySelector("#content").value;
|
|
|
|
|
|
|
|
const res = await request(`/api/messages/${id}/`, "PATCH", { content });
|
|
|
|
if (res.error) return;
|
2022-08-29 19:31:59 +03:00
|
|
|
alert(`Message updated`);
|
2022-09-16 21:57:27 +03:00
|
|
|
message.querySelector(".content").innerHTML = converter.makeHtml(res.content);
|
2022-09-01 14:02:47 +03:00
|
|
|
}
|
|
|
|
window.edit_message = async function (id) {
|
|
|
|
const content = document.getElementById(`message-${id}`).querySelector(".content");
|
|
|
|
|
|
|
|
content.innerHTML = `
|
2022-09-16 21:57:27 +03:00
|
|
|
<textarea rows="4" cols="40" id="content">${content.rawText}</textarea>
|
2022-09-01 14:02:47 +03:00
|
|
|
<button onclick="send_edit(${id});" class="btn-primary">Edit!</button>`;
|
2022-08-29 19:31:59 +03:00
|
|
|
|
|
|
|
}
|
2022-08-29 16:16:44 +03:00
|
|
|
window.undelete_message = async function (id) {
|
2022-08-27 14:08:28 +03:00
|
|
|
const response = await request(`/api/messages/${id}/undelete`);
|
2022-08-29 16:16:44 +03:00
|
|
|
if (response.deleted) return;
|
2022-09-01 14:02:47 +03:00
|
|
|
const message = document.getElementById("message-" + id);
|
|
|
|
|
|
|
|
message.querySelector("#deleted").remove();
|
|
|
|
message.querySelector(".dots-menu").innerHTML = `
|
2022-08-29 16:16:44 +03:00
|
|
|
<a onclick="delete_message('${id}');">DELETE</a>
|
2022-08-29 19:31:59 +03:00
|
|
|
<a onclick="edit_message('${id}');">EDIT</a>`
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 16:16:44 +03:00
|
|
|
window.delete_message = async function (id) {
|
2022-08-31 16:05:23 +03:00
|
|
|
const response = await request(`/api/messages/${id}/`, "DELETE");
|
2022-09-01 14:02:47 +03:00
|
|
|
if (!response.deleted) return
|
|
|
|
const message = document.getElementById(`message-${id}`);
|
|
|
|
alert("Message deleted");
|
|
|
|
|
|
|
|
message.querySelector(".dots-menu").innerHTML = `<a onclick="undelete_message('${id}');">UNDELETE</a>`;
|
|
|
|
|
|
|
|
let dots = message.querySelector(".dots");
|
|
|
|
dots.innerHTML = "<i class='bx bx-trash bx-sm' id='deleted' style='color: var(--important)'></i>" + dots.innerHTML;
|
|
|
|
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 16:16:44 +03:00
|
|
|
window.react = async function (id, type) {
|
2022-08-27 14:08:28 +03:00
|
|
|
const res = await request(`/api/messages/${id}/react/${type}`)
|
2022-09-01 14:02:47 +03:00
|
|
|
const message = document.getElementById(`message-${id}`);
|
|
|
|
for (const react in res.react)
|
|
|
|
message.querySelector("#" + react).innerHTML = res.react[react].length;
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|