aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-18 12:17:03 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-18 12:17:03 -0500
commitfa9cc49337b88f42d0c78e25be698dd90b2498fb (patch)
tree5f45cdd41773eb5d87ab487c2f25ca56a6321b5b /src
parent662f9c3b7027fe88445869eb7373dc0d70ebfe5e (diff)
downloadbbj-fa9cc49337b88f42d0c78e25be698dd90b2498fb.tar.gz
messages can now have toggleable formatting at the database level
Diffstat (limited to 'src')
-rw-r--r--src/db.py66
-rw-r--r--src/formatting.py3
-rw-r--r--src/schema.py6
-rw-r--r--src/utils.py2
4 files changed, 57 insertions, 20 deletions
diff --git a/src/db.py b/src/db.py
index 0c9920c..7fd0fd5 100644
--- a/src/db.py
+++ b/src/db.py
@@ -93,7 +93,7 @@ def thread_set_pin(connection, thread_id, pin_bool):
return pin_bool
-def thread_create(connection, author_id, body, title):
+def thread_create(connection, author_id, body, title, send_raw=False):
"""
Create a new thread and return it.
"""
@@ -116,31 +116,32 @@ def thread_create(connection, author_id, body, title):
# the thread is initially commited with reply_count -1 so that i can
# just pass the message to the reply method, instead of duplicating
# its code here. It then increments to 0.
- thread_reply(connection, author_id, thread_id, body, time_override=now)
+ thread_reply(connection, author_id, thread_id, body, send_raw, time_override=now)
# fetch the new thread out of the database instead of reusing the returned
# objects, just to be 100% sure what is returned is what was committed
return thread_get(connection, thread_id)
-def thread_reply(connection, author_id, thread_id, body, time_override=None):
+def thread_reply(connection, author_id, thread_id, body, send_raw=False, time_override=None):
"""
Submit a new reply for thread_id. Return the new reply object.
- time_overide can be time() value to set as the new message time.
+ time_overide can be a time() value to set as the new message time.
This is to keep post_id 0 in exact parity with its parent thread.
"""
validate([("body", body)])
now = time_override or time()
thread = thread_get(connection, thread_id, messages=False)
- count = thread["reply_count"] + 1
+ thread["reply_count"] += 1
+ count = thread["reply_count"]
scheme = schema.message(
thread_id, count, author_id,
- now, False, body)
+ now, False, body, bool(send_raw))
connection.execute("""
INSERT INTO messages
- VALUES (?,?,?,?,?,?)
+ VALUES (?,?,?,?,?,?,?)
""", schema_values("message", scheme))
connection.execute("""
@@ -157,7 +158,7 @@ def thread_reply(connection, author_id, thread_id, body, time_override=None):
def message_delete(connection, author, thread_id, post_id):
"""
'Delete' a message from a thread. If the message being
- deleted is an OP [pid 0], delete the whole thread.
+ deleted is an OP [post_id == 0], delete the whole thread.
Requires an author id, the thread_id, and post_id.
The same rules for edits apply to deletions: the same
@@ -215,25 +216,58 @@ def message_edit_query(connection, author, thread_id, post_id):
return message
-def message_edit_commit(connection, author_id, thread_id, post_id, new_body):
+def message_edit_commit(
+ connection,
+ author_id,
+ thread_id,
+ post_id,
+ new_body,
+ send_raw=None,
+ set_display=True):
"""
- Attempt to commit new_body to the existing message. Touches base with
- message_edit_query first. Returns the newly updated message object.
+ Attempt to commit new_body, and optionally send_raw (default doesnt modify),
+ to the existing message.
+
+ The send_raw and set_display paramter may be specified as the NoneType
+ to leave its old value intact. Otherwise its given value is coerced to
+ a boolean and is set on the message. send_raw when not explicitly specified
+ will keep its old value, while an unspecified set_display will set it to True.
+
+ new_body may also be a NoneType to retain its old value.
+
+ Touches base with message_edit_query first. Returns
+ the newly updated message object.
"""
- validate([("body", new_body)])
message = message_edit_query(connection, author_id, thread_id, post_id)
- message["body"] = new_body
- message["edited"] = True
+
+ if new_body == None:
+ new_body = message["body"]
+ validate([("body", new_body)])
+
+ if send_raw == None:
+ send_raw = message["send_raw"]
+ else:
+ send_raw = bool(send_raw)
+
+ if set_display == None:
+ display = message["edited"]
+ else:
+ display = bool(set_display)
connection.execute("""
UPDATE messages SET
body = ?,
+ send_raw = ?,
edited = ?
WHERE thread_id = ?
AND post_id = ?
- """, (new_body, True, thread_id, post_id))
-
+ """, (new_body, send_raw, display, thread_id, post_id))
connection.commit()
+
+ message["body"] = new_body
+ message["send_raw"] = send_raw
+ message["edited"] = display
+
return message
diff --git a/src/formatting.py b/src/formatting.py
index a8f1375..0073140 100644
--- a/src/formatting.py
+++ b/src/formatting.py
@@ -180,7 +180,8 @@ def apply_formatting(msg_obj, formatter):
documentation for each formatter.
"""
for x, obj in enumerate(msg_obj):
- msg_obj[x]["body"] = formatter(obj["body"])
+ if not msg_obj[x]["send_raw"]:
+ msg_obj[x]["body"] = formatter(obj["body"])
return msg_obj
diff --git a/src/schema.py b/src/schema.py
index b8d3504..7044c37 100644
--- a/src/schema.py
+++ b/src/schema.py
@@ -147,7 +147,8 @@ def message(
author, # string (uuid1, user.user_id)
created, # floating point unix timestamp (when reply was posted)
edited, # bool
- body): # string
+ body, # string
+ send_raw): # bool
return {
"thread_id": thread_id,
@@ -155,5 +156,6 @@ def message(
"author": author,
"created": created,
"edited": bool(edited),
- "body": body
+ "body": body,
+ "send_raw": bool(send_raw)
}
diff --git a/src/utils.py b/src/utils.py
index 20c8a0d..c533112 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -27,4 +27,4 @@ def schema_values(scheme, obj):
elif scheme == "message":
return ordered_keys(obj,
"thread_id", "post_id", "author",
- "created", "edited", "body")
+ "created", "edited", "body", "send_raw")
Un proyecto texto-plano.xyz