generated from t/malachite
add: user profiles and junk
This commit is contained in:
parent
6b8c33d27f
commit
2bd23f8214
28 changed files with 1139 additions and 108 deletions
|
@ -102,6 +102,10 @@ function sock_con() {
|
|||
if (document.getElementById(`message_${msg.body}`)) {
|
||||
document.getElementById(`message_${msg.body}`).remove();
|
||||
}
|
||||
} else if (msg.method === "MessageUpdate") {
|
||||
const [id, content] = JSON.parse(msg.body);
|
||||
document.getElementById(`${id}_body`).innerHTML =
|
||||
await render_markdown(content);
|
||||
} else if (msg.method === "ReadReceipt") {
|
||||
setTimeout(() => {
|
||||
read_receipt();
|
||||
|
@ -179,3 +183,133 @@ function delete_message(id) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function render_markdown(content) {
|
||||
return await (
|
||||
await fetch("/api/v1/markdown", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content }),
|
||||
})
|
||||
).text();
|
||||
}
|
||||
|
||||
function edit_message_ui(id) {
|
||||
document.getElementById(`${id}_body`).classList.add("hidden");
|
||||
document.getElementById(`${id}_edit_area`).classList.remove("hidden");
|
||||
}
|
||||
|
||||
function edit_message(id, e) {
|
||||
e.preventDefault();
|
||||
|
||||
fetch(`/api/v1/messages/${id}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then(async (res) => {
|
||||
if (!res.ok) {
|
||||
show_message(res.message, res.ok);
|
||||
} else {
|
||||
document
|
||||
.getElementById(`${id}_body`)
|
||||
.classList.remove("hidden");
|
||||
document
|
||||
.getElementById(`${id}_edit_area`)
|
||||
.classList.add("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function leave_chat(id) {
|
||||
if (!confirm("Are you sure you would like to do this?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/chats/${id}/leave`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
show_message(res.message, res.ok);
|
||||
});
|
||||
}
|
||||
|
||||
function add_member_to_chat(e, chat_id) {
|
||||
e.preventDefault();
|
||||
document.getElementById("add_user_dialog").close();
|
||||
fetch(`/api/v1/chats/${chat_id}/members/add/${e.target.username.value}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
show_message(res.message, res.ok);
|
||||
});
|
||||
}
|
||||
|
||||
function update_chat_info(id, info) {
|
||||
fetch(`/api/v1/chats/${id}/info`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
info,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
show_message(res.message, res.ok);
|
||||
});
|
||||
}
|
||||
|
||||
function rename_chat(id, info) {
|
||||
const new_name = prompt("New name:");
|
||||
|
||||
if (!new_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
info.name = new_name;
|
||||
update_chat_info(id, info);
|
||||
}
|
||||
|
||||
function remove_member_from_chat(chat_id, uid) {
|
||||
if (!confirm("Are you sure you would like to do this?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/chats/${chat_id}/members/remove/${uid}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
show_message(res.message, res.ok);
|
||||
});
|
||||
}
|
||||
|
||||
function create_direct_chat_with_user(id) {
|
||||
fetch(`/api/v1/chats`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
style: "Direct",
|
||||
members: [id],
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
show_message(res.message, res.ok);
|
||||
} else {
|
||||
window.location.href = `/chats/${res.payload}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue