|
@ -56,7 +56,7 @@ |
|
|
<script lang="ts"> |
|
|
<script lang="ts"> |
|
|
//--------------------------------------------------------------------------------/ |
|
|
//--------------------------------------------------------------------------------/ |
|
|
let channelMode = ""; |
|
|
let channelMode = ""; |
|
|
const channelOptions = ["public", "private", "direct"]; |
|
|
const channelOptions = ["public", "private"]; |
|
|
|
|
|
|
|
|
const joinChannel = async (id: number) => { |
|
|
const joinChannel = async (id: number) => { |
|
|
socket.emit("joinChannel", { |
|
|
socket.emit("joinChannel", { |
|
@ -99,25 +99,12 @@ |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const createChannel = async () => { |
|
|
const createChannel = async () => { |
|
|
let name, friend; |
|
|
let name; |
|
|
if (channelMode === "direct") { |
|
|
name = prompt("Enter a name for the new channel:"); |
|
|
friend = prompt("Invite a friend to your channel:"); |
|
|
|
|
|
const response = await fetch(API_URL + "/users/" + friend + "/byname", { |
|
|
|
|
|
credentials: "include", |
|
|
|
|
|
method: "GET", |
|
|
|
|
|
mode: "cors",}); |
|
|
|
|
|
if (!response.ok) { |
|
|
|
|
|
alert("Error getting user infos"); |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else name = prompt("Enter a name for the new channel:"); |
|
|
|
|
|
if (name) { |
|
|
if (name) { |
|
|
let password = ""; |
|
|
let password = ""; |
|
|
if (channelMode === "private") |
|
|
password = prompt("Enter a password for the new channel:"); |
|
|
password = prompt("Enter a password for the new channel:"); |
|
|
name = "🚪 " + name; |
|
|
if (friend !== undefined) name = "💬 " + $store.username + "/" + friend; |
|
|
|
|
|
else name = "🚪 " + name; |
|
|
|
|
|
const response = await fetch(API_URL + "/channels", { |
|
|
const response = await fetch(API_URL + "/channels", { |
|
|
credentials: "include", |
|
|
credentials: "include", |
|
|
method: "POST", |
|
|
method: "POST", |
|
@ -129,20 +116,10 @@ |
|
|
name: name, |
|
|
name: name, |
|
|
owner: $store.ftId, |
|
|
owner: $store.ftId, |
|
|
password: password, |
|
|
password: password, |
|
|
isPrivate: channelMode === "private" || channelMode === "direct", |
|
|
isPrivate: channelMode === "private", |
|
|
direct: friend, |
|
|
|
|
|
}), |
|
|
}), |
|
|
}); |
|
|
}); |
|
|
if (response.ok) { |
|
|
if (!response.ok) alert("Error creating channel"); |
|
|
channels.push(await response.json()); |
|
|
|
|
|
} else { |
|
|
|
|
|
alert("Error creating channel"); |
|
|
|
|
|
} |
|
|
|
|
|
const res = await fetch(API_URL + "/channels", { |
|
|
|
|
|
credentials: "include", |
|
|
|
|
|
mode: "cors", |
|
|
|
|
|
}); |
|
|
|
|
|
if (res.ok) channels = await res.json(); |
|
|
|
|
|
getChannels() |
|
|
getChannels() |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -238,7 +215,10 @@ |
|
|
{#if channel.isPrivate == true} |
|
|
{#if channel.isPrivate == true} |
|
|
<button on:click={() => inviteChannel(channel.id)}>🤝</button> |
|
|
<button on:click={() => inviteChannel(channel.id)}>🤝</button> |
|
|
{/if} |
|
|
{/if} |
|
|
|
|
|
{#if channel.password !== ''} |
|
|
<button on:click={() => changePassword(channel.id)}>🔑</button> |
|
|
<button on:click={() => changePassword(channel.id)}>🔑</button> |
|
|
|
|
|
{/if} |
|
|
|
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</li> |
|
|
</li> |
|
|
{/each} |
|
|
{/each} |
|
|