This repository contains react-query based SDK for Ececny vision and mobile projects
yarn add @ecency/ns-query
npm install @ecency/ns-query
- Add
ChatContextProvider
to yourApp.tsx
as root element - Pass there current user information via props
<ChatContextProvider activeUsername={} activeUserData={} />
- Use!
- Channels query – use this query for fetching user joined and created channels
- Requirements – current user and its credentials
- Community channel query – use this query for fetching the community channel from its posting json metadata
- Requirements – nothing
- Direct contacts query – use this query for fetching direct contacts of active user
- Requirements – current user and its credentials
- Left community channels query – use this query for fetching community channels from where active user had been left
- Requirements – current user and its credentials
- 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
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- Created channels query – use this query for fetching created channels by current Nostr account
- Requirements – current user and its credentials
- Joined channels query – use this query for fetching all channels where current Nostr account was joined
- Requirements – current user and its credentials
- Last message query – fetch last message for specific contact or channel
- Requirements – current user and its credentials
Low-level queries builds the high-level queries above
- Direct messages query – fetches direct messages by given direct contacts
- Public messages query – fetches public messages by given channels
- Both of them builds messages query and shouldn't be used for messages management.
- Get user profile query – fetching user metadata from Nostr by given public key
All mutations marked as override channel metadata means that mutation could by run only by channel owner
- Add community channel – adds community channel to community list(only locally w/o saving in Nostr or Ecency)
- Add direct contact – adding direct contact to contacts list
- Create community chat – creates community channel and make current user as owner
- Fetch previous messages – fetches channel's previous messages and appends to messages query
- Hide messages in channel – hides message in a channel by owner(it overrides community channel metadata)
- Import chats by keys – imports existing chat account and saves encrypted chat keys to accounts posting metadata
- Join chat – creates chatting account and saves encrypted chat keys to account metadata
- Leave community channel – leaves community channel
- Logout from chats – clears current active user chatting session
- Resend message – resends failed messages which already exists in queries with status
2
- Restore chat by PIN – restores logged out account session by PIN
- Send message – sends message to specific direct contact or channel
- Update channel's blocked users – updates channel's blocked users(overrides channel metadata)
Update channel's moderator – add, remove or update channel's moderator- Update community channel – updates community channel's information(overrides channel metadata)
- Find healthy relay – finds healthy Nostr relay and return its host(uses by library itself – no need to re-use it)
- Send direct message – sends message to direct contact(uses in Send message)
- Send public message – sends message to channel(uses in Send message)
- Update left channels – updates left channels list(uses in add community channel and Leave community channel)
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)