damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README

commit c0f612e2d3ae551bb931e76d3227d1506d875696
parent 347c6617fee0fb61a62dbcd9ce6cc4b0f8783966
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 11 Nov 2022 12:36:24 -0800

web: always use the latest profile

Diffstat:
Mweb/damus.js | 26+++++++++++++++-----------
Mweb/index.html | 2+-
2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/web/damus.js b/web/damus.js @@ -260,6 +260,8 @@ function process_event(model, ev) process_json_content(ev) else if (ev.kind === 5) process_deletion_event(model, ev) + else if (ev.kind === 0) + process_profile_event(model, ev) const last_notified = get_local_state('last_notified_date') if (notified && (last_notified == null || ((ev.created_at*1000) > last_notified))) { @@ -314,22 +316,24 @@ function handle_home_event(ids, model, relay, sub_id, ev) { model.done_init = true model.pool.unsubscribe(ids.account, [relay]) break - case 0: - handle_profile_event(model, ev) - break } case ids.profiles: - try { - model.profile_events[ev.pubkey] = ev - model.profiles[ev.pubkey] = JSON.parse(ev.content) - } catch { - console.log("failed to parse", ev.content) - } + break } } -function handle_profile_event(model, ev) { - console.log("PROFILE", ev) +function process_profile_event(model, ev) { + const prev_ev = model.profile_events[ev.pubkey] + if (prev_ev) { + if (ev.id === prev_ev.id) + return + + if (prev_ev.created_at > ev.created_at) + return + } + + model.profile_events[ev.pubkey] = ev + model.profiles[ev.pubkey] = JSON.parse(ev.content) } function send_initial_filters(account_id, pubkey, relay) { diff --git a/web/index.html b/web/index.html @@ -41,7 +41,7 @@ <script src="noble-secp256k1.js?v=1"></script> <script src="bech32.js?v=1"></script> <script src="nostr.js?v=6"></script> - <script src="damus.js?v=58"></script> + <script src="damus.js?v=59"></script> <script> // I have to delay loading to wait for nos2x const relay = setTimeout(damus_web_init, 100)