Added some realtime events to the app

* When a user gets a new shared message, it will popup instantly
* When a new website is scraped, it will update in real time
* Various other little bug fixes and improvements
* Sharing displays correct notes and handles shared notes correctly
* Tags were not displaying on notes, they do now. They better.
This commit is contained in:
Max G committed 2020-02-14 01:08:46 +00:00
1 parent a51d81b013
commit daa674c54f
14 files changed
+247 -46

No files matched your search

+31 -11
View File
@@ -15,9 +15,10 @@ ShareNote.addUser = (userId, noteId, rawTextId, username) => {
let shareUserId = null
let newNoteShare = null
const cleanUser = username.toLowerCase().trim()
//Check that user actually exists
db.promise().query(`SELECT id FROM user WHERE username = ?`, [username])
db.promise().query(`SELECT id FROM user WHERE LOWER(username) = ?`, [cleanUser])
.then((rows, fields) => {
if(rows[0].length == 0){
@@ -69,11 +70,17 @@ ShareNote.addUser = (userId, noteId, rawTextId, username) => {
})
.then((rows, fields) => {
//Update note share status to 2
return db.promise()
.query('UPDATE note SET shared = 2 WHERE id = ?', [noteId])
})
.then((rows, fields) => {
//Success!
return resolve(true)
return resolve({'success':true, shareUserId})
})
.catch(error => {
// console.log(error)
console.log(error)
resolve(false)
})
})
@@ -102,25 +109,38 @@ ShareNote.getUsers = (userId, rawTextId) => {
// Remove a user from a shared note
ShareNote.removeUser = (userId, noteId) => {
return new Promise((resolve, reject) => {
const Note = require('@models/Note')
let rawTextId = null
let removeUserId = null
//note.id = noteId, share_user_id = userId
db.promise()
.query('SELECT user_id FROM note WHERE id = ? AND share_user_id = ?', [noteId, userId])
.query('SELECT note_raw_text_id, user_id FROM note WHERE id = ? AND share_user_id = ?', [noteId, userId])
.then( (rows, fields) => {
//User has shared this note, with this user
if(rows[0].length == 1 && Number.isInteger(rows[0][0]['user_id'])){
rawTextId = rows[0][0]['note_raw_text_id']
removeUserId = rows[0][0]['user_id']
Note.delete(rows[0][0]['user_id'], noteId)
.then( result => {
resolve(result)
})
//Delete note entry for other user - remove users access
if(removeUserId && Number.isInteger(removeUserId)){
//Delete this users access to the note
return Note.delete(removeUserId, noteId)
} else {
return resolve(false)
return new Promise((resolve, reject) => { resolve(true) })
}
})
.then(stuff => {
resolve(true)
})
.catch(error => {
console.log(error)
resolve(false)
})
})