Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
feat: Invites and better bans page
Browse files Browse the repository at this point in the history
  • Loading branch information
showierdata9978 committed Dec 13, 2023
1 parent 2d3882e commit c358a4f
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 6 deletions.
30 changes: 26 additions & 4 deletions src/lib/modals/chats/BannedMembers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Modal from "../../Modal.svelte";
import * as modals from "../../modals"
import Spinner from '../../Spinner.svelte';
import Container from '../../Container.svelte';
async function fetchBannedMembers() {
const resp = await fetch(`${apiUrl}chats/${$chat._id}/bans`, {
Expand Down Expand Up @@ -33,18 +34,20 @@

{#each $chat.banned_users as member}

<p>
<Container>
<Member member={member.username} owner={false} />
Reason: {member.message}
<div class="inline">
<p> Reason: {member.message} </p>

<button on:click={() => {
<button class="delete" on:click={() => {
fetch(`${apiUrl}chats/${$chat._id}/bans/${member.username}`, {
method: "DELETE",
headers: $authHeader
})
modals.closeLastModal()
}} >Unban</button>
</p>
</div>
</Container>
{/each}
{/await}
</div>
Expand All @@ -56,4 +59,23 @@
justify-content: center;
text-align: center;
}
.delete {
justify-content: right;
flex: right;
height: 100%;
}
.inline {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: left;
vertical-align: middle;
}
.inline p {
justify-self: center;
align-self: center;
}
</style>
94 changes: 94 additions & 0 deletions src/lib/modals/chats/Invites.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<script>
import Invites from './Invites.svelte';
import { chat, authHeader } from './../../stores.js';
import Spinner from './../../Spinner.svelte';
import { apiUrl } from '../../urls';
import Modal from "../../Modal.svelte";
import * as modals from "../../modals";
import { writable } from 'svelte/store';
import Container from '../../Container.svelte';
if (!$chat.invites) $chat.invites = [];
// @ts-ignore
if ((typeof $chat.invites) != 'Array') $chat.invites = [];
async function fetchInvites() {
let data = await (await fetch(`${apiUrl}chats/${$chat._id}/invites`, {
headers: $authHeader
})).json();
console.log(data)
$chat.invites = data.invites;
}
</script>

<Modal on:close={modals.closeLastModal}>
<h1 slot="header">
Chat Invites
</h1>

<div slot="default">
{#await fetchInvites()}
<Spinner />
{/await}

{#each $chat.invites as invite}
<Container>
<div class="inline">
<a href="https://app.meower.org/invite/{invite._id}" target="_blank">
https://app.meower.org/invite/{invite._id}
</a>
<div class="delete">
<button class="right_align"
on:click|preventDefault={() => {
fetch(`${apiUrl}chats/invites/${invite._id}`, {
method: 'DELETE',
headers: $authHeader
});
modals.closeLastModal();
}}
>
Revoke Invite
</button>
</div>
</div>

</Container>
{/each}
<hr>
<button on:click|preventDefault={async () => {
let invite = await (await fetch(`${apiUrl}chats/${$chat._id}/invites`, {
method: 'POST',
headers: $authHeader
})).json();


$chat.invites = [...$chat.invites, {_id: invite.invite, chat_id: $chat._id}];
}} >Create Invite</button>
</div>

</Modal>

<style>
.right_align {
align-self: right;
}
.delete {
justify-content: right;
flex: right;
}
.inline {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: left;
vertical-align: middle;
}
.inline a {
justify-self: center;
align-self: center;
}
</style>
1 change: 1 addition & 0 deletions src/lib/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const chat = writable({
last_active: 0,
deleted: false,
banned_users: [],
invites: []
});

// User list
Expand Down
12 changes: 10 additions & 2 deletions src/pages/chats/[chatid].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Home but it's a group chat.
-->
<script>
import Invites from './../../lib/modals/chats/Invites.svelte';
import BasicModal from "../../lib/modals/Basic.svelte";
import ChangeChatNicknameModal from "../../lib/modals/chats/ChangeChatNickname.svelte";
import GCMemberModal from "../../lib/modals/chats/GCMember.svelte";
Expand All @@ -26,7 +27,7 @@
import PostList from "../../lib/PostList.svelte";
import {params, goto} from "@roxi/routify";
import {onMount, onDestroy} from "svelte/internal";
import {onMount, onDestroy, prevent_default} from "svelte/internal";
import BannedMembers from "../../lib/modals/chats/BannedMembers.svelte";
let chatsStoreSubscription;
Expand All @@ -44,7 +45,8 @@
created: 0,
last_active: 0,
deleted: false,
banned_users: []
banned_users: [],
invites: []
});
clm.link.send({
Expand Down Expand Up @@ -142,6 +144,7 @@
last_active: 0,
deleted: false,
banned_users: [],
invites: []
});
});
</script>
Expand Down Expand Up @@ -185,6 +188,11 @@
)}>
<b>B</b>
</button>
<button class="circle" on:click|preventDefault={() => {
modals.showModal(Invites, {})
}}>
<b>I</b>
</button>
<button
class="circle settings"
on:click={() => {
Expand Down
51 changes: 51 additions & 0 deletions src/pages/invite/[invite].svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script>
import {authHeader, chats, user} from "./../../lib/stores.js";
import {apiUrl} from "../../lib/urls";
import {params, goto} from "@roxi/routify";
import {onMount} from "svelte";
import Container from "../../lib/Container.svelte";
import Spinner from "../../lib/Spinner.svelte";
import { writable } from "svelte/store";
let ok = writable(true);
onMount(() => {
(async () => {
let response = await fetch(
`${apiUrl}chats/join/${$params.invite}`,
{
method: "GET",
headers: {
...$authHeader,
},
}
);
if (response.status === 404) {
$goto("/404");
} else if (!response.ok) {
$goto("/500");
}
let data = await response.json();
// Cursed code because the server does not seem to want to send a packet
$chats.findLast(
chat => chat._id === data.chat
).members.push($user.name);
$goto(`/chats/${data.chat}`);
})();
});
</script>

<Container>
<h1>Joining Invite...</h1>

{#if $ok}
<Spinner />
{:else}
<h1>Invalid Invite</h1>

Or you could have been banned.
{/if}
</Container>

0 comments on commit c358a4f

Please sign in to comment.