Browse Source

* DMs no wuse ftIds instead of usernames

master
vvandenb 2 years ago
parent
commit
e80464f076
  1. 4
      back/volume/src/chat/chat.controller.ts
  2. 6
      back/volume/src/chat/chat.service.ts
  3. 2
      front/volume/src/App.svelte
  4. 47
      front/volume/src/components/Channels.svelte

4
back/volume/src/chat/chat.controller.ts

@ -228,8 +228,8 @@ export class ChatController {
} }
const dms = channels.filter((channel: Channel) => { const dms = channels.filter((channel: Channel) => {
return ( return (
(channel.name === (user.username + '&' + other.username) || (channel.name === (user.ftId + '&' + other.ftId) ||
channel.name === (other.username + '&' + user.username)) && channel.name === (other.ftId + '&' + user.ftId)) &&
channel.isPrivate && channel.isPrivate &&
(channel.password === undefined || channel.password === '') (channel.password === undefined || channel.password === '')
) )

6
back/volume/src/chat/chat.service.ts

@ -40,8 +40,8 @@ export class ChatService {
const channels = await this.getChannelsForUser(user.id) const channels = await this.getChannelsForUser(user.id)
const dmAlreadyExists = channels.find((channel: Channel) => { const dmAlreadyExists = channels.find((channel: Channel) => {
return ( return (
(channel.name === (user.username + '&' + otherUser.username) || (channel.name === (user.ftId + '&' + otherUser.ftId) ||
channel.name === (otherUser.username + '&' + user.username)) && channel.name === (otherUser.ftId + '&' + user.ftId)) &&
channel.isPrivate && channel.isPrivate &&
(channel.password === undefined || channel.password === '') (channel.password === undefined || channel.password === '')
) )
@ -70,7 +70,7 @@ export class ChatService {
newDM.owner = user newDM.owner = user
newDM.users = [user, otherUser] newDM.users = [user, otherUser]
newDM.admins = [] newDM.admins = []
newDM.name = user.username + '&' + otherUser.username newDM.name = user.ftId + '&' + otherUser.ftId
return newDM return newDM
} }

2
front/volume/src/App.svelte

@ -122,7 +122,7 @@
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name: $store.username + "&" + DMUsername, name: "none",
owner: $store.ftId, owner: $store.ftId,
password: "", password: "",
isPrivate: true, isPrivate: true,

47
front/volume/src/components/Channels.svelte

@ -28,7 +28,11 @@
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
}); });
if (res.ok) channels = await res.json(); if (res.ok) {
const newChannels: Array<ChannelsType> = await res.json();
await formatChannelNames(newChannels);
channels = newChannels;
}
}; };
let channels: Array<ChannelsType> = []; let channels: Array<ChannelsType> = [];
@ -173,6 +177,47 @@
}; };
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
async function formatChannelNames(channel: Array<ChannelsType>): Promise<void> {
const res = await fetch(API_URL + "/users/all", {
credentials: "include",
mode: "cors",
})
if (res.ok) {
const users = await res.json()
if (users) {
channel.forEach((channel) => {
let channelName = channel.name;
if (channelName.startsWith("🚪 ")) return;
const split = channelName.split("&");
if (split.length > 1) {
const firstID = parseInt(split[0]);
const secondID = parseInt(split[1]);
let newChannelName = channelName;
users.forEach((user) => {
if (user.ftId === firstID) {
newChannelName = newChannelName.replace(
split[0],
user.username
);
}
if (user.ftId === secondID) {
newChannelName = newChannelName.replace(
split[1],
user.username
);
}
});
channel.name = newChannelName;
} else {
console.log("Could not format channel name")
}
});
}
}
}
</script> </script>
<div class="overlay"> <div class="overlay">

Loading…
Cancel
Save