stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
115 lines • 4.14 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractSortValue = void 0;
exports.findLastPinnedChannelIndex = findLastPinnedChannelIndex;
exports.findPinnedAtSortOrder = findPinnedAtSortOrder;
exports.shouldConsiderPinnedChannels = exports.shouldConsiderArchivedChannels = exports.isChannelPinned = exports.isChannelArchived = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var isChannelPinned = channel => {
if (!channel) {
return false;
}
var member = channel.state.membership;
return !!(member != null && member.pinned_at);
};
exports.isChannelPinned = isChannelPinned;
var isChannelArchived = channel => {
if (!channel) {
return false;
}
var member = channel.state.membership;
return !!(member != null && member.archived_at);
};
exports.isChannelArchived = isChannelArchived;
var shouldConsiderArchivedChannels = filters => {
if (!filters) {
return false;
}
return typeof filters.archived === 'boolean';
};
exports.shouldConsiderArchivedChannels = shouldConsiderArchivedChannels;
var extractSortValue = ({
atIndex,
sort,
targetKey
}) => {
var _option$targetKey, _option;
if (!sort) {
return null;
}
var option = null;
if (Array.isArray(sort)) {
var _sort$atIndex;
option = (_sort$atIndex = sort[atIndex]) != null ? _sort$atIndex : null;
} else {
var index = 0;
for (var key in sort) {
if (index !== atIndex) {
index++;
continue;
}
if (key !== targetKey) {
return null;
}
option = sort;
break;
}
}
return (_option$targetKey = (_option = option) == null ? void 0 : _option[targetKey]) != null ? _option$targetKey : null;
};
exports.extractSortValue = extractSortValue;
var shouldConsiderPinnedChannels = sort => {
var value = extractSortValue({
atIndex: 0,
sort,
targetKey: 'pinned_at'
});
if (typeof value !== 'number') {
return false;
}
return Math.abs(value) === 1;
};
exports.shouldConsiderPinnedChannels = shouldConsiderPinnedChannels;
function findPinnedAtSortOrder({
sort
}) {
if (!sort) {
return null;
}
if (Array.isArray(sort)) {
var _sort = (0, _slicedToArray2.default)(sort, 1),
option = _sort[0];
if (!(option != null && option.pinned_at)) {
return null;
}
return option.pinned_at;
} else {
if (!sort.pinned_at) {
return null;
}
return sort.pinned_at;
}
}
function findLastPinnedChannelIndex({
channels
}) {
var lastPinnedChannelIndex = null;
for (var _iterator = _createForOfIteratorHelperLoose(channels), _step; !(_step = _iterator()).done;) {
var channel = _step.value;
if (!isChannelPinned(channel)) {
break;
}
if (typeof lastPinnedChannelIndex === 'number') {
lastPinnedChannelIndex++;
} else {
lastPinnedChannelIndex = 0;
}
}
return lastPinnedChannelIndex;
}
//# sourceMappingURL=index.js.map