forked from hippoz/brainlet
implement client side message list
This commit is contained in:
parent
893b1d4ff6
commit
514ca2dd2b
1 changed files with 13 additions and 3 deletions
|
@ -151,7 +151,14 @@ const app = new Vue({
|
||||||
username: '',
|
username: '',
|
||||||
role: ''
|
role: ''
|
||||||
},
|
},
|
||||||
gateway: new GatewayConnection()
|
gateway: new GatewayConnection(),
|
||||||
|
viewingChat: {
|
||||||
|
show: false,
|
||||||
|
categoryId: 'X'
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
'X': [ { username: 'NONEXISTENT_TEST_ACCOUNT', content: 'TEST MSG' } ]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted: async function() {
|
mounted: async function() {
|
||||||
const res = await fetch(`${window.location.origin}/api/v1/users/current/info`, {
|
const res = await fetch(`${window.location.origin}/api/v1/users/current/info`, {
|
||||||
|
@ -220,14 +227,17 @@ const app = new Vue({
|
||||||
};
|
};
|
||||||
this.gateway.onConnect = () => {
|
this.gateway.onConnect = () => {
|
||||||
this.gateway.socket.on('message', ({ username, categoryId, content }) => {
|
this.gateway.socket.on('message', ({ username, categoryId, content }) => {
|
||||||
this.showMessageNotification(username, content);
|
this.showMessageNotification(categoryId, username, content);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
this.gateway.connect(this.loggedInUser.token);
|
this.gateway.connect(this.loggedInUser.token);
|
||||||
},
|
},
|
||||||
showMessageNotification: async function(username, content) {
|
showMessageNotification: async function(categoryId, username, content) {
|
||||||
this.resetSnackbarButton();
|
this.resetSnackbarButton();
|
||||||
this.notification(`${username}: ${content}`);
|
this.notification(`${username}: ${content}`);
|
||||||
|
|
||||||
|
if (!this.messages[categoryId]) this.messages[categoryId] = []
|
||||||
|
this.messages[categoryId].push({ username, content });
|
||||||
},
|
},
|
||||||
button: function(text, click) {
|
button: function(text, click) {
|
||||||
this.cardButtons.push({ text, click });
|
this.cardButtons.push({ text, click });
|
||||||
|
|
Loading…
Reference in a new issue