|
@ -2,8 +2,6 @@ |
|
|
import { content, show_popup } from './Alert/content' |
|
|
import { content, show_popup } from './Alert/content' |
|
|
const showDialog = () => { |
|
|
const showDialog = () => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface ChannelsType { |
|
|
export interface ChannelsType { |
|
|
id: number; |
|
|
id: number; |
|
@ -12,6 +10,11 @@ |
|
|
password: string; |
|
|
password: string; |
|
|
owner: User; |
|
|
owner: User; |
|
|
} |
|
|
} |
|
|
|
|
|
export interface chatMessagesType { |
|
|
|
|
|
id: number; |
|
|
|
|
|
author: User; |
|
|
|
|
|
text: string; |
|
|
|
|
|
} |
|
|
import { onMount } from "svelte"; |
|
|
import { onMount } from "svelte"; |
|
|
import { API_URL, store } from "../Auth"; |
|
|
import { API_URL, store } from "../Auth"; |
|
|
import { socket } from "../socket"; |
|
|
import { socket } from "../socket"; |
|
@ -73,13 +76,23 @@ |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const joinChannel = async (id: number) => { |
|
|
const joinChannel = async (channel: ChannelsType) => { |
|
|
console.log(channels) |
|
|
console.log(channels) |
|
|
socket.emit("joinChannel", { |
|
|
socket.connect(); |
|
|
UserId: $store.ftId, |
|
|
if (!channel.password) { |
|
|
ChannelId: id, |
|
|
socket.emit("joinChannel", { |
|
|
|
|
|
UserId: $store.ftId, |
|
|
}); |
|
|
ChannelId: channel.id, |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
await show_popup("Channel is protected, enter password:") |
|
|
|
|
|
socket.emit("joinChannel", { |
|
|
|
|
|
UserId: $store.ftId, |
|
|
|
|
|
ChannelId: channel.id, |
|
|
|
|
|
pwd: $content, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
console.log("Try to join channel: ", $store.ftId, channel.id, $content) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const getChannels = async () => { |
|
|
const getChannels = async () => { |
|
@ -101,20 +114,31 @@ |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------/ |
|
|
//--------------------------------------------------------------------------------/ |
|
|
|
|
|
|
|
|
export let onSelectChannel: (channel: ChannelsType) => void; |
|
|
|
|
|
|
|
|
export let onSelectChannel: (channel: ChannelsType, messages: Array<chatMessagesType>) => void; |
|
|
|
|
|
let channel: ChannelsType; |
|
|
export const selectChat = (id: number) => { |
|
|
export const selectChat = (id: number) => { |
|
|
console.log("channel: ", id) |
|
|
console.log("channel: ", id) |
|
|
getChannels().then(() => { |
|
|
channel = channels.find((c) => c.id === id); |
|
|
const channel = channels.find((c) => c.id === id); |
|
|
if (channel) { |
|
|
if (channel) { |
|
|
joinChannel(channel); |
|
|
joinChannel(id); |
|
|
} else { |
|
|
onSelectChannel(channel); |
|
|
show_popup("Did not find channel", false) |
|
|
} else { |
|
|
} |
|
|
show_popup("Did not find channel", false) |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
socket.on("messages", (msgs: Array<chatMessagesType>) => { |
|
|
|
|
|
console.log("You are joining channel: ", channel.name) |
|
|
|
|
|
onSelectChannel(channel, msgs); |
|
|
|
|
|
channel = undefined; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on("failedJoin", (error: string) => { |
|
|
|
|
|
show_popup(`Failed to join channel: ${error}`, false) |
|
|
|
|
|
channel = undefined; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const createChannel = async () => { |
|
|
const createChannel = async () => { |
|
|
let name: string; |
|
|
let name: string; |
|
|
let password = ""; |
|
|
let password = ""; |
|
|