stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
45 lines • 1.45 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGroupedAttachments = void 0;
var _react = require("react");
var _streamChat = require("stream-chat");
var useGroupedAttachments = attachments => {
return (0, _react.useMemo)(() => {
if (!(attachments != null && attachments.length)) {
return {
giphys: [],
audios: [],
images: [],
videos: [],
files: [],
voiceRecordings: []
};
}
return attachments.reduce((acc, attachment) => {
if ((0, _streamChat.isGiphyAttachment)(attachment)) {
acc.giphys.push(attachment);
} else if ((0, _streamChat.isVoiceRecordingAttachment)(attachment)) {
acc.voiceRecordings.push(attachment);
} else if ((0, _streamChat.isAudioAttachment)(attachment)) {
acc.audios.push(attachment);
} else if ((0, _streamChat.isImageAttachment)(attachment)) {
acc.images.push(attachment);
} else if ((0, _streamChat.isVideoAttachment)(attachment)) {
acc.videos.push(attachment);
} else if ((0, _streamChat.isFileAttachment)(attachment)) {
acc.files.push(attachment);
}
return acc;
}, {
giphys: [],
audios: [],
images: [],
videos: [],
files: [],
voiceRecordings: []
});
}, [attachments]);
};
exports.useGroupedAttachments = useGroupedAttachments;
//# sourceMappingURL=useGroupedAttachments.js.map