@visit-x/vxunread-messages
v2.0.2
Published
This npm package represents the core unread messages functionality for a client. The number of unread messages from a certain model or from all client's models will come as a property after integrating this library into your project. This value will be li
Downloads
4
Readme
SUMMARY
This npm package represents the core unread messages functionality for a client. The number of unread messages from a certain model or from all client's models will come as a property after integrating this library into your project. This value will be live, updating itself event-based.
The project "vxunread-messages" is completely isolated from other Campoint softwares that implement the messaging between a client and a model. For instance, "vxmessenger". They can co-exist in any application due to their technical independence.
TECHNICAL DOCUMENTATION
The only exported element from the library is an high-order componenent, which will send to the wrapped component the property "unreadMessages" of type number with the desired value. The initial/default value is going to be 0.
The high-order component will receive only one argument, the wrapped component. This component for receiving the unread messages will have to give in its props, the "connection" property, which will contain the login and communication information between the client and the model.
interface Connection {
partner?: {
id: string; // The the model's platform's ID - for instance vx-models or vxpages.
key: string; // The model's ID
};
webToken: string; // client's webToken for the login process
userKey: string; // client's userKey for the login process
onError: (error: { code: number, reason: string }) => void; // a function for dealing with any back-end error
}
If no partner is set in connection property, the "unreadMesssages" property will be of type Array<{ unreadMessages: number, partner: { id: string, key: string}}> and will contain the unread messages for all the models that interacted at some point with our client (the client has a channel already created).
Example
import withUnreadMessages from '@visit-x/vxunread-messages';
const UnreadMessagesDisplayer = (props: Props) => (
<div>Unread messages from your specified model: {props.unreadMessages}</div>
);
const UnreadMessages = withUnreadMessages(UnreadMessagesDisplayer);
const connection = {
userKey:"888888",
webToken:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1Njc0MjgwNDYsInBhcnRuZXJUeXBlIjoiY3AiLCJwYXJ0bmVySWQiOjgxNzAsInJvbGVJZCI6MTAwMDAsImd1ZXN0SWQiOjg1NTE2MjUsInVzZXJQb29sSWQiOjgxNzAsInBmbUlkIjoxNTAzLCJwZm1TdWJyZWYiOiIifQ.NppVfb1bIDLHuq4HTAmEeYPn2EIIRDVEZsSSH1PrAK0",
partner: {
id: "8320",
key: "8470922"
},
onError: (error) => { console.log(`Error's reason is ${error.reason}`); }
};
render() {
return (
<UnreadMessages connection={connection} />
);
}
'''