summaryrefslogtreecommitdiff
path: root/public/emotes
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-07 18:57:32 +0500
committerilotterytea <iltsu@alright.party>2025-05-07 18:57:32 +0500
commitada4748a25c39b226534ff0475569a8bd25e17ab (patch)
treebefc462938025044429643dbceec7466e0160997 /public/emotes
parent73a329d1e620e719932ad8c860f85289c3547ab3 (diff)
feat: user actions
Diffstat (limited to 'public/emotes')
-rw-r--r--public/emotes/setmanip.php30
-rw-r--r--public/emotes/upload.php15
2 files changed, 44 insertions, 1 deletions
diff --git a/public/emotes/setmanip.php b/public/emotes/setmanip.php
index 8b0f085..71d922b 100644
--- a/public/emotes/setmanip.php
+++ b/public/emotes/setmanip.php
@@ -22,12 +22,13 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS);
// checking emote
$emote_id = $_POST["id"];
-$stmt = $db->prepare("SELECT id FROM emotes WHERE id = ?");
+$stmt = $db->prepare("SELECT id, code, uploaded_by, visibility, created_at FROM emotes WHERE id = ?");
$stmt->execute([$emote_id]);
if ($stmt->rowCount() == 0) {
generate_alert("/emotes", "Emote not found", 404);
exit;
}
+$emote = $stmt->fetch(PDO::FETCH_ASSOC);
$user_id = $_SESSION["user_id"];
@@ -66,6 +67,10 @@ $stmt = $db->prepare("SELECT id FROM emote_set_contents WHERE emote_set_id = ? A
$stmt->execute([$emote_set_id, $emote_id]);
$action = $_POST["action"];
+$payload = [
+ "emote" => $emote,
+ "emoteset" => $_SESSION["user_active_emote_set"]
+];
switch ($action) {
case "add": {
@@ -77,6 +82,9 @@ switch ($action) {
$stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)");
$stmt->execute([$emote_set_id, $emote_id, $user_id]);
+ $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)")
+ ->execute([$user_id, "EMOTESET_ADD", json_encode($payload)]);
+
$db = null;
generate_alert("/emotes?id=$emote_id", "This emote has been added to your set. Enjoy!", 200);
@@ -92,6 +100,9 @@ switch ($action) {
exit;
}
+ $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)")
+ ->execute([$user_id, "EMOTESET_REMOVE", json_encode($payload)]);
+
$db = null;
generate_alert("/emotes?id=$emote_id", "This emote has been removed from your set.", 200);
@@ -105,13 +116,30 @@ switch ($action) {
$value = str_safe($_POST["value"], EMOTE_NAME_MAX_LENGTH);
+ $stmt = $db->prepare("SELECT esc.code AS alias_code, e.code FROM emote_set_contents esc
+ INNER JOIN emotes e ON e.id = esc.emote_id
+ WHERE esc.emote_set_id = ? AND esc.emote_id = ?");
+ $stmt->execute([$emote_set_id, $emote_id]);
+
if (empty($value)) {
$value = null;
+
+ if ($row = $stmt->fetch()) {
+ $payload["emote"]["original_code"] = $row["alias_code"];
+ $payload["emote"]["code"] = $row["code"];
+ }
+ } else {
+ $row = $stmt->fetch();
+ $payload["emote"]["original_code"] = $row["alias_code"] ?? $row["code"];
+ $payload["emote"]["code"] = $value;
}
$stmt = $db->prepare("UPDATE emote_set_contents SET code = ? WHERE emote_set_id = ? AND emote_id = ?");
$stmt->execute([$value, $emote_set_id, $emote_id]);
+ $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)")
+ ->execute([$user_id, "EMOTESET_ALIAS", json_encode($payload)]);
+
$db = null;
generate_alert("/emotes?id=$emote_id", "Updated emote name!", 200);
diff --git a/public/emotes/upload.php b/public/emotes/upload.php
index 0b79b5c..42e58c6 100644
--- a/public/emotes/upload.php
+++ b/public/emotes/upload.php
@@ -389,6 +389,21 @@ if ($is_manual) {
}
}
+$db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)")
+ ->execute([
+ $uploaded_by,
+ "EMOTE_CREATE",
+ json_encode([
+ "emote" => [
+ "id" => $id,
+ "code" => $code,
+ "visibility" => $visibility,
+ "uploaded_by" => $uploaded_by,
+ ]
+ ])
+ ]);
+
+
$db = null;
if (CLIENT_REQUIRES_JSON) {