Minor: `add_chat_message` returns seq (or None)
It now returns the seq of the just-added message if one was added, and None otherwise. The previous behaviour was to return True and False respectively.
このコミットが含まれているのは:
コミット
4a22ca8a92
|
@ -31,9 +31,9 @@ def get_all_messages_for_websocket():
|
||||||
))
|
))
|
||||||
|
|
||||||
def add_chat_message(user, nonce, comment, ignore_empty=False):
|
def add_chat_message(user, nonce, comment, ignore_empty=False):
|
||||||
# Special case: if the comment is empty, do nothing and return
|
# Special case: if the comment is empty, do nothing and return None
|
||||||
if ignore_empty and len(comment) == 0:
|
if ignore_empty and len(comment) == 0:
|
||||||
return False
|
return None
|
||||||
|
|
||||||
timestamp_ms = time.time_ns() // 1_000_000
|
timestamp_ms = time.time_ns() // 1_000_000
|
||||||
timestamp = timestamp_ms // 1000
|
timestamp = timestamp_ms // 1000
|
||||||
|
@ -137,7 +137,7 @@ def add_chat_message(user, nonce, comment, ignore_empty=False):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return seq
|
||||||
|
|
||||||
def delete_chat_messages(seqs):
|
def delete_chat_messages(seqs):
|
||||||
seq_set = set(seqs)
|
seq_set = set(seqs)
|
||||||
|
|
|
@ -135,12 +135,13 @@ async def nojs_submit_message(timestamp, user):
|
||||||
try:
|
try:
|
||||||
# If the comment is empty but the captcha was just solved,
|
# If the comment is empty but the captcha was just solved,
|
||||||
# be lenient: don't raise an exception and don't create a notice
|
# be lenient: don't raise an exception and don't create a notice
|
||||||
message_was_added = add_chat_message(
|
seq = add_chat_message(
|
||||||
user,
|
user,
|
||||||
nonce,
|
nonce,
|
||||||
comment,
|
comment,
|
||||||
ignore_empty=verification_happened,
|
ignore_empty=verification_happened,
|
||||||
)
|
)
|
||||||
|
message_was_added = seq is not None
|
||||||
except Rejected as e:
|
except Rejected as e:
|
||||||
notice, *_ = e.args
|
notice, *_ = e.args
|
||||||
state_id = add_state(
|
state_id = add_state(
|
||||||
|
|
|
@ -140,12 +140,13 @@ def handle_inbound_message(timestamp, queue, user, nonce, comment, digest, answe
|
||||||
message_was_added = False
|
message_was_added = False
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
message_was_added = add_chat_message(
|
seq = add_chat_message(
|
||||||
user,
|
user,
|
||||||
nonce,
|
nonce,
|
||||||
comment,
|
comment,
|
||||||
ignore_empty=verification_happened,
|
ignore_empty=verification_happened,
|
||||||
)
|
)
|
||||||
|
message_was_added = seq is not None
|
||||||
except Rejected as e:
|
except Rejected as e:
|
||||||
notice, *_ = e.args
|
notice, *_ = e.args
|
||||||
message_was_added = False
|
message_was_added = False
|
||||||
|
|
読み込み中…
新しいイシューから参照