0.0.2 • Published 5 months ago

ns-query v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Nostr protocol react-query based client SDK for Ecency

NPM JavaScript Style Guide

Overview

This repository contains react-query based SDK for Ececny vision and mobile projects

Installation

yarn add @ecency/ns-query

npm install @ecency/ns-query

Setup

  1. Add ChatContextProvider to your App.tsx as root element
  2. Pass there current user information via props
<ChatContextProvider activeUsername={} activeUserData={} />
  1. Use!

Queries

High-level queries

  1. Channels query – use this query for fetching user joined and created channels
    • Requirements – current user and its credentials
  2. Community channel query – use this query for fetching the community channel from its posting json metadata
    • Requirements – nothing
  3. Direct contacts query – use this query for fetching direct contacts of active user
    • Requirements – current user and its credentials
  4. Left community channels query – use this query for fetching community channels from where active user had been left
    • Requirements – current user and its credentials
  5. Messages query – use this query for fetching channel or contact messages based on their username
    • Requirements – current user and its credentials
    • Note – this query are invalidating each N seconds periodically to keep messages fresh
  6. Joined community team query – use this query for fetching community team member which joined to chats and assigned to moderation team
    • Requirements – current user and its credentials

Low-level queries

Low-level queries builds the high-level queries above 1. Direct messages query – fetches direct messages by given direct contacts 2. Public messages query – fetches public messages by given channels

  • Both of them builds messages query and shouldn't be used for messages management.
  1. Get user profile query – fetching user metadata from Nostr by given public key

Mutations

High-level mutations

All mutations marked as override channel metadata means that mutation could by run only by channel owner 1. Add community channel – adds community channel to community list(only locally w/o saving in Nostr or Ecency) 2. Add direct contact – adding direct contact to contacts list 3. Create community chat – creates community channel and make current user as owner 4. Fetch previous messages – fetches channel's previous messages and appends to messages query 5. Hide messages in channel – hides message in a channel by owner(it overrides community channel metadata) 6. Import chats by keys – imports existing chat account and saves encrypted chat keys to accounts posting metadata 7. Join chat – creates chatting account and saves encrypted chat keys to account metadata 8. Leave community channel – leaves community channel 9. Logout from chats – clears current active user chatting session 10. Resend message – resends failed messages which already exists in queries with status 2 11. Restore chat by PIN – restores logged out account session by PIN 12. Send message – sends message to specific direct contact or channel 13. Update channel's blocked users – updates channel's blocked users(overrides channel metadata) 14. Update channel's moderator – add, remove or update channel's moderator 15. Update community channel – updates community channel's information(overrides channel metadata)

Low-level mutations

  1. Find healthy relay – finds healthy Nostr relay and return its host(uses by library itself – no need to re-use it)
  2. Send direct message – sends message to direct contact(uses in Send message)
  3. Send public message – sends message to channel(uses in Send message)
  4. Update left channels – updates left channels list(uses in add community channel and Leave community channel)

Misc

useActiveUserSwitching – invalidates all Nostr queries each time when active user changes(no need to call, library use it itself).

useAutoScrollInChatBox – uses for auto-scrolling to the end of chatbox(available in Web only)