From 41dff3d5bbe4e4efc859bbddc5e5d180e69964a1 Mon Sep 17 00:00:00 2001
From: Harvey Tindall <hrfee@protonmail.ch>
Date: Sat, 15 Mar 2025 14:53:53 +0000
Subject: [PATCH] user: fix welcome message sent value on NewUserFromAdmin

inverted since WelcomeNewUser returns a bool called "failed", rather
than one indicating success.
---
 api-users.go           |  2 +-
 ts/modules/accounts.ts | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/api-users.go b/api-users.go
index e865b27..352366d 100644
--- a/api-users.go
+++ b/api-users.go
@@ -63,7 +63,7 @@ func (app *appContext) NewUserFromAdmin(gc *gin.Context) {
 
 	welcomeMessageSentIfNecessary := true
 	if nu.Created {
-		welcomeMessageSentIfNecessary = app.WelcomeNewUser(nu.User, time.Time{})
+		welcomeMessageSentIfNecessary = !app.WelcomeNewUser(nu.User, time.Time{})
 	}
 
 	respondUser(nu.Status, nu.Created, welcomeMessageSentIfNecessary, nu.Message, gc)
diff --git a/ts/modules/accounts.ts b/ts/modules/accounts.ts
index b9da9e5..ab88af0 100644
--- a/ts/modules/accounts.ts
+++ b/ts/modules/accounts.ts
@@ -103,7 +103,7 @@ class user implements User, SearchableItem {
     set selected(state: boolean) {
         this._selected = state;
         this._check.checked = state;
-        state ? document.dispatchEvent(this._checkEvent) : document.dispatchEvent(this._uncheckEvent);
+        state ? document.dispatchEvent(this._checkEvent()) : document.dispatchEvent(this._uncheckEvent());
     }
 
     get name(): string { return this._username.textContent; }
@@ -481,8 +481,8 @@ class user implements User, SearchableItem {
         );
     }
 
-    private _checkEvent = new CustomEvent("accountCheckEvent");
-    private _uncheckEvent = new CustomEvent("accountUncheckEvent");
+    private _checkEvent = () => new CustomEvent("accountCheckEvent", {detail: this.id});
+    private _uncheckEvent = () => new CustomEvent("accountUncheckEvent", {detail: this.id});
 
     constructor(user: User) {
         this._row = document.createElement("tr") as HTMLTableRowElement;
@@ -696,7 +696,7 @@ class user implements User, SearchableItem {
     asElement = (): HTMLTableRowElement => { return this._row; }
     remove = () => {
         if (this.selected) {
-            document.dispatchEvent(this._uncheckEvent);
+            document.dispatchEvent(this._uncheckEvent());
         }
         this._row.remove(); 
     }
@@ -927,6 +927,17 @@ export class accountsList {
         state ? this._checkCount = count : 0;
     }
     
+    selectAllBetweenIDs = (startID: string, endID: string) => {
+        let inRange = false;
+        for (let id of this._ordering) {
+            if (!(inRange || id == startID)) continue;
+            inRange = true;
+            if (!(this._table.contains(this._users[id].asElement()))) continue;
+            this._users[id].selected = true;
+            if (id == endID) return;
+        }
+    }
+
     add = (u: User) => {
         let domAccount = new user(u);
         this._users[u.id] = domAccount;