* Removed arrows from notification
* Added trash can function * Tweaked status text to always be the same * Removed some open second note code * Edior always focuses on text now * Added some extra loading note messages * Notes are now removed from search index when deleted * Lots more things happen and update in real time on multiple machines * Shared notes can be reverted * WAY more tests * Note Categories are much more reliable * Lots of code is much cleaner
This commit is contained in:
1 parent
e87e8513bc
commit
5096e74a60
18 files changed
+644
-368
No files matched your search
@@ -89,7 +89,7 @@ ShareNote.migrateNoteToShared = (userId, noteId, shareUserId, masterKey) => {
|
||||
const encryptedSharedKey = crypto.publicEncrypt(publicKey, Buffer.from(sharedNoteMasterKey, 'utf8')).toString('base64')
|
||||
|
||||
//Update note snippet for current user with public key encoded snippet
|
||||
return db.promise().query('UPDATE note SET snippet = ?, snippet_salt = ?, encrypted_share_password_key = ? WHERE id = ? AND user_id = ?',
|
||||
return db.promise().query('UPDATE note SET snippet = ?, snippet_salt = ?, encrypted_share_password_key = ?, shared = 2 WHERE id = ? AND user_id = ?',
|
||||
[encryptedSnippet, sharedNoteSnippetSalt, encryptedSharedKey, noteId, userId])
|
||||
|
||||
})
|
||||
@@ -116,8 +116,13 @@ ShareNote.migrateNoteToShared = (userId, noteId, shareUserId, masterKey) => {
|
||||
})
|
||||
.then((rows, fields) => {
|
||||
|
||||
const sharedUserNoteId = rows[0]['insertId']
|
||||
|
||||
//Emit update count event to user shared with - so they see the note in real time
|
||||
SocketIo.to(sharedUserNoteId).emit('update_counts')
|
||||
|
||||
let success = true
|
||||
return resolve({success, shareUserId})
|
||||
return resolve({success, shareUserId, sharedUserNoteId})
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -128,6 +133,69 @@ ShareNote.migrateNoteToShared = (userId, noteId, shareUserId, masterKey) => {
|
||||
})
|
||||
}
|
||||
|
||||
ShareNote.removeUserFromShared = (userId, noteId, shareNoteUserId, masterKey) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let rawTextId = null
|
||||
let removeUserId = null
|
||||
|
||||
db.promise()
|
||||
.query('SELECT note_raw_text_id, user_id FROM note WHERE id = ? AND share_user_id = ?', [shareNoteUserId, userId])
|
||||
.then( (rows, fields) => {
|
||||
|
||||
rawTextId = rows[0][0]['note_raw_text_id']
|
||||
removeUserId = rows[0][0]['user_id']
|
||||
|
||||
//Delete note entry for other user - remove users access
|
||||
//@TODO - this won't remove the note from their search index, it needs to
|
||||
return Note.delete(removeUserId, shareNoteUserId)
|
||||
|
||||
})
|
||||
.then(results => {
|
||||
|
||||
return db.promise().query('SELECT count(*) as count FROM note WHERE note_raw_text_id = ?', [rawTextId])
|
||||
})
|
||||
.then((rows, fields) => {
|
||||
|
||||
//Convert back to normal note if there is only one person with this note
|
||||
if(rows[0][0]['count'] == 1){
|
||||
|
||||
Note.get(userId, noteId, masterKey)
|
||||
.then(noteObject => {
|
||||
|
||||
const salt = cs.createSmallSalt()
|
||||
const snippetSalt = cs.createSmallSalt()
|
||||
|
||||
const snippetObj = JSON.stringify([noteObject.title, noteObject.text.substring(0, 500)])
|
||||
const snippet = cs.encrypt(masterKey, snippetSalt, snippetObj)
|
||||
|
||||
const textObject = JSON.stringify([noteObject.title, noteObject.text])
|
||||
const encryptedText = cs.encrypt(masterKey, salt, textObject)
|
||||
|
||||
db.promise()
|
||||
.query(`UPDATE note SET snippet = ?, snippet_salt = ?, encrypted_share_password_key = ?, shared = 0 WHERE id = ? AND user_id = ?`,
|
||||
[snippet, snippetSalt, null, noteId, userId])
|
||||
.then((r,f) => {
|
||||
|
||||
db.promise()
|
||||
.query('UPDATE note_raw_text SET text = ?, salt = ? WHERE id = ?',
|
||||
[encryptedText, salt, noteObject.rawTextId])
|
||||
.then(() => {
|
||||
return resolve(true)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
//Keep note shared
|
||||
return resolve(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Get users who see a shared note
|
||||
ShareNote.getUsers = (userId, rawTextId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -168,7 +236,7 @@ ShareNote.removeUser = (userId, noteId) => {
|
||||
//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)
|
||||
return Note.delete(removeUserId, noteId, masterKey)
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Reference in new issue
Block a user