-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clean up script * chat look and feel update * Bicep tweaks
- Loading branch information
Showing
15 changed files
with
136 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Chatr App</title> | ||
|
||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].2/css/bulma.min.css" /> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].3/css/bulma.min.css" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" /> | ||
|
||
|
@@ -25,20 +25,21 @@ | |
<!-- Main app --> | ||
<section class="section" id="app"> | ||
<!-- display spinner if we're not online yet --> | ||
<div v-if="!online || !user || !ws" class="loaderOverlay"> | ||
<div v-if="(!online || !user || !ws) && !error" class="loaderOverlay"> | ||
<div class="loader">Loading...</div> | ||
</div> | ||
|
||
<div class="notification is-danger" v-if="error">{{ error }}</div> | ||
<div class="columns" v-if="ws"> | ||
|
||
<div class="columns" v-if="ws && !error"> | ||
<!-- box for group chats --> | ||
<div class="column"> | ||
<div class="title is-4"> | ||
Group Chats | ||
<button @click="newChat()" class="button is-info is-pulled-right"><i class="fas fa-comment-dots"></i> New Chat</button> | ||
</div> | ||
|
||
<aside class="menu chatMenu box"> | ||
<aside class="menu chatMenu box" ref="chatList"> | ||
<ul class="menu-list"> | ||
<li v-for="(chat, chatId) in allChats" > | ||
<a class="animate__animated animate__bounceIn" @click.stop="joinChat(chatId, chat.name)"> | ||
|
@@ -134,6 +135,6 @@ | |
|
||
</section> | ||
|
||
<footer>Chatr v0.0.9, Ben Coleman 2021 <a href="https://github.com/benc-uk/chatr" target="_blank">[GitHub Project]</a></footer> | ||
<footer>Chatr v0.1.0, Ben Coleman 2021 <a href="https://github.com/benc-uk/chatr" target="_blank">[GitHub Project]</a></footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ import Vue from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.esm.browser.js | |
export default Vue.component('chat', { | ||
data() { | ||
return { | ||
chatText: '', | ||
message: '', | ||
connected: false, | ||
chats: [], | ||
} | ||
}, | ||
|
||
|
@@ -15,8 +15,7 @@ export default Vue.component('chat', { | |
id: String, | ||
active: Boolean, | ||
user: Object, | ||
// This is shared with the parent app component | ||
ws: WebSocket, | ||
ws: WebSocket, // This is shared with the parent app component | ||
}, | ||
|
||
async mounted() { | ||
|
@@ -31,7 +30,7 @@ export default Vue.component('chat', { | |
|
||
// User sent messages, i.e. from sendMessage() below | ||
if (msg.data.message && msg.data.fromUserName) { | ||
this.appendChat(`<b>${msg.data.fromUserName}:</b> ${msg.data.message}`) | ||
this.appendChat(msg.data.message, msg.data.fromUserName) | ||
break | ||
} | ||
|
||
|
@@ -50,8 +49,12 @@ export default Vue.component('chat', { | |
}, | ||
|
||
methods: { | ||
appendChat(text) { | ||
this.chatText += `${text}<br/>` | ||
appendChat(text, from = null) { | ||
this.chats.push({ | ||
text, | ||
from, | ||
time: new Date(), | ||
}) | ||
|
||
// eslint-disable-next-line no-undef | ||
Vue.nextTick(() => { | ||
|
@@ -91,6 +94,13 @@ export default Vue.component('chat', { | |
<button class="button is-warning" @click="$emit('leave', id)"><i class="far fa-times-circle"></i><span class="is-hidden-mobile"> Leave</span></button> | ||
</div> | ||
<div class="chatBox" contentEditable="false" readonly v-html="chatText" ref="chatBox"></div> | ||
<div class="chatBox" contentEditable="false" readonly ref="chatBox"> | ||
<div v-for="chat of chats" class="chatMsgRow" :class="{chatRight: user.userDetails == chat.from}"> | ||
<div class="card m-3 p-2 chatMsg"> | ||
<div class="chatMsgTitle text-info" v-if="chat.from">{{ chat.from }}</div> | ||
<div class="chatMsgBody" v-html="chat.text"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div>`, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!node | ||
const state = require('../api/state') | ||
|
||
const DELETE_AGE = process.argv[2] !== undefined ? parseInt(process.argv[2]) : 24 | ||
console.log(`### Deleting data older than ${DELETE_AGE} hours`) | ||
|
||
console.log('### Cleaning up old users') | ||
state.listUsers().then((users) => { | ||
for (let userId in users) { | ||
const user = users[userId] | ||
|
||
const timestamp = new Date(user.timestamp) | ||
const now = new Date() | ||
const ageInHours = (now.getTime() - timestamp.getTime()) / (1000 * 60 * 60) | ||
|
||
if (ageInHours > DELETE_AGE) { | ||
console.log(`### Deleting user ${user.userName} with age of ${ageInHours} hours`) | ||
state.removeUser(userId) | ||
} | ||
} | ||
}) | ||
|
||
console.log('### Cleaning up old chats') | ||
state.listChats().then((chats) => { | ||
for (let chatId in chats) { | ||
const chat = chats[chatId] | ||
|
||
const timestamp = new Date(chat.timestamp) | ||
const now = new Date() | ||
const ageInHours = (now.getTime() - timestamp.getTime()) / (1000 * 60 * 60) | ||
|
||
if (ageInHours > DELETE_AGE) { | ||
console.log(`### Deleting chat ${chat.name} with age of ${ageInHours} hours`) | ||
state.removeChat(chatId) | ||
} | ||
} | ||
}) |