Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chatpreview bug #1063

Merged
merged 20 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6d61a4e
ci(restapi): 🎉 cut beta release to restapi-v0.0.1-alpha.61
mohammeds1992 Jan 3, 2024
f07f84b
fix: Merge branch 'alpha' into alpha-deployment
mohammeds1992 Jan 3, 2024
38c7539
ci(restapi): 🎉 cut beta release to restapi-v0.0.1-alpha.62
mohammeds1992 Jan 3, 2024
25f6f4f
fix: Merge branch 'alpha' into alpha-deployment
mohammeds1992 Jan 15, 2024
a1dfaa9
ci(restapi): 🎉 cut release to restapi-v0.9.0
mohammeds1992 Jan 15, 2024
f90e416
ci(restapi): 🎉 cut beta release to restapi-v0.0.1-alpha.63
mohammeds1992 Jan 15, 2024
f93c645
fix: Merge branch 'alpha' into alpha-deployment
mohammeds1992 Jan 18, 2024
6a91107
fix: fix errors
mohammeds1992 Jan 18, 2024
65d46c6
ci(restapi): 🎉 cut beta release to restapi-v0.0.1-alpha.64
mohammeds1992 Jan 18, 2024
e597fe5
fix: changed stream type to any
mishramonalisha76 Jan 18, 2024
859341e
ci(uiweb): 🎉 cut beta release to uiweb-v0.0.1-alpha.16
mohammeds1992 Jan 18, 2024
d75a862
fix: minor change
mohammeds1992 Jan 18, 2024
e57160a
ci(uiweb): 🎉 cut beta release to uiweb-v0.0.1-alpha.17
mohammeds1992 Jan 18, 2024
3034c2c
fix: minor fix
mohammeds1992 Jan 18, 2024
2f7f04e
ci(uiweb): 🎉 cut beta release to uiweb-v0.0.1-alpha.36
mohammeds1992 Jan 18, 2024
bb3bdf5
fix: Merge branch 'alpha' into alpha-deployment
mohammeds1992 Jan 19, 2024
a05ba4a
ci(uiweb): 🎉 cut beta release to uiweb-v0.0.1-alpha.37
mohammeds1992 Jan 19, 2024
9c7e4cc
fix: fixed bugs in chatpreviewlist
mishramonalisha76 Jan 24, 2024
fc99d81
fix: fixed pagination bug and added functions for preload
mishramonalisha76 Jan 24, 2024
87778a6
fix: added review comments
mishramonalisha76 Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,159 changes: 3,159 additions & 0 deletions packages/dist/packages/restapi/packages/restapi/CHANGELOG.md

Large diffs are not rendered by default.

2,745 changes: 2,745 additions & 0 deletions packages/dist/packages/restapi/packages/restapi/PushChatLowLevelAPI.md

Large diffs are not rendered by default.

1,490 changes: 1,490 additions & 0 deletions packages/dist/packages/restapi/packages/restapi/PushNotificationLowLevelAPI.md

Large diffs are not rendered by default.

5,857 changes: 5,857 additions & 0 deletions packages/dist/packages/restapi/packages/restapi/README.md

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions packages/dist/packages/socket/packages/socket/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Changelog

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [0.5.2](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.5.1...socket-0.5.2) (2023-08-03)


### Bug Fixes

