vicariousdrama / cornychat

🌽 Corny Chat is an open source audio space built on Jam that integrates Nostr and Lightning
https://cornychat.com
GNU Affero General Public License v3.0
21 stars 6 forks source link

Force local user profile update on extension login #21

Closed vicariousdrama closed 5 months ago

vicariousdrama commented 6 months ago

Consider this identity

  {
    "id": "YDb3ZA0SP9UpfSO8xv5ja4gIw7Qs6qx7dGa7XtqEjQ8",
    "identities": [
      {
        "type": "nostr",
        "id": "npub1dmahfent0mtlh8ahhzu0ztslhw470azcyw3n599vvrxfysfg25mqurhrpq",
        "loginTime": 1710466125,
        "loginId": "0cd3ca37d9e2159eee468d992aade8e8c65b820f965e8dbdfeae6e44beff005c",
        "loginSig": "6e6f7f816509cf75ddbdae0eac280dde79daf63459d131c875d2960e13475ca11759d295309bfa44076b168c3725682e7fd4a2b5e18d91869943d6fcc01401c9"
      }
    ],
    "avatar": "https://nostr.build/i/nostr.build_a1a006a9d6a6246dce3302ce2c65ae13682b65837fe4d4afdc486fd7591dcfab.gif"
  },

On login, if "name" field is not present, but a nostr identity is, try to fetch the kind 0 for the npub in the id field.

Here is sample kind 0 for this user

{
  "id": "24471171cc058128efe7d88be4c402d84fab7b6c7cf6e4326b4498c95c6f4655",
  "pubkey": "6efb74e66b7ed7fb9fb7b8b8f12e1fbbabe7f45823a33a14ac60cc9241285536",
  "created_at": 1701844627,
  "kind": 0,
  "tags": [],
  "content": "{\"picture\":\"https://nostr.build/i/nostr.build_a1a006a9d6a6246dce3302ce2c65ae13682b65837fe4d4afdc486fd7591dcfab.gif\",\"nip05\":\"chef4brains@nostrpurple.com\",\"banner\":\"https://nostr.build/i/nostr.build_c5835e338d784247e88dc4a033a073d856216d49e3afe93d8b37451271f5dc34.jpeg\",\"damus_donation_v2\":100,\"about\":\"I cook, I learn, I HODL. \\n\\n‘If more of us valued food and cheer and song above hoarded gold, it would be a merrier world.’ Tolkien\\n\\n#AUStrich\\n#AUStriches \\n#bitcoin\\n#chefstr\",\"website\":\"\",\"lud16\":\"chef4brains@getalby.com\",\"display_name\":\"chef4₿rains\",\"name\":\"chef4₿rains\"}",
  "sig": "4e066509a59d4e3c22ce5353382f0afd78b0cd38d35bb8e5c37a447268db1b2f953fa5f31c1eba164c8a01acfd052096c4c9927b20d427e861b644c56bda352a"
}

The content field needs parsed, and the embedded name field should reveal as chef4â‚¿rains

Save locally, and PUT to the server.