diff --git a/back/volume/src/chat/chat.controller.ts b/back/volume/src/chat/chat.controller.ts index cfd20ac..a3573cd 100644 --- a/back/volume/src/chat/chat.controller.ts +++ b/back/volume/src/chat/chat.controller.ts @@ -228,8 +228,8 @@ export class ChatController { } const dms = channels.filter((channel: Channel) => { return ( - (channel.name === (user.username + '&' + other.username) || - channel.name === (other.username + '&' + user.username)) && + (channel.name === (user.ftId + '&' + other.ftId) || + channel.name === (other.ftId + '&' + user.ftId)) && channel.isPrivate && (channel.password === undefined || channel.password === '') ) diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index 70efacd..c89a267 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -40,8 +40,8 @@ export class ChatService { const channels = await this.getChannelsForUser(user.id) const dmAlreadyExists = channels.find((channel: Channel) => { return ( - (channel.name === (user.username + '&' + otherUser.username) || - channel.name === (otherUser.username + '&' + user.username)) && + (channel.name === (user.ftId + '&' + otherUser.ftId) || + channel.name === (otherUser.ftId + '&' + user.ftId)) && channel.isPrivate && (channel.password === undefined || channel.password === '') ) @@ -70,7 +70,7 @@ export class ChatService { newDM.owner = user newDM.users = [user, otherUser] newDM.admins = [] - newDM.name = user.username + '&' + otherUser.username + newDM.name = user.ftId + '&' + otherUser.ftId return newDM } diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 2f2ad41..db33fd9 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -122,7 +122,7 @@ "Content-Type": "application/json", }, body: JSON.stringify({ - name: $store.username + "&" + DMUsername, + name: "none", owner: $store.ftId, password: "", isPrivate: true, diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 885e82a..2af43f4 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -28,7 +28,11 @@ credentials: "include", mode: "cors", }); - if (res.ok) channels = await res.json(); + if (res.ok) { + const newChannels: Array = await res.json(); + await formatChannelNames(newChannels); + channels = newChannels; + } }; let channels: Array = []; @@ -173,6 +177,47 @@ }; //--------------------------------------------------------------------------------/ + + async function formatChannelNames(channel: Array): Promise { + 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") + } + }); + } + } + }