Notify
Properties
name | type | Description |
---|---|---|
notificationList | NotifyResponse [ ] | null | notification list |
Methods
name | type | Parameters Description | response |
---|---|---|---|
changeNotificationStatus | function | 1.messages: string[] 2.status:MessageStatus | Promise:SearchUsersResponse |
Prerequisites
init() see: init
register() see: register
login() see: login
event see: event
Init and get Client
To use the functions of the current module, please complete the following steps first.
tip
After successful login, you can get the secret key pair from the returned result
import { useEffect, useState } from 'react';
import { Client } from '@web3mq/client';
export const App = () => {
const [fastestUrl, setFastUrl] = useState<string | null>(null);
useEffect(() => {
Client.init({
connectUrl: '', //
app_key: 'app_key', // temporary authorization key obtained by applying, will be removed in future testnets and mainnet
}).then(data => {
setFastUrl(data);
});
}, [])
if (!fastestUrl) return;
const {
tempPrivateKey,
tempPublicKey,
pubkeyExpiredTimestamp,
mainPrivateKey,
mainPublicKey,
} = loginRes
const keys = {
PrivateKey: tempPrivateKey,
PublicKey: tempPublicKey,
userid: localStorage.getItem('userid')
};
const client = Client.getInstance(keys);
return (
<Child client={client} />
)
}
Methods
ChangeNotificationStatus
Change notification status.
import { Client } from '@web3mq/client';
interface IProps {
client: Client;
}
export const Child = (props: IProps) => {
const { client } = props;
return (
<div>
<button
onClick={() => {
client.notify.changeNotificationStatus(['notifyId'], 'delivered');
}}>
Change Notification Status
</button>
</div>
);
};
Get NotificationList
Get the list of notifications in the
notification.getList
event.
import { useEffect } from 'react';
import { Client } from '@web3mq/client';
interface IProps {
client: Client;
}
export const Child = (props: IProps) => {
const { client } = props;
const handleEvent = (event: { type: any }) => {
if (event.type === 'notification.getList') {
console.log(client.notify.notificationList);
}
};
useEffect(() => {
client.on('notification.getList', handleEvent);
return () => {
client.off('notification.getList');
};
}, []);
return <div>Notify Test</div>;
};