File: /volume1/@appstore/Spreadsheet/server/common/collab/Connection2.js
"use strict";const{default:t}=require("../base/client");var e=require("./Constants");const{schemaComment:s}=require("../prosemirror");const{logger:i}=require("@synology-office/logger");class n extends t{onPeek(t,e){if(typeof e!=="function"){t(false,{});return}if(t.serverId!==this.instance.getUniqueId()){e(false);return}if(this.instance.hasClient(this.id)){e(null,{id:this.id,doc_version:this.instance.getDataVersionCache(),permission:this.getPermission()})}else{e(false)}}onSayHello(t){this.getPeerInfo().then((e=>{t({id:this.id,serverId:this.instance.getUniqueId()});this.broadcastPeerInfo("hello",e)})).catch((()=>{}))}isWritableCommentable(t){if(this.isWritable()){return true}else if(this.isCommentable()){const e=this.isAnonymous()?s.isPublicCommentableStep:s.isCommentableStep;const i=this.getUid();for(const s of t.steps){if(!e(s,i)){return false}}return true}return false}async onEvent(t,s,n){if(!t.steps.length){s(null,{id:this.id,version:this.instance.getCollabObject(true).getVersionCache(),steps:[],clientIDs:[],selection:t.selection});return}if(!this.isWritableCommentable(t)){s({status:e.ERR_PERM_NOT_ENOUGH});return}try{t=await this.instance.addDocEvents(t,this.id,this.getUid());this.notifyCommentSteps(t.steps)}catch(t){if(t.status!==e.ERR_VERSION_NOT_CURRENT){i.error("addDocEvents failed",this.getObjectId(),this.id,t,t.stack)}s({status:t.status||e.ERR_GENERAL},t.toString());return}if(false===t){s({status:e.ERR_VERSION_NOT_CURRENT});return}if(true!==n){this.stopWaiting()}s(null,t);this.instance.broadcastClientChanges();this.updateMtime()}onBroadcast(t){t.id=this.id;this.broadcast("broadcast",null,t)}onSave(t,s){if(!this.isWritable()){s({status:e.ERR_PERM_NOT_ENOUGH});return}this.instance.snapshot(t||undefined).then(s)}sayBye(){this.broadcast("bye",this.id)}}module.exports=n;