✨ Site > Chat > Add user update
This commit is contained in:
+7
-9
@@ -42,11 +42,11 @@ class Chat
|
|||||||
console.log('chat > user'.green.bold + ' - ' + 'create'.cyan + ' - ' + user.name.cyan)
|
console.log('chat > user'.green.bold + ' - ' + 'create'.cyan + ' - ' + user.name.cyan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send infos
|
// Send user infos
|
||||||
const broadcastUser = {}
|
const broadcastUser = {}
|
||||||
broadcastUser.name = user.name
|
broadcastUser.name = user.name
|
||||||
broadcastUser.color = user.color
|
broadcastUser.color = user.color
|
||||||
socket.emit('infos', broadcastUser)
|
socket.emit('user', broadcastUser)
|
||||||
|
|
||||||
// On message
|
// On message
|
||||||
socket.on('message', (data) =>
|
socket.on('message', (data) =>
|
||||||
@@ -74,8 +74,8 @@ class Chat
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// On update infos
|
// On update user
|
||||||
socket.on('update_infos', (data) =>
|
socket.on('update_user', (data) =>
|
||||||
{
|
{
|
||||||
const newName = data.name.trim()
|
const newName = data.name.trim()
|
||||||
const oldName = user.name
|
const oldName = user.name
|
||||||
@@ -92,7 +92,7 @@ class Chat
|
|||||||
// Debug
|
// Debug
|
||||||
if(this.config.debug >= 1)
|
if(this.config.debug >= 1)
|
||||||
{
|
{
|
||||||
console.log('chat > socket'.green.bold + ' - ' + 'update_infos'.cyan + ' - ' + (oldName + ' > ' + user.name).cyan)
|
console.log('chat > socket'.green.bold + ' - ' + 'update_user'.cyan + ' - ' + (oldName + ' > ' + user.name).cyan)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -161,11 +161,11 @@ class Chat
|
|||||||
// Create user A
|
// Create user A
|
||||||
const userA = this.createUser()
|
const userA = this.createUser()
|
||||||
|
|
||||||
// Send infos
|
// Send user infos
|
||||||
const broadcastUser = {}
|
const broadcastUser = {}
|
||||||
broadcastUser.name = userA.name
|
broadcastUser.name = userA.name
|
||||||
broadcastUser.color = userA.color
|
broadcastUser.color = userA.color
|
||||||
this.chatSocket.emit('infos', broadcastUser)
|
this.chatSocket.emit('user', broadcastUser)
|
||||||
|
|
||||||
let counting = 0
|
let counting = 0
|
||||||
setInterval(() =>
|
setInterval(() =>
|
||||||
@@ -188,8 +188,6 @@ class Chat
|
|||||||
broadcastMessage.user = userA
|
broadcastMessage.user = userA
|
||||||
|
|
||||||
this.chatSocket.emit('message', broadcastMessage)
|
this.chatSocket.emit('message', broadcastMessage)
|
||||||
|
|
||||||
console.log('message')
|
|
||||||
}, 1500)
|
}, 1500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<template src="./template.html"></template>
|
||||||
|
<script src="./script.js"></script>
|
||||||
|
<style src="./style.styl" lang="stylus" scoped></style>
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
export default
|
||||||
|
{
|
||||||
|
name: 'chat',
|
||||||
|
|
||||||
|
data()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
userName: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
computed:
|
||||||
|
{
|
||||||
|
messages()
|
||||||
|
{
|
||||||
|
return this.$store.state.chatMessages
|
||||||
|
},
|
||||||
|
|
||||||
|
user()
|
||||||
|
{
|
||||||
|
return this.$store.state.user
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch:
|
||||||
|
{
|
||||||
|
user(value)
|
||||||
|
{
|
||||||
|
this.userName = value.name
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted()
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
methods:
|
||||||
|
{
|
||||||
|
onUserNameChange()
|
||||||
|
{
|
||||||
|
this.$store.commit('askUpdateUser', { name: this.userName })
|
||||||
|
},
|
||||||
|
|
||||||
|
onUserNameKeyDown(event)
|
||||||
|
{
|
||||||
|
// Blur if enter pressed
|
||||||
|
if(event.keyCode === 13)
|
||||||
|
{
|
||||||
|
event.target.blur()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
.chat
|
||||||
|
position fixed
|
||||||
|
bottom 0
|
||||||
|
right 20px
|
||||||
|
|
||||||
|
.user-name
|
||||||
|
outline none
|
||||||
|
border none
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<div class="chat">
|
||||||
|
<header>
|
||||||
|
Discussions
|
||||||
|
</header>
|
||||||
|
<div class="messages">
|
||||||
|
<div class="message" v-for="message of messages" :key="message.id">
|
||||||
|
<div class="date">
|
||||||
|
{{ message.time }}
|
||||||
|
</div>
|
||||||
|
<div class="user" :style="`color: ${message.user.color};`">
|
||||||
|
{{ message.user.name }}
|
||||||
|
</div>
|
||||||
|
<div class="text">
|
||||||
|
{{ message.text }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="infos" v-if="user">
|
||||||
|
Your nickname is <input class="user-name" :style="`color: ${user.color};`" v-model="userName" @change="onUserNameChange($event)" @keydown="onUserNameKeyDown($event)"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -9,12 +9,18 @@ export default
|
|||||||
project()
|
project()
|
||||||
{
|
{
|
||||||
return this.$store.state.project
|
return this.$store.state.project
|
||||||
|
},
|
||||||
|
|
||||||
|
pendingUser()
|
||||||
|
{
|
||||||
|
return this.$store.state.pendingUser
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
{
|
{
|
||||||
project: 'onProjectChange'
|
project: 'onProjectChange',
|
||||||
|
pendingUser: 'onPendingUser'
|
||||||
},
|
},
|
||||||
|
|
||||||
created()
|
created()
|
||||||
@@ -29,7 +35,6 @@ export default
|
|||||||
|
|
||||||
this.projectsSocket.on('update_projects', (data) =>
|
this.projectsSocket.on('update_projects', (data) =>
|
||||||
{
|
{
|
||||||
// console.log('update_projects', data)
|
|
||||||
this.$store.commit('updateProjects', data.all)
|
this.$store.commit('updateProjects', data.all)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -38,6 +43,12 @@ export default
|
|||||||
{
|
{
|
||||||
onProjectChange(value)
|
onProjectChange(value)
|
||||||
{
|
{
|
||||||
|
if(!value)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Project socket
|
||||||
const projectURL = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/project/${value.slug}`
|
const projectURL = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/project/${value.slug}`
|
||||||
|
|
||||||
this.projectSocket = socketIoClient(projectURL)
|
this.projectSocket = socketIoClient(projectURL)
|
||||||
@@ -66,6 +77,31 @@ export default
|
|||||||
{
|
{
|
||||||
this.$store.commit('createVersion', data)
|
this.$store.commit('createVersion', data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Chat socket
|
||||||
|
const chatURL = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/project/${value.slug}/chat`
|
||||||
|
|
||||||
|
this.chatSocket = socketIoClient(chatURL)
|
||||||
|
|
||||||
|
this.chatSocket.on('connect', () =>
|
||||||
|
{
|
||||||
|
// console.log('chat connected')
|
||||||
|
})
|
||||||
|
|
||||||
|
this.chatSocket.on('user', (data) =>
|
||||||
|
{
|
||||||
|
this.$store.commit('updateUser', data)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.chatSocket.on('message', (data) =>
|
||||||
|
{
|
||||||
|
this.$store.commit('createMessage', data)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onPendingUser(value)
|
||||||
|
{
|
||||||
|
this.chatSocket.emit('update_user', value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import FilesTree from '@/components/files-tree'
|
import FilesTree from '@/components/files-tree'
|
||||||
import File from '@/components/file'
|
import File from '@/components/file'
|
||||||
|
import Chat from '@/components/chat'
|
||||||
|
|
||||||
export default
|
export default
|
||||||
{
|
{
|
||||||
@@ -8,7 +9,8 @@ export default
|
|||||||
components:
|
components:
|
||||||
{
|
{
|
||||||
FilesTree,
|
FilesTree,
|
||||||
File
|
File,
|
||||||
|
Chat
|
||||||
},
|
},
|
||||||
|
|
||||||
computed:
|
computed:
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
|
|
||||||
<files-tree></files-tree>
|
<files-tree></files-tree>
|
||||||
<file v-if="file" :content="file.data"></file>
|
<file v-if="file" :content="file.data"></file>
|
||||||
|
<chat></chat>
|
||||||
</div>
|
</div>
|
||||||
+30
-1
@@ -11,7 +11,10 @@ export default new Vuex.Store({
|
|||||||
project: null,
|
project: null,
|
||||||
files: new FileTree({ autoWash: true }),
|
files: new FileTree({ autoWash: true }),
|
||||||
file: null,
|
file: null,
|
||||||
version: null
|
version: null,
|
||||||
|
chatMessages: [],
|
||||||
|
user: null,
|
||||||
|
pendingUser: null
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations:
|
mutations:
|
||||||
@@ -106,6 +109,32 @@ export default new Vuex.Store({
|
|||||||
setVersion(state, data)
|
setVersion(state, data)
|
||||||
{
|
{
|
||||||
state.version = data
|
state.version = data
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Messages
|
||||||
|
*/
|
||||||
|
createMessage(state, data)
|
||||||
|
{
|
||||||
|
state.chatMessages.push(data)
|
||||||
|
|
||||||
|
if(state.chatMessages.length > 100)
|
||||||
|
{
|
||||||
|
state.chatMessages.splice(0, state.chatMessages.length - 100)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User
|
||||||
|
*/
|
||||||
|
updateUser(state, data)
|
||||||
|
{
|
||||||
|
state.user = data
|
||||||
|
},
|
||||||
|
|
||||||
|
askUpdateUser(state, data)
|
||||||
|
{
|
||||||
|
state.pendingUser = data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user