Refactored shared notes app
This commit is contained in:
parent
20231003ae
commit
59cd4f64bf
@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit
|
||||
import org.bigbluebutton.core.util._
|
||||
import scala.concurrent.duration._
|
||||
import org.bigbluebutton.core.apps.{ PollApp, UsersApp, PresentationApp, LayoutApp, ChatApp, WhiteboardApp, SharedNotesApp }
|
||||
import org.bigbluebutton.core.apps.{ ChatModel, LayoutModel, UsersModel, PollModel, WhiteboardModel }
|
||||
import org.bigbluebutton.core.apps.{ ChatModel, LayoutModel, UsersModel, PollModel, WhiteboardModel, SharedNotesModel }
|
||||
import org.bigbluebutton.core.apps.PresentationModel
|
||||
|
||||
object MeetingActor {
|
||||
@ -29,6 +29,7 @@ class MeetingActor(val mProps: MeetingProperties, val outGW: OutMessageGateway)
|
||||
val pollModel = new PollModel()
|
||||
val wbModel = new WhiteboardModel()
|
||||
val presModel = new PresentationModel()
|
||||
val notesModel = new SharedNotesModel()
|
||||
|
||||
import context.dispatcher
|
||||
context.system.scheduler.schedule(2 seconds, 30 seconds, self, "MonitorNumberOfWebUsers")
|
||||
|
@ -2,80 +2,48 @@ package org.bigbluebutton.core.apps
|
||||
|
||||
import org.bigbluebutton.core.api._
|
||||
import org.bigbluebutton.core.MeetingActor
|
||||
import com.google.gson.Gson
|
||||
import org.bigbluebutton.core.OutMessageGateway
|
||||
|
||||
import name.fraser.neil.plaintext.diff_match_patch
|
||||
import name.fraser.neil.plaintext.diff_match_patch._
|
||||
import scala.collection.JavaConversions._
|
||||
import scala.collection._
|
||||
import java.util.Collections
|
||||
|
||||
trait SharedNotesApp {
|
||||
this: MeetingActor =>
|
||||
|
||||
val outGW: OutMessageGateway
|
||||
|
||||
val notes = new scala.collection.mutable.HashMap[String, Note]()
|
||||
notes += ("MAIN_WINDOW" -> new Note("", ""))
|
||||
val patcher = new diff_match_patch()
|
||||
var notesCounter = 0;
|
||||
var removedNotes: Set[Int] = Set()
|
||||
|
||||
def handlePatchDocumentRequest(msg: PatchDocumentRequest) {
|
||||
// meetingId, userId, noteId, patch, beginIndex, endIndex
|
||||
notes.synchronized {
|
||||
val note = notes(msg.noteID)
|
||||
val document = note.document
|
||||
val patchObjects = patcher.patch_fromText(msg.patch)
|
||||
val result = patcher.patch_apply(patchObjects, document)
|
||||
notes(msg.noteID) = new Note(note.name, result(0).toString())
|
||||
}
|
||||
notesModel.patchDocument(msg.noteID, msg.patch)
|
||||
|
||||
outGW.send(new PatchDocumentReply(mProps.meetingID, mProps.recorded, msg.requesterID, msg.noteID, msg.patch))
|
||||
}
|
||||
|
||||
def handleGetCurrentDocumentRequest(msg: GetCurrentDocumentRequest) {
|
||||
val copyNotes = notes.toMap
|
||||
val copyNotes = notesModel.notes.toMap
|
||||
|
||||
outGW.send(new GetCurrentDocumentReply(mProps.meetingID, mProps.recorded, msg.requesterID, copyNotes))
|
||||
}
|
||||
|
||||
private def createAdditionalNotesNonSync(requesterID: String, noteName: String = "") {
|
||||
var noteID = 0
|
||||
if (removedNotes.isEmpty()) {
|
||||
notesCounter += 1
|
||||
noteID = notesCounter
|
||||
} else {
|
||||
noteID = removedNotes.min
|
||||
removedNotes -= noteID
|
||||
}
|
||||
notes += (noteID.toString -> new Note(noteName, ""))
|
||||
private def createAdditionalNotes(requesterID: String, noteName: String = "") {
|
||||
notesModel.synchronized {
|
||||
val noteID = notesModel.createNote(noteName)
|
||||
|
||||
outGW.send(new CreateAdditionalNotesReply(mProps.meetingID, mProps.recorded, requesterID, noteID.toString, noteName))
|
||||
outGW.send(new CreateAdditionalNotesReply(mProps.meetingID, mProps.recorded, requesterID, noteID, noteName))
|
||||
}
|
||||
}
|
||||
|
||||
def handleCreateAdditionalNotesRequest(msg: CreateAdditionalNotesRequest) {
|
||||
notes.synchronized {
|
||||
createAdditionalNotesNonSync(msg.requesterID, msg.noteName)
|
||||
}
|
||||
createAdditionalNotes(msg.requesterID, msg.noteName)
|
||||
}
|
||||
|
||||
def handleDestroyAdditionalNotesRequest(msg: DestroyAdditionalNotesRequest) {
|
||||
notes.synchronized {
|
||||
removedNotes += msg.noteID.toInt
|
||||
notes -= msg.noteID
|
||||
}
|
||||
notesModel.synchronized {
|
||||
notesModel.destroyNote(msg.noteID)
|
||||
|
||||
outGW.send(new DestroyAdditionalNotesReply(mProps.meetingID, mProps.recorded, msg.requesterID, msg.noteID))
|
||||
}
|
||||
}
|
||||
|
||||
def handleRequestAdditionalNotesSetRequest(msg: RequestAdditionalNotesSetRequest) {
|
||||
notes.synchronized {
|
||||
var num = msg.additionalNotesSetSize - notes.size + 1
|
||||
for (i <- 1 to num) {
|
||||
createAdditionalNotesNonSync(msg.requesterID)
|
||||
}
|
||||
while (notesModel.notesSize < msg.additionalNotesSetSize) {
|
||||
createAdditionalNotes(msg.requesterID)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.bigbluebutton.core.apps
|
||||
|
||||
import org.bigbluebutton.core.api._
|
||||
|
||||
import name.fraser.neil.plaintext.diff_match_patch
|
||||
import name.fraser.neil.plaintext.diff_match_patch._
|
||||
import scala.collection._
|
||||
import java.util.Collections
|
||||
|
||||
class SharedNotesModel {
|
||||
val notes = new scala.collection.mutable.HashMap[String, Note]()
|
||||
notes += ("MAIN_WINDOW" -> new Note("", ""))
|
||||
private val patcher = new diff_match_patch()
|
||||
private var notesCounter = 0;
|
||||
private var removedNotes: Set[Int] = Set()
|
||||
|
||||
def patchDocument(noteID: String, patch: String) {
|
||||
notes.synchronized {
|
||||
val note = notes(noteID)
|
||||
val document = note.document
|
||||
val patchObjects = patcher.patch_fromText(patch)
|
||||
val result = patcher.patch_apply(patchObjects, document)
|
||||
notes(noteID) = new Note(note.name, result(0).toString())
|
||||
}
|
||||
}
|
||||
|
||||
def createNote(noteName: String = ""): String = {
|
||||
var noteID = 0
|
||||
if (removedNotes.isEmpty) {
|
||||
notesCounter += 1
|
||||
noteID = notesCounter
|
||||
} else {
|
||||
noteID = removedNotes.min
|
||||
removedNotes -= noteID
|
||||
}
|
||||
notes += (noteID.toString -> new Note(noteName, ""))
|
||||
|
||||
noteID.toString
|
||||
}
|
||||
|
||||
def destroyNote(noteID: String) {
|
||||
removedNotes += noteID.toInt
|
||||
notes -= noteID
|
||||
}
|
||||
|
||||
def notesSize(): Int = {
|
||||
notes.size
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user