Only allow using history in writable mode

Otherwise stuff can be reverted, and the write ID can be taken from
padData change events.
pull/54/merge
Candid Dauth 2016-11-01 19:59:55 +03:00
rodzic 88483d142e
commit be37c6b6e1
1 zmienionych plików z 8 dodań i 2 usunięć

Wyświetl plik

@ -429,8 +429,8 @@ utils.extend(SocketConnection.prototype, {
listenToHistory: function() { listenToHistory: function() {
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
if(this.padId == null) if(!this.writable)
throw "No pad ID set."; throw "In read-only mode.";
if(this.historyListener) if(this.historyListener)
throw "Already listening to history."; throw "Already listening to history.";
@ -450,6 +450,9 @@ utils.extend(SocketConnection.prototype, {
if(!this.historyListener) if(!this.historyListener)
throw "Not listening to history."; throw "Not listening to history.";
if(!this.writable)
throw "In read-only mode.";
this.historyListener(); // Unregister db listener this.historyListener(); // Unregister db listener
this.historyListener = null; this.historyListener = null;
}, },
@ -461,6 +464,9 @@ utils.extend(SocketConnection.prototype, {
if(!utils.stripObject(data, { id: "number" })) if(!utils.stripObject(data, { id: "number" }))
throw "Invalid parameters."; throw "Invalid parameters.";
if(!this.writable)
throw "In read-only mode.";
if(listening) if(listening)
this.socketHandlers.stopListeningToHistory.call(this); this.socketHandlers.stopListeningToHistory.call(this);