forked from olcxjas-softworks/LarpixClient
Add test dm accepting, revoking and declining
This commit is contained in:
parent
81e222250d
commit
2979881908
3 changed files with 41 additions and 16 deletions
|
|
@ -514,10 +514,10 @@ function createAvatarSvg(name, size = 512) {
|
|||
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
||||
}
|
||||
|
||||
async function getAvatarUrl(username)
|
||||
async function getAvatarUrl(id, username)
|
||||
{
|
||||
try {
|
||||
let pfpUrl = `${url}/user/storage/public/getentry?u=${username}&e=larp.profile.pfp`;
|
||||
let pfpUrl = `${url}/user/storage/public/getentry?id=${id}&e=larp.profile.pfp`;
|
||||
if ((await fetchAsync(pfpUrl)) == "")
|
||||
{
|
||||
throw Error();
|
||||
|
|
@ -1024,7 +1024,7 @@ async function renderInvites(res, type) {
|
|||
if (!(username && username.trim() !== "")) return;
|
||||
count++;
|
||||
|
||||
let pfp = await getAvatarUrl(username);
|
||||
let pfp = await getAvatarUrl(id, username);
|
||||
|
||||
let actions = "";
|
||||
let desc = "";
|
||||
|
|
@ -1032,17 +1032,17 @@ async function renderInvites(res, type) {
|
|||
if (type === "received") {
|
||||
desc = `:desc.invite.dm.received:${username};${id}`;
|
||||
actions = `
|
||||
<button class="icon-button" style="background-color: var(--big-green); border-color: transparent;" onclick="acceptInvite('${id}')">
|
||||
<button class="icon-button" style="background-color: var(--big-green);" onclick="acceptInvite('${id}')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#fff"><path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/></svg>
|
||||
</button>
|
||||
<button class="icon-button" style="background-color: var(--big-red); border-color: transparent;" onclick="declineInvite('${id}')">
|
||||
<button class="icon-button" style="background-color: var(--big-red);" onclick="declineInvite('${id}')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#fff"><path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>
|
||||
</button>
|
||||
`;
|
||||
} else {
|
||||
desc = `:desc.invite.dm.sent:${username};${id}`;
|
||||
actions = `
|
||||
<button class="icon-button" style="background-color: var(--big-red); border-color: transparent;" onclick="revokeInvite('${id}')">
|
||||
<button class="icon-button" style="background-color: var(--big-red);" onclick="revokeInvite('${id}')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#fff"><path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>
|
||||
</button>
|
||||
`;
|
||||
|
|
@ -1096,10 +1096,15 @@ async function switchInvitesTab(tab) {
|
|||
|
||||
await loadInvites(tab);
|
||||
}
|
||||
async function acceptInvite(username) { //TODO
|
||||
async function acceptInvite(targetId) { //TODO: Implement key generation
|
||||
try {
|
||||
showAction("action.invite.accepting", "invite.action");
|
||||
let res = await fetchEncrypted("user/dm/create", username);
|
||||
let payload = JSON.stringify({
|
||||
string1: targetId,
|
||||
string2: "", // TODO: Generate symmetric keys
|
||||
string3: "" // TODO: Encrypt key for targetId
|
||||
});
|
||||
let res = await fetchEncrypted("user/dm/create", payload);
|
||||
clearAction("invite.action");
|
||||
showBlahNotification(res || "success:invite.accepted");
|
||||
await loadInvites('received');
|
||||
|
|
@ -1109,10 +1114,10 @@ async function acceptInvite(username) { //TODO
|
|||
}
|
||||
}
|
||||
|
||||
async function declineInvite(username) { //TODO
|
||||
async function declineInvite(username) {
|
||||
try {
|
||||
showAction("action.invite.declining", "invite.action");
|
||||
let res = await fetchEncrypted("user/dm/decline", username);
|
||||
let res = await fetchEncrypted("user/dm/invite/decline", username);
|
||||
clearAction("invite.action");
|
||||
showBlahNotification(res || "success:invite.declined");
|
||||
await loadInvites('received');
|
||||
|
|
@ -1122,10 +1127,10 @@ async function declineInvite(username) { //TODO
|
|||
}
|
||||
}
|
||||
|
||||
async function revokeInvite(username) { //TODO
|
||||
async function revokeInvite(username) {
|
||||
try {
|
||||
showAction("action.invite.revoking", "invite.action");
|
||||
let res = await fetchEncrypted("user/dm/revoke", username);
|
||||
let res = await fetchEncrypted("user/dm/invite/revoke", username);
|
||||
clearAction("invite.action");
|
||||
showBlahNotification(res || "success:invite.revoked");
|
||||
await loadInvites('sent');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue