Merge tag 'v3.0.0' into hometown-dev

This commit is contained in:
Darius Kazemi
2019-10-08 13:24:20 -07:00
1012 changed files with 31176 additions and 15165 deletions

View File

@ -14,6 +14,7 @@ export default function alerts(state = initialState, action) {
key: state.size > 0 ? state.last().get('key') + 1 : 0,
title: action.title,
message: action.message,
message_values: action.message_values,
}));
case ALERT_DISMISS:
return state.filterNot(item => item.get('key') === action.alert.key);

View File

@ -0,0 +1,22 @@
import Immutable from 'immutable';
import {
BLOCKS_INIT_MODAL,
} from '../actions/blocks';
const initialState = Immutable.Map({
new: Immutable.Map({
account_id: null,
}),
});
export default function mutes(state = initialState, action) {
switch (action.type) {
case BLOCKS_INIT_MODAL:
return state.withMutations((state) => {
state.setIn(['new', 'account_id'], action.account.get('id'));
});
default:
return state;
}
}

View File

@ -107,10 +107,13 @@ function clearAll(state) {
});
};
function appendMedia(state, media) {
function appendMedia(state, media, file) {
const prevSize = state.get('media_attachments').size;
return state.withMutations(map => {
if (media.get('type') === 'image') {
media = media.set('file', file);
}
map.update('media_attachments', list => list.push(media));
map.set('is_uploading', false);
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
@ -148,15 +151,20 @@ const insertSuggestion = (state, position, token, completion, path) => {
});
};
const updateSuggestionTags = (state, token) => {
const prefix = token.slice(1);
const sortHashtagsByUse = (state, tags) => {
const personalHistory = state.get('tagHistory');
return state.merge({
suggestions: state.get('tagHistory')
.filter(tag => tag.toLowerCase().startsWith(prefix.toLowerCase()))
.slice(0, 4)
.map(tag => '#' + tag),
suggestion_token: token,
return tags.sort((a, b) => {
const usedA = personalHistory.includes(a.name);
const usedB = personalHistory.includes(b.name);
if (usedA === usedB) {
return 0;
} else if (usedA && !usedB) {
return -1;
} else {
return 1;
}
});
};
@ -205,6 +213,36 @@ const expiresInFromExpiresAt = expires_at => {
return [300, 1800, 3600, 21600, 86400, 259200, 604800].find(expires_in => expires_in >= delta) || 24 * 3600;
};
const mergeLocalHashtagResults = (suggestions, prefix, tagHistory) => {
prefix = prefix.toLowerCase();
if (suggestions.length < 4) {
const localTags = tagHistory.filter(tag => tag.toLowerCase().startsWith(prefix) && !suggestions.some(suggestion => suggestion.type === 'hashtag' && suggestion.name.toLowerCase() === tag.toLowerCase()));
return suggestions.concat(localTags.slice(0, 4 - suggestions.length).toJS().map(tag => ({ type: 'hashtag', name: tag })));
} else {
return suggestions;
}
};
const normalizeSuggestions = (state, { accounts, emojis, tags, token }) => {
if (accounts) {
return accounts.map(item => ({ id: item.id, type: 'account' }));
} else if (emojis) {
return emojis.map(item => ({ ...item, type: 'emoji' }));
} else {
return mergeLocalHashtagResults(sortHashtagsByUse(state, tags.map(item => ({ ...item, type: 'hashtag' }))), token.slice(1), state.get('tagHistory'));
}
};
const updateSuggestionTags = (state, token) => {
const prefix = token.slice(1);
const suggestions = state.get('suggestions').toJS();
return state.merge({
suggestions: ImmutableList(mergeLocalHashtagResults(suggestions, prefix, state.get('tagHistory'))),
suggestion_token: token,
});
};
export default function compose(state = initialState, action) {
switch(action.type) {
case STORE_HYDRATE:
@ -296,7 +334,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_UPLOAD_REQUEST:
return state.set('is_uploading', true);
case COMPOSE_UPLOAD_SUCCESS:
return appendMedia(state, fromJS(action.media));
return appendMedia(state, fromJS(action.media), action.file);
case COMPOSE_UPLOAD_FAIL:
return state.set('is_uploading', false);
case COMPOSE_UPLOAD_UNDO:
@ -321,7 +359,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_SUGGESTIONS_CLEAR:
return state.update('suggestions', ImmutableList(), list => list.clear()).set('suggestion_token', null);
case COMPOSE_SUGGESTIONS_READY:
return state.set('suggestions', ImmutableList(action.accounts ? action.accounts.map(item => item.id) : action.emojis)).set('suggestion_token', action.token);
return state.set('suggestions', ImmutableList(normalizeSuggestions(state, action))).set('suggestion_token', action.token);
case COMPOSE_SUGGESTION_SELECT:
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
case COMPOSE_SUGGESTION_TAGS_UPDATE:

View File

@ -7,6 +7,7 @@ import {
CONVERSATIONS_FETCH_FAIL,
CONVERSATIONS_UPDATE,
CONVERSATIONS_READ,
CONVERSATIONS_DELETE_SUCCESS,
} from '../actions/conversations';
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'mastodon/actions/accounts';
import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
@ -107,6 +108,8 @@ export default function conversations(state = initialState, action) {
return filterConversations(state, [action.relationship.id]);
case DOMAIN_BLOCK_SUCCESS:
return filterConversations(state, action.accounts);
case CONVERSATIONS_DELETE_SUCCESS:
return state.update('items', list => list.filterNot(item => item.get('id') === action.id));
default:
return state;
}

View File

@ -15,6 +15,7 @@ import settings from './settings';
import push_notifications from './push_notifications';
import status_lists from './status_lists';
import mutes from './mutes';
import blocks from './blocks';
import reports from './reports';
import contexts from './contexts';
import compose from './compose';
@ -31,6 +32,8 @@ import conversations from './conversations';
import suggestions from './suggestions';
import polls from './polls';
import identity_proofs from './identity_proofs';
import trends from './trends';
import missed_updates from './missed_updates';
const reducers = {
dropdown_menu,
@ -49,6 +52,7 @@ const reducers = {
settings,
push_notifications,
mutes,
blocks,
reports,
contexts,
compose,
@ -65,6 +69,8 @@ const reducers = {
conversations,
suggestions,
polls,
trends,
missed_updates,
};
export default combineReducers(reducers);

View File

@ -0,0 +1,21 @@
import { Map as ImmutableMap } from 'immutable';
import { NOTIFICATIONS_UPDATE } from 'mastodon/actions/notifications';
import { APP_FOCUS, APP_UNFOCUS } from 'mastodon/actions/app';
const initialState = ImmutableMap({
focused: true,
unread: 0,
});
export default function missed_updates(state = initialState, action) {
switch(action.type) {
case APP_FOCUS:
return state.set('focused', true).set('unread', 0);
case APP_UNFOCUS:
return state.set('focused', false);
case NOTIFICATIONS_UPDATE:
return state.get('focused') ? state : state.update('unread', x => x + 1);
default:
return state;
}
};

View File

@ -7,7 +7,6 @@ import {
const initialState = Immutable.Map({
new: Immutable.Map({
isSubmitting: false,
account: null,
notifications: true,
}),
@ -17,7 +16,6 @@ export default function mutes(state = initialState, action) {
switch (action.type) {
case MUTES_INIT_MODAL:
return state.withMutations((state) => {
state.setIn(['new', 'isSubmitting'], false);
state.setIn(['new', 'account'], action.account);
state.setIn(['new', 'notifications'], true);
});

View File

@ -6,6 +6,9 @@ import {
NOTIFICATIONS_FILTER_SET,
NOTIFICATIONS_CLEAR,
NOTIFICATIONS_SCROLL_TOP,
NOTIFICATIONS_LOAD_PENDING,
NOTIFICATIONS_MOUNT,
NOTIFICATIONS_UNMOUNT,
} from '../actions/notifications';
import {
ACCOUNT_BLOCK_SUCCESS,
@ -17,9 +20,11 @@ import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import compareId from '../compare_id';
const initialState = ImmutableMap({
pendingItems: ImmutableList(),
items: ImmutableList(),
hasMore: true,
top: false,
mounted: false,
unread: 0,
isLoading: false,
});
@ -32,9 +37,13 @@ const notificationToMap = notification => ImmutableMap({
status: notification.status ? notification.status.id : null,
});
const normalizeNotification = (state, notification) => {
const normalizeNotification = (state, notification, usePendingItems) => {
const top = state.get('top');
if (usePendingItems || !state.get('pendingItems').isEmpty()) {
return state.update('pendingItems', list => list.unshift(notificationToMap(notification))).update('unread', unread => unread + 1);
}
if (!top) {
state = state.update('unread', unread => unread + 1);
}
@ -48,7 +57,7 @@ const normalizeNotification = (state, notification) => {
});
};
const expandNormalizedNotifications = (state, notifications, next) => {
const expandNormalizedNotifications = (state, notifications, next, isLoadingRecent, usePendingItems) => {
let items = ImmutableList();
notifications.forEach((n, i) => {
@ -57,7 +66,9 @@ const expandNormalizedNotifications = (state, notifications, next) => {
return state.withMutations(mutable => {
if (!items.isEmpty()) {
mutable.update('items', list => {
usePendingItems = isLoadingRecent && (usePendingItems || !mutable.get('pendingItems').isEmpty());
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
const lastIndex = 1 + list.findLastIndex(
item => item !== null && (compareId(item.get('id'), items.last().get('id')) > 0 || item.get('id') === items.last().get('id'))
);
@ -79,35 +90,39 @@ const expandNormalizedNotifications = (state, notifications, next) => {
};
const filterNotifications = (state, accountIds) => {
return state.update('items', list => list.filterNot(item => item !== null && accountIds.includes(item.get('account'))));
const helper = list => list.filterNot(item => item !== null && accountIds.includes(item.get('account')));
return state.update('items', helper).update('pendingItems', helper);
};
const updateTop = (state, top) => {
if (top) {
state = state.set('unread', 0);
state = state.set('unread', state.get('pendingItems').size);
}
return state.set('top', top);
};
const deleteByStatus = (state, statusId) => {
return state.update('items', list => list.filterNot(item => item !== null && item.get('status') === statusId));
const helper = list => list.filterNot(item => item !== null && item.get('status') === statusId);
return state.update('items', helper).update('pendingItems', helper);
};
export default function notifications(state = initialState, action) {
switch(action.type) {
case NOTIFICATIONS_LOAD_PENDING:
return state.update('items', list => state.get('pendingItems').concat(list.take(40))).set('pendingItems', ImmutableList()).set('unread', 0);
case NOTIFICATIONS_EXPAND_REQUEST:
return state.set('isLoading', true);
case NOTIFICATIONS_EXPAND_FAIL:
return state.set('isLoading', false);
case NOTIFICATIONS_FILTER_SET:
return state.set('items', ImmutableList()).set('hasMore', true);
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', true);
case NOTIFICATIONS_SCROLL_TOP:
return updateTop(state, action.top);
case NOTIFICATIONS_UPDATE:
return normalizeNotification(state, action.notification);
return normalizeNotification(state, action.notification, action.usePendingItems);
case NOTIFICATIONS_EXPAND_SUCCESS:
return expandNormalizedNotifications(state, action.notifications, action.next);
return expandNormalizedNotifications(state, action.notifications, action.next, action.isLoadingRecent, action.usePendingItems);
case ACCOUNT_BLOCK_SUCCESS:
return filterNotifications(state, [action.relationship.id]);
case ACCOUNT_MUTE_SUCCESS:
@ -115,13 +130,17 @@ export default function notifications(state = initialState, action) {
case DOMAIN_BLOCK_SUCCESS:
return filterNotifications(state, action.accounts);
case NOTIFICATIONS_CLEAR:
return state.set('items', ImmutableList()).set('hasMore', false);
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', false);
case TIMELINE_DELETE:
return deleteByStatus(state, action.id);
case TIMELINE_DISCONNECT:
return action.timeline === 'home' ?
state.update('items', items => items.first() ? items.unshift(null) : items) :
state.update(action.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items) :
state;
case NOTIFICATIONS_MOUNT:
return state.set('mounted', true);
case NOTIFICATIONS_UNMOUNT:
return state.set('mounted', false);
default:
return state;
}

View File

@ -3,6 +3,7 @@ import {
SEARCH_CLEAR,
SEARCH_FETCH_SUCCESS,
SEARCH_SHOW,
SEARCH_EXPAND_SUCCESS,
} from '../actions/search';
import {
COMPOSE_MENTION,
@ -42,6 +43,9 @@ export default function search(state = initialState, action) {
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
hashtags: fromJS(action.results.hashtags),
})).set('submitted', true).set('searchTerm', action.searchTerm);
case SEARCH_EXPAND_SUCCESS:
const results = action.searchType === 'hashtags' ? fromJS(action.results.hashtags) : action.results[action.searchType].map(item => item.id);
return state.updateIn(['results', action.searchType], list => list.concat(results));
default:
return state;
}

View File

@ -10,10 +10,12 @@ import uuid from '../uuid';
const initialState = ImmutableMap({
saved: true,
onboarded: false,
skinTone: 1,
trends: ImmutableMap({
show: true,
}),
home: ImmutableMap({
shows: ImmutableMap({
reblog: true,
@ -74,10 +76,6 @@ const initialState = ImmutableMap({
body: '',
}),
}),
trends: ImmutableMap({
show: true,
}),
});
const defaultColumns = fromJS([

View File

@ -8,6 +8,7 @@ import {
TIMELINE_SCROLL_TOP,
TIMELINE_CONNECT,
TIMELINE_DISCONNECT,
TIMELINE_LOAD_PENDING,
} from '../actions/timelines';
import {
ACCOUNT_BLOCK_SUCCESS,
@ -25,10 +26,11 @@ const initialTimeline = ImmutableMap({
top: true,
isLoading: false,
hasMore: true,
pendingItems: ImmutableList(),
items: ImmutableList(),
});
const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, isLoadingRecent) => {
const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, isLoadingRecent, usePendingItems) => {
return state.update(timeline, initialTimeline, map => map.withMutations(mMap => {
mMap.set('isLoading', false);
mMap.set('isPartial', isPartial);
@ -38,7 +40,9 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
if (timeline.endsWith(':pinned')) {
mMap.set('items', statuses.map(status => status.get('id')));
} else if (!statuses.isEmpty()) {
mMap.update('items', ImmutableList(), oldIds => {
usePendingItems = isLoadingRecent && (usePendingItems || !mMap.get('pendingItems').isEmpty());
mMap.update(usePendingItems ? 'pendingItems' : 'items', ImmutableList(), oldIds => {
const newIds = statuses.map(status => status.get('id'));
const lastIndex = oldIds.findLastIndex(id => id !== null && compareId(id, newIds.last()) >= 0) + 1;
@ -57,8 +61,17 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
}));
};
const updateTimeline = (state, timeline, status) => {
const top = state.getIn([timeline, 'top']);
const updateTimeline = (state, timeline, status, usePendingItems) => {
const top = state.getIn([timeline, 'top']);
if (usePendingItems || !state.getIn([timeline, 'pendingItems']).isEmpty()) {
if (state.getIn([timeline, 'pendingItems'], ImmutableList()).includes(status.get('id')) || state.getIn([timeline, 'items'], ImmutableList()).includes(status.get('id'))) {
return state;
}
return state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id'))).update('unread', unread => unread + 1));
}
const ids = state.getIn([timeline, 'items'], ImmutableList());
const includesId = ids.includes(status.get('id'));
const unread = state.getIn([timeline, 'unread'], 0);
@ -78,8 +91,10 @@ const updateTimeline = (state, timeline, status) => {
const deleteStatus = (state, id, accountId, references, exclude_account = null) => {
state.keySeq().forEach(timeline => {
if (exclude_account === null || (timeline !== `account:${exclude_account}` && !timeline.startsWith(`account:${exclude_account}:`)))
state = state.updateIn([timeline, 'items'], list => list.filterNot(item => item === id));
if (exclude_account === null || (timeline !== `account:${exclude_account}` && !timeline.startsWith(`account:${exclude_account}:`))) {
const helper = list => list.filterNot(item => item === id);
state = state.updateIn([timeline, 'items'], helper).updateIn([timeline, 'pendingItems'], helper);
}
});
// Remove reblogs of deleted status
@ -109,29 +124,31 @@ const filterTimelines = (state, relationship, statuses) => {
return state;
};
const filterTimeline = (timeline, state, relationship, statuses) =>
state.updateIn([timeline, 'items'], ImmutableList(), list =>
list.filterNot(statusId =>
statuses.getIn([statusId, 'account']) === relationship.id
));
const filterTimeline = (timeline, state, relationship, statuses) => {
const helper = list => list.filterNot(statusId => statuses.getIn([statusId, 'account']) === relationship.id);
return state.updateIn([timeline, 'items'], ImmutableList(), helper).updateIn([timeline, 'pendingItems'], ImmutableList(), helper);
};
const updateTop = (state, timeline, top) => {
return state.update(timeline, initialTimeline, map => map.withMutations(mMap => {
if (top) mMap.set('unread', 0);
if (top) mMap.set('unread', mMap.get('pendingItems').size);
mMap.set('top', top);
}));
};
export default function timelines(state = initialState, action) {
switch(action.type) {
case TIMELINE_LOAD_PENDING:
return state.update(action.timeline, initialTimeline, map =>
map.update('items', list => map.get('pendingItems').concat(list.take(40))).set('pendingItems', ImmutableList()).set('unread', 0));
case TIMELINE_EXPAND_REQUEST:
return state.update(action.timeline, initialTimeline, map => map.set('isLoading', true));
case TIMELINE_EXPAND_FAIL:
return state.update(action.timeline, initialTimeline, map => map.set('isLoading', false));
case TIMELINE_EXPAND_SUCCESS:
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent);
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent, action.usePendingItems);
case TIMELINE_UPDATE:
return updateTimeline(state, action.timeline, fromJS(action.status));
return updateTimeline(state, action.timeline, fromJS(action.status), action.usePendingItems);
case TIMELINE_DELETE:
return deleteStatus(state, action.id, action.accountId, action.references, action.reblogOf);
case TIMELINE_CLEAR:
@ -149,7 +166,7 @@ export default function timelines(state = initialState, action) {
return state.update(
action.timeline,
initialTimeline,
map => map.set('online', false).update('items', items => items.first() ? items.unshift(null) : items)
map => map.set('online', false).update(action.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items)
);
default:
return state;

View File

@ -0,0 +1,23 @@
import { TRENDS_FETCH_REQUEST, TRENDS_FETCH_SUCCESS, TRENDS_FETCH_FAIL } from '../actions/trends';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
const initialState = ImmutableMap({
items: ImmutableList(),
isLoading: false,
});
export default function trendsReducer(state = initialState, action) {
switch(action.type) {
case TRENDS_FETCH_REQUEST:
return state.set('isLoading', true);
case TRENDS_FETCH_SUCCESS:
return state.withMutations(map => {
map.set('items', fromJS(action.trends));
map.set('isLoading', false);
});
case TRENDS_FETCH_FAIL:
return state.set('isLoading', false);
default:
return state;
}
};

View File

@ -20,6 +20,14 @@ import {
MUTES_FETCH_SUCCESS,
MUTES_EXPAND_SUCCESS,
} from '../actions/mutes';
import {
DIRECTORY_FETCH_REQUEST,
DIRECTORY_FETCH_SUCCESS,
DIRECTORY_FETCH_FAIL,
DIRECTORY_EXPAND_REQUEST,
DIRECTORY_EXPAND_SUCCESS,
DIRECTORY_EXPAND_FAIL,
} from 'mastodon/actions/directory';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
const initialState = ImmutableMap({
@ -74,6 +82,16 @@ export default function userLists(state = initialState, action) {
return state.setIn(['mutes', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
case MUTES_EXPAND_SUCCESS:
return state.updateIn(['mutes', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
case DIRECTORY_FETCH_SUCCESS:
return state.setIn(['directory', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
case DIRECTORY_EXPAND_SUCCESS:
return state.updateIn(['directory', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
case DIRECTORY_FETCH_REQUEST:
case DIRECTORY_EXPAND_REQUEST:
return state.setIn(['directory', 'isLoading'], true);
case DIRECTORY_FETCH_FAIL:
case DIRECTORY_EXPAND_FAIL:
return state.setIn(['directory', 'isLoading'], false);
default:
return state;
}