|
| 1 | +A custom hook to handle message pinning. It provides the permission status of the connected user and a function to toggle pinned status on the message. |
| 2 | + |
| 3 | +| Parameter | Type | Description | |
| 4 | +| ------------------------------------ | -------------------------------------------------------- | --------------------------------------------------------------- | |
| 5 | +| `message` | [object](https://getstream.io/chat/docs/#message_format) | The message to be handled. | |
| 6 | +| `permissions` | object | The user roles allowed to pin messages in various channel types | |
| 7 | +| `notifications` | object | An object containing the following properties: | |
| 8 | +| `notifications.notify` | func | A function that adds notification text to message | |
| 9 | +| `notifications.getErrorNotification` | func | A function that returns an error message | |
| 10 | + |
| 11 | +It returns the following object: |
| 12 | + |
| 13 | +| Parameter | Type | Description | |
| 14 | +| ----------- | ------- | -------------------------------------------------- | |
| 15 | +| `canPin` | boolean | Whether or not the connected user can pin messages | |
| 16 | +| `handlePin` | func | Function to toggle the pinned status of a message | |
| 17 | + |
| 18 | +```json |
| 19 | +import { usePinHandler } from 'stream-chat-react'; |
| 20 | +const MyCustomMessageComponent = (props) => { |
| 21 | + const { addNotification, getPinMessageErrorNotification, message, pinPermissions } = props; |
| 22 | + const { canPin, handlePin } = usePinHandler(message, pinPermissions, { |
| 23 | + notify: addNotification, |
| 24 | + getErrorNotification: getPinMessageErrorNotification, |
| 25 | + }); |
| 26 | + const handleClick = () => { |
| 27 | + if (canPin) handlePin(message); |
| 28 | + } |
| 29 | + return ( |
| 30 | + <div className={message.pinned ? 'pinned' : ''} onClick={handleClick}> |
| 31 | + <p>{message.text}</p> |
| 32 | + </div> |
| 33 | + ); |
| 34 | +}; |
| 35 | +``` |
0 commit comments