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
|
|
@ -94,7 +94,9 @@
|
||||||
{
|
{
|
||||||
await updateProtocolAndUrl(window.location.hostname);
|
await updateProtocolAndUrl(window.location.hostname);
|
||||||
}
|
}
|
||||||
sidebarPfp.src = await getAvatarUrl(`${username}:${host}`);
|
let localIdRes = await fetchAsync(`${url}/nametoid?u=${username}`);
|
||||||
|
let localId = localIdRes.trim();
|
||||||
|
sidebarPfp.src = await getAvatarUrl(localId, `${username}:${host}`);
|
||||||
|
|
||||||
showAction("action.auth", "startauth");
|
showAction("action.auth", "startauth");
|
||||||
let res = await Auth(username, password);
|
let res = await Auth(username, password);
|
||||||
|
|
@ -134,7 +136,15 @@
|
||||||
async function addDm() {
|
async function addDm() {
|
||||||
try {
|
try {
|
||||||
showAction("action.dm.adding", "dmadd");
|
showAction("action.dm.adding", "dmadd");
|
||||||
let res = await fetchEncrypted("user/dm/invite", document.getElementById("addchat-username").value);
|
let username = document.getElementById("addchat-username").value;
|
||||||
|
let idRes = await fetchAsync(`${url}/nametoid?u=${username}`);
|
||||||
|
if (idRes.startsWith("error") || idRes.trim() === "0" || idRes.trim() === "") {
|
||||||
|
clearAction("dmadd");
|
||||||
|
showBlahNotification("error:user.not.found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let targetId = idRes.trim();
|
||||||
|
let res = await fetchEncrypted("user/dm/invite", targetId);
|
||||||
|
|
||||||
clearAction("dmadd");
|
clearAction("dmadd");
|
||||||
showBlahNotification(res);
|
showBlahNotification(res);
|
||||||
|
|
|
||||||
|
|
@ -514,10 +514,10 @@ function createAvatarSvg(name, size = 512) {
|
||||||
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAvatarUrl(username)
|
async function getAvatarUrl(id, username)
|
||||||
{
|
{
|
||||||
try {
|
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)) == "")
|
if ((await fetchAsync(pfpUrl)) == "")
|
||||||
{
|
{
|
||||||
throw Error();
|
throw Error();
|
||||||
|
|
@ -1024,7 +1024,7 @@ async function renderInvites(res, type) {
|
||||||
if (!(username && username.trim() !== "")) return;
|
if (!(username && username.trim() !== "")) return;
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
let pfp = await getAvatarUrl(username);
|
let pfp = await getAvatarUrl(id, username);
|
||||||
|
|
||||||
let actions = "";
|
let actions = "";
|
||||||
let desc = "";
|
let desc = "";
|
||||||
|
|
@ -1032,17 +1032,17 @@ async function renderInvites(res, type) {
|
||||||
if (type === "received") {
|
if (type === "received") {
|
||||||
desc = `:desc.invite.dm.received:${username};${id}`;
|
desc = `:desc.invite.dm.received:${username};${id}`;
|
||||||
actions = `
|
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>
|
<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>
|
||||||
<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>
|
<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>
|
</button>
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
desc = `:desc.invite.dm.sent:${username};${id}`;
|
desc = `:desc.invite.dm.sent:${username};${id}`;
|
||||||
actions = `
|
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>
|
<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>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
@ -1096,10 +1096,15 @@ async function switchInvitesTab(tab) {
|
||||||
|
|
||||||
await loadInvites(tab);
|
await loadInvites(tab);
|
||||||
}
|
}
|
||||||
async function acceptInvite(username) { //TODO
|
async function acceptInvite(targetId) { //TODO: Implement key generation
|
||||||
try {
|
try {
|
||||||
showAction("action.invite.accepting", "invite.action");
|
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");
|
clearAction("invite.action");
|
||||||
showBlahNotification(res || "success:invite.accepted");
|
showBlahNotification(res || "success:invite.accepted");
|
||||||
await loadInvites('received');
|
await loadInvites('received');
|
||||||
|
|
@ -1109,10 +1114,10 @@ async function acceptInvite(username) { //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function declineInvite(username) { //TODO
|
async function declineInvite(username) {
|
||||||
try {
|
try {
|
||||||
showAction("action.invite.declining", "invite.action");
|
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");
|
clearAction("invite.action");
|
||||||
showBlahNotification(res || "success:invite.declined");
|
showBlahNotification(res || "success:invite.declined");
|
||||||
await loadInvites('received');
|
await loadInvites('received');
|
||||||
|
|
@ -1122,10 +1127,10 @@ async function declineInvite(username) { //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function revokeInvite(username) { //TODO
|
async function revokeInvite(username) {
|
||||||
try {
|
try {
|
||||||
showAction("action.invite.revoking", "invite.action");
|
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");
|
clearAction("invite.action");
|
||||||
showBlahNotification(res || "success:invite.revoked");
|
showBlahNotification(res || "success:invite.revoked");
|
||||||
await loadInvites('sent');
|
await loadInvites('sent');
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
--border-width: 0.09rem;
|
--border-width: 0.09rem;
|
||||||
|
|
||||||
--big-default: rgb(207, 207, 207);
|
--big-default: rgb(207, 207, 207);
|
||||||
--big-red: rgb(195, 75, 75);
|
--big-red: hsl(0, 60%, 55%);
|
||||||
--big-green: rgb(75, 165, 95);
|
--big-green: hsl(120, 60%, 55%);
|
||||||
}
|
}
|
||||||
*:focus {
|
*:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
@ -544,6 +544,7 @@ space{
|
||||||
width: 2.8rem;
|
width: 2.8rem;
|
||||||
height: 2.8rem;
|
height: 2.8rem;
|
||||||
border-radius: 0.8rem;
|
border-radius: 0.8rem;
|
||||||
|
border: var(--border-width) solid rgba(255, 255, 255, 0.2);
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
.invite-details {
|
.invite-details {
|
||||||
|
|
@ -565,6 +566,9 @@ space{
|
||||||
}
|
}
|
||||||
.invite-actions button {
|
.invite-actions button {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
border-color: rgba(255, 255, 255, 0.2);
|
||||||
|
width: 3.1rem;
|
||||||
|
height: 3.1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (hover: hover) {
|
@media (hover: hover) {
|
||||||
|
|
@ -591,11 +595,17 @@ space{
|
||||||
.context-menu button:hover {
|
.context-menu button:hover {
|
||||||
background-color: rgba(255, 255, 255, 0.08);
|
background-color: rgba(255, 255, 255, 0.08);
|
||||||
}
|
}
|
||||||
|
.invite-actions button:hover {
|
||||||
|
filter: brightness(0.93);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
button:active, button.is-pressed, input:active, input.is-pressed {
|
button:active, button.is-pressed, input:active, input.is-pressed {
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
transform: var(--press-scale);
|
transform: var(--press-scale);
|
||||||
}
|
}
|
||||||
|
.invite-actions button:active {
|
||||||
|
filter: brightness(0.85);
|
||||||
|
}
|
||||||
button.active, input.active {
|
button.active, input.active {
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue