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.
Commit
0fffa63bbdc8f89d6bc383c8f40f9db3a55d270742e3d4ad8866940e91584b74
Parent
2d329da18979aef…
1 file changed
+6
-3
+6
-3
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -499,11 +499,11 @@ | ||
| 499 | 499 | globally. A user may always delete a local copy of a |
| 500 | 500 | post. The server may trump this, e.g. if the login has been |
| 501 | 501 | cancelled after this page was loaded. |
| 502 | 502 | */ |
| 503 | 503 | cs.userMayDelete = function(eMsg){ |
| 504 | - return eMsg.msgid>0 | |
| 504 | + return +eMsg.dataset.msgid>0 | |
| 505 | 505 | && (this.me === eMsg.dataset.xfrom |
| 506 | 506 | || F.user.isAdmin/*will be confirmed server-side*/); |
| 507 | 507 | }; |
| 508 | 508 | |
| 509 | 509 | /** Returns a new Error() object encapsulating state from the given |
| @@ -539,12 +539,15 @@ | ||
| 539 | 539 | e = this.getMessageElemById(id); |
| 540 | 540 | } |
| 541 | 541 | if(!(e instanceof HTMLElement)) return; |
| 542 | 542 | if(this.userMayDelete(e)){ |
| 543 | 543 | 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 | + }) | |
| 546 | 549 | .then(()=>this.deleteMessageElem(e)) |
| 547 | 550 | .catch(err=>this.reportErrorAsMessage(err)) |
| 548 | 551 | .finally(()=>this.ajaxEnd()); |
| 549 | 552 | }else{ |
| 550 | 553 | this.deleteMessageElem(id); |
| 551 | 554 |
| --- 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 |