Fossil SCM

chat: fixed the 'may user delete this message?' check, which was comparing an incorrect property. Corrected response handling for remote deletion, broken by API changes made since it was implemented.

stephan 2021-01-05 06:40 trunk
Commit 0fffa63bbdc8f89d6bc383c8f40f9db3a55d270742e3d4ad8866940e91584b74
1 file changed +6 -3
+6 -3
--- src/chat.js
+++ src/chat.js
@@ -499,11 +499,11 @@
499499
globally. A user may always delete a local copy of a
500500
post. The server may trump this, e.g. if the login has been
501501
cancelled after this page was loaded.
502502
*/
503503
cs.userMayDelete = function(eMsg){
504
- return eMsg.msgid>0
504
+ return +eMsg.dataset.msgid>0
505505
&& (this.me === eMsg.dataset.xfrom
506506
|| F.user.isAdmin/*will be confirmed server-side*/);
507507
};
508508
509509
/** Returns a new Error() object encapsulating state from the given
@@ -539,12 +539,15 @@
539539
e = this.getMessageElemById(id);
540540
}
541541
if(!(e instanceof HTMLElement)) return;
542542
if(this.userMayDelete(e)){
543543
this.ajaxStart();
544
- fetch("chat-delete?name=" + id)
545
- .then(this._fetchJsonOrError)
544
+ fetch("chat-delete/" + id)
545
+ .then(function(response){
546
+ if(!response.ok) throw cs._newResponseError(response);
547
+ return response;
548
+ })
546549
.then(()=>this.deleteMessageElem(e))
547550
.catch(err=>this.reportErrorAsMessage(err))
548551
.finally(()=>this.ajaxEnd());
549552
}else{
550553
this.deleteMessageElem(id);
551554
--- src/chat.js
+++ src/chat.js
@@ -499,11 +499,11 @@
499 globally. A user may always delete a local copy of a
500 post. The server may trump this, e.g. if the login has been
501 cancelled after this page was loaded.
502 */
503 cs.userMayDelete = function(eMsg){
504 return eMsg.msgid>0
505 && (this.me === eMsg.dataset.xfrom
506 || F.user.isAdmin/*will be confirmed server-side*/);
507 };
508
509 /** Returns a new Error() object encapsulating state from the given
@@ -539,12 +539,15 @@
539 e = this.getMessageElemById(id);
540 }
541 if(!(e instanceof HTMLElement)) return;
542 if(this.userMayDelete(e)){
543 this.ajaxStart();
544 fetch("chat-delete?name=" + id)
545 .then(this._fetchJsonOrError)
 
 
 
546 .then(()=>this.deleteMessageElem(e))
547 .catch(err=>this.reportErrorAsMessage(err))
548 .finally(()=>this.ajaxEnd());
549 }else{
550 this.deleteMessageElem(id);
551
--- src/chat.js
+++ src/chat.js
@@ -499,11 +499,11 @@
499 globally. A user may always delete a local copy of a
500 post. The server may trump this, e.g. if the login has been
501 cancelled after this page was loaded.
502 */
503 cs.userMayDelete = function(eMsg){
504 return +eMsg.dataset.msgid>0
505 && (this.me === eMsg.dataset.xfrom
506 || F.user.isAdmin/*will be confirmed server-side*/);
507 };
508
509 /** Returns a new Error() object encapsulating state from the given
@@ -539,12 +539,15 @@
539 e = this.getMessageElemById(id);
540 }
541 if(!(e instanceof HTMLElement)) return;
542 if(this.userMayDelete(e)){
543 this.ajaxStart();
544 fetch("chat-delete/" + id)
545 .then(function(response){
546 if(!response.ok) throw cs._newResponseError(response);
547 return response;
548 })
549 .then(()=>this.deleteMessageElem(e))
550 .catch(err=>this.reportErrorAsMessage(err))
551 .finally(()=>this.ajaxEnd());
552 }else{
553 this.deleteMessageElem(id);
554

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button