This commit is contained in:
Troplo 2022-10-25 17:24:51 +11:00
parent 5edbd5ad4d
commit fa26fafcde
5 changed files with 56 additions and 25 deletions

View file

@ -17,6 +17,7 @@ module.exports = {
} }
}) })
if (user && socket.user.id) { if (user && socket.user.id) {
console.log(user.id + " client connect")
console.log(socket.user.id) console.log(socket.user.id)
socket.join(user.id) socket.join(user.id)
socket.emit("siteState", { socket.emit("siteState", {
@ -48,6 +49,7 @@ module.exports = {
}) })
}) })
socket.on("ping", () => { socket.on("ping", () => {
console.log(user.id + " client ping")
socket.emit("pong") socket.emit("pong")
}) })
socket.on("bcBots/deleteMessage", (e) => { socket.on("bcBots/deleteMessage", (e) => {
@ -60,11 +62,7 @@ module.exports = {
} }
}) })
socket.on("idle", async () => { socket.on("idle", async () => {
const user = await User.findOne({ console.log(user.id + " client online")
where: {
id: socket.user.id
}
})
if (user.storedStatus === "online") { if (user.storedStatus === "online") {
friends.forEach((friend) => { friends.forEach((friend) => {
io.to(friend.friendId).emit("userStatus", { io.to(friend.friendId).emit("userStatus", {
@ -82,11 +80,7 @@ module.exports = {
} }
}) })
socket.on("online", async () => { socket.on("online", async () => {
const user = await User.findOne({ console.log(user.id + " client online")
where: {
id: socket.user.id
}
})
if (user.storedStatus === "online") { if (user.storedStatus === "online") {
friends.forEach((friend) => { friends.forEach((friend) => {
io.to(friend.friendId).emit("userStatus", { io.to(friend.friendId).emit("userStatus", {
@ -104,6 +98,7 @@ module.exports = {
} }
}) })
socket.on("disconnect", async function () { socket.on("disconnect", async function () {
console.log(user.id + " client disconnected")
const clients = io.sockets.adapter.rooms.get(user.id) || new Set() const clients = io.sockets.adapter.rooms.get(user.id) || new Set()
if (!clients.size || clients.size === 0) { if (!clients.size || clients.size === 0) {
friends.forEach((friend) => { friends.forEach((friend) => {

View file

@ -1,6 +1,6 @@
{ {
"name": "colubrina", "name": "colubrina",
"version": "1.0.32", "version": "1.0.33",
"description": "Simple instant communication.", "description": "Simple instant communication.",
"private": true, "private": true,
"author": "Troplo <troplo@troplo.com>", "author": "Troplo <troplo@troplo.com>",

View file

@ -490,6 +490,15 @@ export default {
touchEndX: null touchEndX: null
}), }),
computed: { computed: {
/*chat() {
try {
return this.$store.state.chats.find(
(item) => item.id === parseInt(this.$route.params.id)
)
} catch {
return null
}
},*/
creatorJSON: { creatorJSON: {
get() { get() {
return JSON.stringify(this.$store.state.themeEngine.theme) return JSON.stringify(this.$store.state.themeEngine.theme)

View file

@ -545,11 +545,11 @@
Debug Debug
</button> </button>
<template v-if="$route.name === 'Communications'"> <template v-if="$route.name === 'Communications'">
<v-toolbar-title v-if="$store.state.selectedChat?.chat?.type"> <v-toolbar-title v-if="chat?.chat?.type">
{{ {{
$store.state.selectedChat?.chat?.type === "direct" chat?.chat?.type === "direct"
? getDirectRecipient($store.state.selectedChat).username ? getDirectRecipient(chat).username
: $store.state.selectedChat?.chat?.name : chat?.chat?.name
}} }}
</v-toolbar-title> </v-toolbar-title>
<v-spacer></v-spacer> <v-spacer></v-spacer>
@ -954,6 +954,15 @@ export default {
} }
}, },
computed: { computed: {
chat() {
try {
return this.$store.state.chats.find(
(item) => item.id === parseInt(this.$route.params.id)
)
} catch {
return null
}
},
chats() { chats() {
if (!this.search?.length) { if (!this.search?.length) {
return this.$store.state.chats return this.$store.state.chats

View file

@ -1160,11 +1160,13 @@ export default {
this.message = drafts[this.$route.params.id] this.message = drafts[this.$route.params.id]
} }
this.$socket.on("readChat", (data) => { this.$socket.on("readChat", (data) => {
if (data.id === this.chat.id) { if (!this.chat) return
if (data.id === this.chat?.id) {
this.lastRead = data.lastRead this.lastRead = data.lastRead
} }
}) })
this.$socket.on("readReceipt", (data) => { this.$socket.on("readReceipt", (data) => {
if (!this.chat) return
try { try {
if ( if (
data.messageId && data.messageId &&
@ -1186,6 +1188,8 @@ export default {
} }
}) })
this.$socket.on("message", (message) => { this.$socket.on("message", (message) => {
try {
if (!this.chat) return
if (message.chatId === this.chat.chatId) { if (message.chatId === this.chat.chatId) {
this.messages.push(message) this.messages.push(message)
this.autoScroll() this.autoScroll()
@ -1197,6 +1201,9 @@ export default {
this.reachedTop = false this.reachedTop = false
} }
} }
} catch (e) {
console.log("Message error", e)
}
}) })
this.$socket.on("editMessage", (message) => { this.$socket.on("editMessage", (message) => {
if (message.chatId === this.chat.chatId) { if (message.chatId === this.chat.chatId) {
@ -1248,6 +1255,17 @@ export default {
userPanel() { userPanel() {
localStorage.setItem("userPanel", JSON.stringify(this.userPanel)) localStorage.setItem("userPanel", JSON.stringify(this.userPanel))
}, },
"$route.path"() {
const tryParse = this.$route.params.id
if (!tryParse) {
// remove event listeners
document.removeEventListener("keypress", this.focusKey)
document
.getElementById("message-list")
.removeEventListener("scroll", this.scrollEvent)
clearInterval(this.interval)
}
},
"$route.params.id"(val, oldVal) { "$route.params.id"(val, oldVal) {
this.focusInput() this.focusInput()
let drafts = {} let drafts = {}