summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--confirm.go37
-rw-r--r--frontend/student.js4
-rw-r--r--wsmsg_hello.go13
3 files changed, 51 insertions, 3 deletions
diff --git a/confirm.go b/confirm.go
new file mode 100644
index 0000000..88dc8be
--- /dev/null
+++ b/confirm.go
@@ -0,0 +1,37 @@
+/*
+ * Confirmination checking
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package main
+
+import (
+ "context"
+)
+
+func getConfirmedStatus(ctx context.Context, userID string) (confirmed bool, retErr error) {
+ err := db.QueryRow(
+ ctx,
+ "SELECT confirmed FROM users WHERE id = $1",
+ userID,
+ ).Scan(&confirmed)
+ if err != nil {
+ retErr = wrapError(errUnexpectedDBError, err)
+ }
+ return
+}
diff --git a/frontend/student.js b/frontend/student.js
index 40598b9..c85a6a2 100644
--- a/frontend/student.js
+++ b/frontend/student.js
@@ -73,8 +73,8 @@ document.addEventListener("DOMContentLoaded", () => {
forEach(c => {
c.style.display = "none"
})
- if (mar[1] !== "") {
- let courseIDs = mar[1].split(",")
+ if (mar[2] !== "") {
+ let courseIDs = mar[2].split(",")
for (let i = 0; i < courseIDs.length; i++) {
document.getElementById(
`tick${ courseIDs[i] }`
diff --git a/wsmsg_hello.go b/wsmsg_hello.go
index 8ed03d8..02e8ac1 100644
--- a/wsmsg_hello.go
+++ b/wsmsg_hello.go
@@ -66,7 +66,18 @@ func messageHello(
return wrapError(errCannotSend, err)
}
}
- err = writeText(ctx, c, "HI :"+strings.Join(courseIDs, ","))
+
+ confirmed, err := getConfirmedStatus(ctx, userID)
+ if err != nil {
+ return err
+ }
+ var confirmedString string
+ if confirmed {
+ confirmedString = "1"
+ } else {
+ confirmedString = "0"
+ }
+ err = writeText(ctx, c, "HI "+confirmedString+" :"+strings.Join(courseIDs, ","))
if err != nil {
return wrapError(errCannotSend, err)
}