UNPKG

@droppii-org/chat-sdk

Version:

Droppii React Chat SDK

59 lines (58 loc) 2.33 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { GroupSessionTypes } from "../constants/im"; export const isGroupSession = (sessionType) => sessionType ? GroupSessionTypes.includes(sessionType) : false; export const conversationSort = (conversationList, originalList) => { const listWithIndex = (conversationList === null || conversationList === void 0 ? void 0 : conversationList.map((item, index) => { var _a; return (Object.assign(Object.assign({}, item), { originalIndex: (_a = originalList === null || originalList === void 0 ? void 0 : originalList.findIndex((c) => c.conversationID === item.conversationID)) !== null && _a !== void 0 ? _a : index })); })) || []; const arr = []; const filterArr = listWithIndex.filter((c) => { if (!arr.includes(c.conversationID)) { arr.push(c.conversationID); return true; } return false; }); filterArr.sort((a, b) => { if (a.isPinned === b.isPinned) { const aCompare = a.draftTextTime > a.latestMsgSendTime ? a.draftTextTime : a.latestMsgSendTime; const bCompare = b.draftTextTime > b.latestMsgSendTime ? b.draftTextTime : b.latestMsgSendTime; if (aCompare > bCompare) { return -1; } else if (aCompare < bCompare) { return 1; } else { if (!originalList) return 0; return a.originalIndex - b.originalIndex; } } else if (a.isPinned && !b.isPinned) { return -1; } else { return 1; } }); return filterArr.map((_a) => { var { originalIndex } = _a, rest = __rest(_a, ["originalIndex"]); return rest; }); };