* socket options ([#601](https://github.com/ethereum-push-notification-service/push-sdk/issues/601)) ([d821535](https://github.com/ethereum-push-notification-service/push-sdk/commit/d821535d3e800c8821206fc387b346c990c02b5a))



## [0.5.1](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.5.0...socket-0.5.1) (2023-05-22)


### Bug Fixes

* fixed nft socket ([#413](https://github.com/ethereum-push-notification-service/push-sdk/issues/413)) ([0d8c3ab](https://github.com/ethereum-push-notification-service/push-sdk/commit/0d8c3ab628ec29903bcc051254e5c54e94a2325e))



# [0.5.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.4.1...socket-0.5.0) (2023-04-27)


### Bug Fixes

* **component:** env type in demo react and uiweb ([#225](https://github.com/ethereum-push-notification-service/push-sdk/issues/225)) ([ff1113a](https://github.com/ethereum-push-notification-service/push-sdk/commit/ff1113adb226aee4c9f6ccdfa488e59b47ca9b9e))
* **component:** group chat socket event ([#251](https://github.com/ethereum-push-notification-service/push-sdk/issues/251)) ([17f0892](https://github.com/ethereum-push-notification-service/push-sdk/commit/17f0892570a6f2318d515a7d6e297a71463fe490))


### Features

* add local env to socket config file ([#334](https://github.com/ethereum-push-notification-service/push-sdk/issues/334)) ([db4171e](https://github.com/ethereum-push-notification-service/push-sdk/commit/db4171e57bcba2b86f798072fc37d9f082236ad0))



## [0.4.2](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.4.1...socket-0.4.2) (2023-03-22)


### Bug Fixes

* **component:** env type in demo react and uiweb ([#225](https://github.com/ethereum-push-notification-service/push-sdk/issues/225)) ([ff1113a](https://github.com/ethereum-push-notification-service/push-sdk/commit/ff1113adb226aee4c9f6ccdfa488e59b47ca9b9e))
* **component:** group chat socket event ([#251](https://github.com/ethereum-push-notification-service/push-sdk/issues/251)) ([17f0892](https://github.com/ethereum-push-notification-service/push-sdk/commit/17f0892570a6f2318d515a7d6e297a71463fe490))



## [0.4.1](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.4.0...socket-0.4.1) (2023-02-28)


### Bug Fixes

* remove mandatory api key for chat socket connection ([dd79bf7](https://github.com/ethereum-push-notification-service/push-sdk/commit/dd79bf7fc3a4a7e0913e399fff3e1325b9143e13))



# [0.4.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.3.1...socket-0.4.0) (2023-02-28)


### Bug Fixes

* send message signature fixes ([#203](https://github.com/ethereum-push-notification-service/push-sdk/issues/203)) ([9a3c448](https://github.com/ethereum-push-notification-service/push-sdk/commit/9a3c4484f2c1ac5f7abd2796801da626caa91629))


### Features

* **component:** Added Group Chat Functionality ([#122](https://github.com/ethereum-push-notification-service/push-sdk/issues/122)) ([5bf341f](https://github.com/ethereum-push-notification-service/push-sdk/commit/5bf341f6f60a6786be47f668fa3ed1b15a66be88))



# [0.4.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.3.1...socket-0.4.0) (2023-02-15)


### Features

* **component:** Added Group Chat Functionality ([#122](https://github.com/ethereum-push-notification-service/push-sdk/issues/122)) ([5bf341f](https://github.com/ethereum-push-notification-service/push-sdk/commit/5bf341f6f60a6786be47f668fa3ed1b15a66be88))



## [0.3.1](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.3.0...socket-0.3.1) (2023-02-03)


### Bug Fixes

* Metamask reject handled ([#136](https://github.com/ethereum-push-notification-service/push-sdk/issues/136)) ([46a20b7](https://github.com/ethereum-push-notification-service/push-sdk/commit/46a20b751e655a526168c8ae7c400211f3b62b15))



# [0.3.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.2.0...socket-0.3.0) (2023-01-27)


### Features

* inc version ([74c7e63](https://github.com/ethereum-push-notification-service/push-sdk/commit/74c7e63a3e5e5131fcd53d192a076c09c37989e9))



# [0.2.1](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.1.0...socket-0.2.0) (2023-01-27)


### Features

* add chat wss ([aba9f17](https://github.com/ethereum-push-notification-service/push-sdk/commit/aba9f17c037fe59e44729c9b49c8eaa9e2a71630))
* add new chat events for websocket ([429061f](https://github.com/ethereum-push-notification-service/push-sdk/commit/429061f2f906420f5fe3d854d3602277dae1021b))
* add new types for create wss function ([d5a11ed](https://github.com/ethereum-push-notification-service/push-sdk/commit/d5a11ed9f5336f0a8197707cbe29848eb2faad54))
* add validation for chat websocket ([9b77ff7](https://github.com/ethereum-push-notification-service/push-sdk/commit/9b77ff7102475f8b4187028c9fc5cb68c94c4985))



# [0.1.0](https://github.com/ethereum-push-notification-service/sdk/compare/socket-0.0.1...socket-0.1.0) (2022-10-07)


### Features

* **socket:** make it stable ([d0db84f](https://github.com/ethereum-push-notification-service/sdk/commit/d0db84fb6f53c0e612b2fa209eae813cc6dc51c2))



## 0.0.1 (2022-10-05)
229 changes: 229 additions & 0 deletions packages/dist/packages/socket/packages/socket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# Deprecation Notice

**Important**: This package will be deprecated in future releases. We recommend migrating to [@pushprotocol/restapi](https://www.npmjs.com/package/@pushprotocol/restapi) for continued support and updates. Please refer to the [Stream Documentation](https://push.org/docs/chat/build/stream-chat/) for instructions on transitioning to the new package.

# socket

This package gives access to Push Protocol (Push Nodes) using Websockets built on top of [Socket.IO](https://socket.io/docs/v4/client-api/). Visit [Developer Docs](https://docs.push.org/developers) or [Push.org](https://push.org) to learn more.

# Index

- [How to use in your app?](#how-to-use-in-your-app)
- [Installation](#installation)
- [Import SDK](#import-sdk)
- [About blockchain agnostic address format](#about-blockchain-agnostic-address-format)
- [Socket SDK Features](#socket-sdk-features)
- [Creating a socket connection object](#creating-a-socket-connection-object)
- [For notification](#for-notification)
- [For chat](#for-chat)
- [Connect the socket connection object](#connect-the-socket-connection-object)
- [Disconnect the socket connection object](#disconnect-the-socket-connection-object)
- [Subscribing to Socket Events](#subscribing-to-socket-events)
- [Examples](#examples)
- [Basic example of using SDK sockets in a React App](#basic-example-of-using-sdk-sockets-in-a-react-app)

# How to use in your app?

## Installation

```
yarn add @pushprotocol/socket@latest ethers@^5.6
```

or

```
npm install @pushprotocol/socket@latest ethers@^5.6
```

## Import SDK

```typescript
import { createSocketConnection, EVENTS } from '@pushprotocol/socket';
```

## **About blockchain agnostic address format**

In any of the below methods (unless explicitly stated otherwise) we accept either -

- [CAIP format](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#test-cases): for any on chain addresses **_We strongly recommend using this address format_**. [Learn more about the format and examples](https://docs.push.org/developers/concepts/web3-notifications).
(Example : `eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb`)

- ETH address format: only for backwards compatibility.
(Example: `0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb`)

### Chat blockchain agnostic address format

**Note** - For chat related apis, the address is in the format: eip155:<address> instead of eip155:<chainId>:<address>, we call this format **Partial CAIP**
(Example : `eip155:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb`)

# Socket SDK Features

## **Creating a socket connection object**

### **For notification**

```typescript
const pushSDKSocket = createSocketConnection({
user: 'eip155:11155111:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb', // CAIP, see below
env: 'staging',
socketOptions: { autoConnect: false },
});
```

### **For chat**

```typescript
const pushSDKSocket = createSocketConnection({
user: 'eip155:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb',
env: 'staging',
socketType: 'chat',
socketOptions: { autoConnect: true, reconnectionAttempts: 3 },
});
```

IMPORTANT: create the connection object in your app only when you have the `user` address available since its mandatory.

**`autoConnect`**: Generally if we don't pass `autoConnect: false` then the socket connection is automatic once the object is created. Now since we may or may not have the account address handy and wish to start the connection during instantiation so this option makes it easier for us to choose when we want to `connect` or not!

Allowed Options (params with _ are mandatory)
| Param | Type | Default | Remarks |
|----------|---------|---------|--------------------------------------------|
| user_ | string | - | user account address (CAIP) |
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'|
| socketType | 'notification' | 'chat' | 'notification' | socket type |
| socketOptions | object | - | supports the same as [SocketIO Options](https://socket.io/docs/v4/client-options/) |

## **Connect the socket connection object**

```typescript
pushSDKSocket.connect();
```

## **Disconnect the socket connection object**

```typescript
pushSDKSocket.disconnect();
```

## **Subscribing to Socket Events**

```typescript
pushSDKSocket.on(EVENTS.CONNECT, () => {});

pushSDKSocket.on(EVENTS.DISCONNECT, () => {});

pushSDKSocket.on(EVENTS.USER_FEEDS, (feedItem) => {
// feedItem is the notification data when that notification was received
});

pushSDKSocket.on(EVENT.CHAT_RECEIVED_MESSAGE, (message) => {
// message is the message object data whenever a new message is received
});

pushSDKSocket.on(EVENT.CHAT_GROUPS, (message) => {
// message is the message object data whenever a group is created or updated
});
```

Supported EVENTS
| EVENT name | When is it triggered? |
|------------|--------------------------------------------|
| EVENTS.CONNECT | whenever the socket is connected |
| EVENTS.DISCONNECT | whenever the socket is disconneted |
| EVENTS.USER_FEEDS | whenever a new notification is received by the user after the last socket connection |
| EVENTS.USER_SPAM_FEEDS | whenever a new spam notification is received by the user after the last socket connection |
| EVENT.CHAT_RECEIVED_MESSAGE | whenever a new message is received |
| EVENT.CHAT_GROUPS | whenever a group is created or updated |

# Examples

## Basic example of using SDK sockets in a React App

```
import { useState, useEffect } from "react";
import { createSocketConnection, EVENTS } from '@pushprotocol/socket';

const user = '0xD8634C39BBFd4033c0d3289C4515275102423681';
const chainId = 11155111;

const userCAIP = `eip155:${chainId}:${user}`;

function App() {
const [sdkSocket, setSDKSocket] = useState<any>(null);
const [isConnected, setIsConnected] = useState(sdkSocket?.connected);

const addSocketEvents = () => {
sdkSocket?.on(EVENTS.CONNECT, () => {
setIsConnected(true);
})

sdkSocket?.on(EVENTS.DISCONNECT, () => {
setIsConnected(false);
})

sdkSocket?.on(EVENTS.USER_FEEDS, (feedItem) => {
/**
* "feedItem" is the latest notification received
*/
console.log(feedItem);
})
};

const removeSocketEvents = () => {
sdkSocket?.off(EVENTS.CONNECT);
sdkSocket?.off(EVENTS.DISCONNECT);
};

const toggleConnection = () => {
if (sdkSocket?.connected) {
sdkSocket.disconnect();
} else {
sdkSocket.connect();
}
};


useEffect(() => {
if (sdkSocket) {
addSocketEvents();
}
return () => {
removeSocketEvents();
};
}, [sdkSocket]);

useEffect(() => {
const connectionObject = createSocketConnection({
user: userCAIP,
env: 'dev',
socketOptions: { autoConnect: false }
});


setSDKSocket(connectionObject);

return () => {
if (sdkSocket) {
sdkSocket.disconnect();
}
};
}, []);

return (
<div>
<h1>Socket Hello World</h1>

<div>
<p>Connection Status : {JSON.stringify(isConnected)}</p>

<button onClick={toggleConnection}>{isConnected ? 'disconnect' : 'connect'}</button>
</div>
</div>
);
}

export default App;
```

Please note connecting with sockets and maintaining the state of the connection object in your DAPP might have a different setup like first getting the `user` account and `chainId` and then connecting with socket. You can use [React Context](https://reactjs.org/docs/context.html) for state management.
Loading
Loading