+ Giant update to multiple users editing notes.
- Edits are done per DOM element, making diffs smaller and faster - Multiple users can now edit the same note witheout it turning into a gaint mess - Caret position is saved better and wont jump around as much + Removed Active sessions text
This commit is contained in:
@@ -114,29 +114,12 @@ io.on('connection', function(socket){
|
||||
|
||||
//Emit all sorted diffs to user
|
||||
socket.emit('past_diffs', noteDiffs[rawTextId])
|
||||
} else {
|
||||
socket.emit('past_diffs', null)
|
||||
}
|
||||
|
||||
const usersInRoom = io.sockets.adapter.rooms[rawTextId]
|
||||
if(usersInRoom){
|
||||
//Update users in room count
|
||||
io.to(rawTextId).emit('update_user_count', usersInRoom.length)
|
||||
|
||||
//Debugging text - prints out notes in limbo
|
||||
let noteDiffKeys = Object.keys(noteDiffs)
|
||||
let totalDiffs = 0
|
||||
noteDiffKeys.forEach(diffSetKey => {
|
||||
if(noteDiffs[diffSetKey]){
|
||||
totalDiffs += noteDiffs[diffSetKey].length
|
||||
}
|
||||
})
|
||||
//Debugging Text
|
||||
if(noteDiffKeys.length > 0){
|
||||
console.log('Total notes in limbo -> ', noteDiffKeys.length)
|
||||
console.log('Total Diffs for all notes -> ', totalDiffs)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
@@ -162,31 +145,13 @@ io.on('connection', function(socket){
|
||||
|
||||
noteDiffs[noteId].push(data)
|
||||
|
||||
//Remove duplicate diffs if they exist
|
||||
for (var i = noteDiffs[noteId].length - 1; i >= 0; i--) {
|
||||
|
||||
let pastDiff = noteDiffs[noteId][i]
|
||||
|
||||
for (var j = noteDiffs[noteId].length - 1; j >= 0; j--) {
|
||||
let currentDiff = noteDiffs[noteId][j]
|
||||
|
||||
if(i == j){
|
||||
continue
|
||||
}
|
||||
|
||||
if(currentDiff.diff == pastDiff.diff || currentDiff.time == pastDiff.time){
|
||||
console.log('Removing Duplicate')
|
||||
noteDiffs[noteId].splice(i,1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Each user joins a room when they open the app.
|
||||
// Go over each user in this note-room
|
||||
io.in(noteId).clients((error, clients) => {
|
||||
if (error) throw error;
|
||||
|
||||
//Go through each client in note room and send them the diff
|
||||
//Go through each client in note-room and send them the diff
|
||||
clients.forEach(socketId => {
|
||||
// only send off diff if user
|
||||
if(socketId != socket.id){
|
||||
io.to(socketId).emit('incoming_diff', data)
|
||||
}
|
||||
@@ -213,7 +178,6 @@ io.on('connection', function(socket){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
noteDiffs[checkpoint.rawTextId] = diffSet.slice(0, sliceTo)
|
||||
|
||||
if(noteDiffs[checkpoint.rawTextId].length == 0){
|
||||
|
Reference in New Issue
Block a user