diff --git a/anonkun.sql b/anonkun.sql
index 8235569..613b23a 100644
--- a/anonkun.sql
+++ b/anonkun.sql
@@ -15,9 +15,11 @@ CREATE TABLE `quest_meta` (
) ENGINE=InnoDB CHARSET utf8mb4;
CREATE TABLE `quest_data` (
+ `post_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
`quest_id` SMALLINT UNSIGNED NOT NULL,
`post` MEDIUMTEXT NOT NULL,
- `timestamp` INT UNSIGNED NOT NULL
+ `timestamp` INT UNSIGNED NOT NULL,
+ PRIMARY KEY (`post_id`)
) ENGINE=InnoDB CHARSET utf8mb4;
CREATE TABLE `chat_messages` (
diff --git a/database.py b/database.py
index 81b6f55..a6da949 100644
--- a/database.py
+++ b/database.py
@@ -65,7 +65,7 @@ def verify_password(username, password):
if not user:
return False
- user_id, _, pw_hash = user
+ user_id, _, pw_hash, _ = user
if argon2.verify(password, pw_hash):
session["user_id"] = user_id
@@ -135,12 +135,20 @@ def insert_quest_post(quest_id, post, timestamp):
"VALUES (%s, %s, %s)", (quest_id, post, timestamp))
-def get_quest_meta(ident_title):
+def get_quest_meta(quest_id=None, ident_title=None):
"""
- Retrieves all meta info about a quest.
+ Retrieves all meta info about a quest. Allows searching by either
+ quest_id or ident_title.
"""
- data = _DB.execute("SELECT * FROM `quest_meta` WHERE `ident_title` = %s",
- (ident_title,)).fetchone()
+ statement = "SELECT * FROM `quest_meta` WHERE "
+ if quest_id:
+ statement += "`quest_id` = %s"
+ data = _DB.execute(statement, (quest_id,)).fetchone()
+ elif ident_title:
+ statement += "`ident_title` = %s"
+ data = _DB.execute(statement, (ident_title,)).fetchone()
+ else:
+ return
return data
@@ -171,3 +179,12 @@ def get_user_quests(user_id):
"SELECT * FROM `quest_meta` WHERE `owner_id` = %s",
(user_id,)).fetchall()
return data
+
+
+def update_quest_post(post_id, new_post):
+ """
+ Updates a quest post.
+ """
+ _DB.execute(
+ "UPDATE `quest_data` SET `post` = %s WHERE `post_id` = %s",
+ (new_post, post_id))
diff --git a/events.py b/events.py
index 0e9f653..cc7fc7c 100644
--- a/events.py
+++ b/events.py
@@ -5,6 +5,7 @@ SocketIO events.
import time
import bleach
+from flask import session
from flask_socketio import SocketIO, emit, join_room
import database as db
@@ -54,11 +55,34 @@ def new_post(data):
Called when the QM makes a new post.
"""
room = data["room"]
- post = data["post"]
+ res = db.get_quest_meta(quest_id=room)
+ if not res:
+ return
+ if session.get("user_id") != res[3]:
+ return
+ post = data["post"]
post = bleach.clean(post.strip())
post = post.replace("\n", "
")
data["post"] = [post]
db.insert_quest_post(room, post, int(time.time()))
emit("new_post", data, room=room)
+
+
+@socketio.on("update_post")
+def update_post(data):
+ """
+ Called when the QM edits and saves a post.
+ """
+ room = data["room"]
+ res = db.get_quest_meta(quest_id=room)
+ if not res:
+ return
+ if session.get("user_id") != res[3]:
+ return
+
+ post = data["post"]
+ post_id = data["post_id"]
+ db.update_quest_post(post_id, post)
+ emit("update_post", data, room=room)
diff --git a/static/anonkun.css b/static/anonkun.css
index ecd85cf..19dc225 100644
--- a/static/anonkun.css
+++ b/static/anonkun.css
@@ -30,7 +30,7 @@
}
#questPosts {
- border-spacing: 10px;
+ border-spacing: 15px;
}
.questPostTime {
@@ -38,6 +38,10 @@
white-space: nowrap;
}
+.questPostData {
+ vertical-align: top;
+}
+
#newQPostArea {
}
diff --git a/templates/quest.html b/templates/quest.html
index 2132b2d..9c02e04 100644
--- a/templates/quest.html
+++ b/templates/quest.html
@@ -13,26 +13,30 @@
socket.emit('joined', {room: {{ room_id }}});
});
socket.on('message', function(data) {
- date = new Date(data.date * 1000);
- date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
+ var date = new Date(data.date * 1000);
+ var date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds());
- msg_str = '