mirror of
https://github.com/l5yth/potato-mesh.git
synced 2026-06-16 16:15:20 +02:00
Update node last seen when ingesting encrypted messages (#198)
* Update node last seen for encrypted messages * run rufo
This commit is contained in:
+15
@@ -1064,6 +1064,9 @@ def insert_message(db, m)
|
||||
|
||||
ensure_unknown_node(db, from_id || raw_from_id, m["from_num"], heard_time: rx_time)
|
||||
|
||||
update_sender_last_heard =
|
||||
encrypted && !encrypted.strip.empty? && from_id && rx_time
|
||||
|
||||
row = [
|
||||
msg_id,
|
||||
rx_time,
|
||||
@@ -1133,6 +1136,18 @@ def insert_message(db, m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if update_sender_last_heard
|
||||
with_busy_retry do
|
||||
db.execute <<~SQL, [rx_time, rx_time, from_id, rx_time]
|
||||
UPDATE nodes
|
||||
SET last_heard = ?,
|
||||
first_heard = COALESCE(first_heard, ?)
|
||||
WHERE node_id = ?
|
||||
AND COALESCE(last_heard, 0) <= ?
|
||||
SQL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Resolve a node reference to the canonical node ID when possible.
|
||||
|
||||
@@ -1004,6 +1004,13 @@ RSpec.describe "Potato Mesh Sinatra app" do
|
||||
expect(row["to_id"]).to eq(receiver_id)
|
||||
expect(row["text"]).to be_nil
|
||||
expect(row["encrypted"]).to eq(encrypted_b64)
|
||||
|
||||
node_row = db.get_first_row(
|
||||
"SELECT last_heard FROM nodes WHERE node_id = ?",
|
||||
[sender_id],
|
||||
)
|
||||
|
||||
expect(node_row["last_heard"]).to eq(reference_time.to_i)
|
||||
end
|
||||
|
||||
get "/api/messages"
|
||||
|
||||
Reference in New Issue
Block a user