You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
8 years ago
|
import { createSelector } from 'reselect';
|
||
7 years ago
|
import { List as ImmutableList } from 'immutable';
|
||
8 years ago
|
|
||
8 years ago
|
const getAccountBase = (state, id) => state.getIn(['accounts', id], null);
|
||
8 years ago
|
const getAccountCounters = (state, id) => state.getIn(['accounts_counters', id], null);
|
||
8 years ago
|
const getAccountRelationship = (state, id) => state.getIn(['relationships', id], null);
|
||
8 years ago
|
|
||
8 years ago
|
export const makeGetAccount = () => {
|
||
8 years ago
|
return createSelector([getAccountBase, getAccountCounters, getAccountRelationship], (base, counters, relationship) => {
|
||
8 years ago
|
if (base === null) {
|
||
|
return null;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return base.merge(counters).set('relationship', relationship);
|
||
8 years ago
|
});
|
||
|
};
|
||
8 years ago
|
|
||
8 years ago
|
export const makeGetStatus = () => {
|
||
8 years ago
|
return createSelector(
|
||
|
[
|
||
|
(state, id) => state.getIn(['statuses', id]),
|
||
|
(state, id) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
|
||
|
(state, id) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
|
||
|
(state, id) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
|
||
|
],
|
||
|
|
||
|
(statusBase, statusReblog, accountBase, accountReblog) => {
|
||
|
if (!statusBase) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (statusReblog) {
|
||
|
statusReblog = statusReblog.set('account', accountReblog);
|
||
|
} else {
|
||
|
statusReblog = null;
|
||
|
}
|
||
|
|
||
|
return statusBase.withMutations(map => {
|
||
|
map.set('reblog', statusReblog);
|
||
|
map.set('account', accountBase);
|
||
|
});
|
||
8 years ago
|
}
|
||
8 years ago
|
);
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
const getAlertsBase = state => state.get('alerts');
|
||
8 years ago
|
|
||
8 years ago
|
export const getAlerts = createSelector([getAlertsBase], (base) => {
|
||
8 years ago
|
let arr = [];
|
||
|
|
||
|
base.forEach(item => {
|
||
|
arr.push({
|
||
|
message: item.get('message'),
|
||
|
title: item.get('title'),
|
||
|
key: item.get('key'),
|
||
8 years ago
|
dismissAfter: 5000,
|
||
|
barStyle: {
|
||
8 years ago
|
zIndex: 200,
|
||
|
},
|
||
8 years ago
|
});
|
||
|
});
|
||
|
|
||
|
return arr;
|
||
|
});
|
||
8 years ago
|
|
||
|
export const makeGetNotification = () => {
|
||
|
return createSelector([
|
||
|
(_, base) => base,
|
||
8 years ago
|
(state, _, accountId) => state.getIn(['accounts', accountId]),
|
||
8 years ago
|
], (base, account) => {
|
||
|
return base.set('account', account);
|
||
|
});
|
||
|
};
|
||
8 years ago
|
|
||
|
export const getAccountGallery = createSelector([
|
||
7 years ago
|
(state, id) => state.getIn(['timelines', `account:${id}:media`, 'items'], ImmutableList()),
|
||
8 years ago
|
state => state.get('statuses'),
|
||
|
], (statusIds, statuses) => {
|
||
7 years ago
|
let medias = ImmutableList();
|
||
8 years ago
|
|
||
|
statusIds.forEach(statusId => {
|
||
|
const status = statuses.get(statusId);
|
||
|
medias = medias.concat(status.get('media_attachments').map(media => media.set('status', status)));
|
||
|
});
|
||
|
|
||
|
return medias;
|
||
|
});
|