forked from treehouse/mastodon
Merge branch 'master' into master
commit
f8da0dd490
|
@ -80,7 +80,7 @@ export function fetchAccount(id) {
|
||||||
|
|
||||||
export function fetchAccountTimeline(id, replace = false) {
|
export function fetchAccountTimeline(id, replace = false) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const ids = getState().getIn(['timelines', 'accounts_timelines', id], Immutable.List());
|
const ids = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List());
|
||||||
const newestId = ids.size > 0 ? ids.first() : null;
|
const newestId = ids.size > 0 ? ids.first() : null;
|
||||||
|
|
||||||
let params = '';
|
let params = '';
|
||||||
|
@ -103,11 +103,16 @@ export function fetchAccountTimeline(id, replace = false) {
|
||||||
|
|
||||||
export function expandAccountTimeline(id) {
|
export function expandAccountTimeline(id) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const lastId = getState().getIn(['timelines', 'accounts_timelines', id], Immutable.List()).last();
|
const lastId = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List()).last();
|
||||||
|
|
||||||
dispatch(expandAccountTimelineRequest(id));
|
dispatch(expandAccountTimelineRequest(id));
|
||||||
|
|
||||||
api(getState).get(`/api/v1/accounts/${id}/statuses?max_id=${lastId}`).then(response => {
|
api(getState).get(`/api/v1/accounts/${id}/statuses`, {
|
||||||
|
params: {
|
||||||
|
limit: 10,
|
||||||
|
max_id: lastId
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
dispatch(expandAccountTimelineSuccess(id, response.data));
|
dispatch(expandAccountTimelineSuccess(id, response.data));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandAccountTimelineFail(id, error));
|
dispatch(expandAccountTimelineFail(id, error));
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function fetchStatusCard(id) {
|
||||||
dispatch(fetchStatusCardRequest(id));
|
dispatch(fetchStatusCardRequest(id));
|
||||||
|
|
||||||
api(getState).get(`/api/v1/statuses/${id}/card`).then(response => {
|
api(getState).get(`/api/v1/statuses/${id}/card`).then(response => {
|
||||||
if (!response.data.url) {
|
if (!response.data.url || !response.data.title || !response.data.description) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,10 @@ export function refreshTimelineRequest(timeline, id, skipLoading) {
|
||||||
|
|
||||||
export function refreshTimeline(timeline, id = null) {
|
export function refreshTimeline(timeline, id = null) {
|
||||||
return function (dispatch, getState) {
|
return function (dispatch, getState) {
|
||||||
|
if (getState().getIn(['timelines', timeline, 'isLoading'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ids = getState().getIn(['timelines', timeline, 'items'], Immutable.List());
|
const ids = getState().getIn(['timelines', timeline, 'items'], Immutable.List());
|
||||||
const newestId = ids.size > 0 ? ids.first() : null;
|
const newestId = ids.size > 0 ? ids.first() : null;
|
||||||
|
|
||||||
|
@ -102,8 +106,9 @@ export function expandTimeline(timeline, id = null) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last();
|
const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last();
|
||||||
|
|
||||||
if (!lastId) {
|
if (!lastId || getState().getIn(['timelines', timeline, 'isLoading'])) {
|
||||||
// If timeline is empty, don't try to load older posts since there are none
|
// If timeline is empty, don't try to load older posts since there are none
|
||||||
|
// Also if already loading
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +120,12 @@ export function expandTimeline(timeline, id = null) {
|
||||||
path = `${path}/${id}`
|
path = `${path}/${id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
api(getState).get(`/api/v1/timelines/${path}?max_id=${lastId}`).then(response => {
|
api(getState).get(`/api/v1/timelines/${path}`, {
|
||||||
|
params: {
|
||||||
|
limit: 10,
|
||||||
|
max_id: lastId
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
dispatch(expandTimelineSuccess(timeline, response.data));
|
dispatch(expandTimelineSuccess(timeline, response.data));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandTimelineFail(timeline, error));
|
dispatch(expandTimelineFail(timeline, error));
|
||||||
|
|
|
@ -37,8 +37,6 @@ const StatusContent = React.createClass({
|
||||||
link.setAttribute('target', '_blank');
|
link.setAttribute('target', '_blank');
|
||||||
link.setAttribute('rel', 'noopener');
|
link.setAttribute('rel', 'noopener');
|
||||||
}
|
}
|
||||||
|
|
||||||
link.addEventListener('click', this.onNormalClick, false);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -70,16 +68,39 @@ const StatusContent = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onNormalClick (e) {
|
handleMouseDown (e) {
|
||||||
e.stopPropagation();
|
this.startXY = [e.clientX, e.clientY];
|
||||||
|
},
|
||||||
|
|
||||||
|
handleMouseUp (e) {
|
||||||
|
const [ startX, startY ] = this.startXY;
|
||||||
|
const [ deltaX, deltaY ] = [Math.abs(e.clientX - startX), Math.abs(e.clientY - startY)];
|
||||||
|
|
||||||
|
if (e.target.localName === 'a' || (e.target.parentNode && e.target.parentNode.localName === 'a')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deltaX + deltaY < 5) {
|
||||||
|
this.props.onClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.startXY = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { status, onClick } = this.props;
|
const { status } = this.props;
|
||||||
|
|
||||||
const content = { __html: emojify(status.get('content')) };
|
const content = { __html: emojify(status.get('content')) };
|
||||||
|
|
||||||
return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={onClick} />;
|
return (
|
||||||
|
<div
|
||||||
|
className='status__content'
|
||||||
|
style={{ cursor: 'pointer' }}
|
||||||
|
dangerouslySetInnerHTML={content}
|
||||||
|
onMouseDown={this.handleMouseDown}
|
||||||
|
onMouseUp={this.handleMouseUp}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,8 @@ const StatusList = React.createClass({
|
||||||
onScrollToBottom: React.PropTypes.func,
|
onScrollToBottom: React.PropTypes.func,
|
||||||
onScrollToTop: React.PropTypes.func,
|
onScrollToTop: React.PropTypes.func,
|
||||||
onScroll: React.PropTypes.func,
|
onScroll: React.PropTypes.func,
|
||||||
trackScroll: React.PropTypes.bool
|
trackScroll: React.PropTypes.bool,
|
||||||
|
isLoading: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps () {
|
getDefaultProps () {
|
||||||
|
@ -24,10 +25,10 @@ const StatusList = React.createClass({
|
||||||
|
|
||||||
handleScroll (e) {
|
handleScroll (e) {
|
||||||
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
||||||
|
const offset = scrollHeight - scrollTop - clientHeight;
|
||||||
this._oldScrollPosition = scrollHeight - scrollTop;
|
this._oldScrollPosition = scrollHeight - scrollTop;
|
||||||
|
|
||||||
if (scrollTop === scrollHeight - clientHeight && this.props.onScrollToBottom) {
|
if (250 > offset && this.props.onScrollToBottom && !this.props.isLoading) {
|
||||||
this.props.onScrollToBottom();
|
this.props.onScrollToBottom();
|
||||||
} else if (scrollTop < 100 && this.props.onScrollToTop) {
|
} else if (scrollTop < 100 && this.props.onScrollToTop) {
|
||||||
this.props.onScrollToTop();
|
this.props.onScrollToTop();
|
||||||
|
@ -36,21 +37,37 @@ const StatusList = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate (prevProps) {
|
componentDidMount () {
|
||||||
if (prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && this._oldScrollPosition) {
|
this.attachScrollListener();
|
||||||
const node = ReactDOM.findDOMNode(this);
|
},
|
||||||
|
|
||||||
if (node.scrollTop > 0) {
|
componentDidUpdate (prevProps) {
|
||||||
node.scrollTop = node.scrollHeight - this._oldScrollPosition;
|
if (this.node.scrollTop > 0 && (prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && !!this._oldScrollPosition)) {
|
||||||
}
|
this.node.scrollTop = this.node.scrollHeight - this._oldScrollPosition;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
this.detachScrollListener();
|
||||||
|
},
|
||||||
|
|
||||||
|
attachScrollListener () {
|
||||||
|
this.node.addEventListener('scroll', this.handleScroll);
|
||||||
|
},
|
||||||
|
|
||||||
|
detachScrollListener () {
|
||||||
|
this.node.removeEventListener('scroll', this.handleScroll);
|
||||||
|
},
|
||||||
|
|
||||||
|
setRef (c) {
|
||||||
|
this.node = c;
|
||||||
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { statusIds, onScrollToBottom, trackScroll } = this.props;
|
const { statusIds, onScrollToBottom, trackScroll } = this.props;
|
||||||
|
|
||||||
const scrollableArea = (
|
const scrollableArea = (
|
||||||
<div className='scrollable' onScroll={this.handleScroll}>
|
<div className='scrollable' ref={this.setRef}>
|
||||||
<div>
|
<div>
|
||||||
{statusIds.map((statusId) => {
|
{statusIds.map((statusId) => {
|
||||||
return <StatusContainer key={statusId} id={statusId} />;
|
return <StatusContainer key={statusId} id={statusId} />;
|
||||||
|
|
|
@ -9,7 +9,8 @@ import StatusList from '../../components/status_list';
|
||||||
import LoadingIndicator from '../../components/loading_indicator';
|
import LoadingIndicator from '../../components/loading_indicator';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId)]),
|
statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'items']),
|
||||||
|
isLoading: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'isLoading']),
|
||||||
me: state.getIn(['meta', 'me'])
|
me: state.getIn(['meta', 'me'])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ const AccountTimeline = React.createClass({
|
||||||
params: React.PropTypes.object.isRequired,
|
params: React.PropTypes.object.isRequired,
|
||||||
dispatch: React.PropTypes.func.isRequired,
|
dispatch: React.PropTypes.func.isRequired,
|
||||||
statusIds: ImmutablePropTypes.list,
|
statusIds: ImmutablePropTypes.list,
|
||||||
|
isLoading: React.PropTypes.bool,
|
||||||
me: React.PropTypes.number.isRequired
|
me: React.PropTypes.number.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -39,13 +41,13 @@ const AccountTimeline = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { statusIds, me } = this.props;
|
const { statusIds, isLoading, me } = this.props;
|
||||||
|
|
||||||
if (!statusIds) {
|
if (!statusIds) {
|
||||||
return <LoadingIndicator />;
|
return <LoadingIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <StatusList statusIds={statusIds} me={me} onScrollToBottom={this.handleScrollToBottom} />
|
return <StatusList statusIds={statusIds} isLoading={isLoading} me={me} onScrollToBottom={this.handleScrollToBottom} />
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -62,6 +62,7 @@ const Notifications = React.createClass({
|
||||||
if (trackScroll) {
|
if (trackScroll) {
|
||||||
return (
|
return (
|
||||||
<Column icon='bell' heading={intl.formatMessage(messages.title)}>
|
<Column icon='bell' heading={intl.formatMessage(messages.title)}>
|
||||||
|
<ColumnSettingsContainer />
|
||||||
<ScrollContainer scrollKey='notifications'>
|
<ScrollContainer scrollKey='notifications'>
|
||||||
{scrollableArea}
|
{scrollableArea}
|
||||||
</ScrollContainer>
|
</ScrollContainer>
|
||||||
|
|
|
@ -33,7 +33,8 @@ const getStatusIds = createSelector([
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
statusIds: getStatusIds(state, props)
|
statusIds: getStatusIds(state, props),
|
||||||
|
isLoading: state.getIn(['timelines', props.type, 'isLoading'], true)
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch, { type, id }) => ({
|
const mapDispatchToProps = (dispatch, { type, id }) => ({
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import {
|
import {
|
||||||
TIMELINE_REFRESH_REQUEST,
|
TIMELINE_REFRESH_REQUEST,
|
||||||
TIMELINE_REFRESH_SUCCESS,
|
TIMELINE_REFRESH_SUCCESS,
|
||||||
|
TIMELINE_REFRESH_FAIL,
|
||||||
TIMELINE_UPDATE,
|
TIMELINE_UPDATE,
|
||||||
TIMELINE_DELETE,
|
TIMELINE_DELETE,
|
||||||
TIMELINE_EXPAND_SUCCESS,
|
TIMELINE_EXPAND_SUCCESS,
|
||||||
|
TIMELINE_EXPAND_REQUEST,
|
||||||
|
TIMELINE_EXPAND_FAIL,
|
||||||
TIMELINE_SCROLL_TOP
|
TIMELINE_SCROLL_TOP
|
||||||
} from '../actions/timelines';
|
} from '../actions/timelines';
|
||||||
import {
|
import {
|
||||||
|
@ -13,37 +16,43 @@ import {
|
||||||
UNFAVOURITE_SUCCESS
|
UNFAVOURITE_SUCCESS
|
||||||
} from '../actions/interactions';
|
} from '../actions/interactions';
|
||||||
import {
|
import {
|
||||||
ACCOUNT_FETCH_SUCCESS,
|
ACCOUNT_TIMELINE_FETCH_REQUEST,
|
||||||
ACCOUNT_TIMELINE_FETCH_SUCCESS,
|
ACCOUNT_TIMELINE_FETCH_SUCCESS,
|
||||||
|
ACCOUNT_TIMELINE_FETCH_FAIL,
|
||||||
|
ACCOUNT_TIMELINE_EXPAND_REQUEST,
|
||||||
ACCOUNT_TIMELINE_EXPAND_SUCCESS,
|
ACCOUNT_TIMELINE_EXPAND_SUCCESS,
|
||||||
|
ACCOUNT_TIMELINE_EXPAND_FAIL,
|
||||||
ACCOUNT_BLOCK_SUCCESS
|
ACCOUNT_BLOCK_SUCCESS
|
||||||
} from '../actions/accounts';
|
} from '../actions/accounts';
|
||||||
import {
|
import {
|
||||||
STATUS_FETCH_SUCCESS,
|
|
||||||
CONTEXT_FETCH_SUCCESS
|
CONTEXT_FETCH_SUCCESS
|
||||||
} from '../actions/statuses';
|
} from '../actions/statuses';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
const initialState = Immutable.Map({
|
const initialState = Immutable.Map({
|
||||||
home: Immutable.Map({
|
home: Immutable.Map({
|
||||||
|
isLoading: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
top: true,
|
top: true,
|
||||||
items: Immutable.List()
|
items: Immutable.List()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
mentions: Immutable.Map({
|
mentions: Immutable.Map({
|
||||||
|
isLoading: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
top: true,
|
top: true,
|
||||||
items: Immutable.List()
|
items: Immutable.List()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
public: Immutable.Map({
|
public: Immutable.Map({
|
||||||
|
isLoading: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
top: true,
|
top: true,
|
||||||
items: Immutable.List()
|
items: Immutable.List()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
tag: Immutable.Map({
|
tag: Immutable.Map({
|
||||||
|
isLoading: false,
|
||||||
id: null,
|
id: null,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
top: true,
|
top: true,
|
||||||
|
@ -82,6 +91,7 @@ const normalizeTimeline = (state, timeline, statuses, replace = false) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
state = state.setIn([timeline, 'loaded'], true);
|
state = state.setIn([timeline, 'loaded'], true);
|
||||||
|
state = state.setIn([timeline, 'isLoading'], false);
|
||||||
|
|
||||||
return state.updateIn([timeline, 'items'], Immutable.List(), list => (loaded ? list.unshift(...ids) : ids));
|
return state.updateIn([timeline, 'items'], Immutable.List(), list => (loaded ? list.unshift(...ids) : ids));
|
||||||
};
|
};
|
||||||
|
@ -94,6 +104,8 @@ const appendNormalizedTimeline = (state, timeline, statuses) => {
|
||||||
moreIds = moreIds.set(i, status.get('id'));
|
moreIds = moreIds.set(i, status.get('id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
state = state.setIn([timeline, 'isLoading'], false);
|
||||||
|
|
||||||
return state.updateIn([timeline, 'items'], Immutable.List(), list => list.push(...moreIds));
|
return state.updateIn([timeline, 'items'], Immutable.List(), list => list.push(...moreIds));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,7 +117,10 @@ const normalizeAccountTimeline = (state, accountId, statuses, replace = false) =
|
||||||
ids = ids.set(i, status.get('id'));
|
ids = ids.set(i, status.get('id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
return state.updateIn(['accounts_timelines', accountId], Immutable.List([]), list => (replace ? ids : list.unshift(...ids)));
|
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
||||||
|
.set('isLoading', false)
|
||||||
|
.set('loaded', true)
|
||||||
|
.update('items', Immutable.List(), list => (replace ? ids : list.unshift(...ids))));
|
||||||
};
|
};
|
||||||
|
|
||||||
const appendNormalizedAccountTimeline = (state, accountId, statuses) => {
|
const appendNormalizedAccountTimeline = (state, accountId, statuses) => {
|
||||||
|
@ -116,7 +131,9 @@ const appendNormalizedAccountTimeline = (state, accountId, statuses) => {
|
||||||
moreIds = moreIds.set(i, status.get('id'));
|
moreIds = moreIds.set(i, status.get('id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
return state.updateIn(['accounts_timelines', accountId], Immutable.List([]), list => list.push(...moreIds));
|
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
||||||
|
.set('isLoading', false)
|
||||||
|
.update('items', list => list.push(...moreIds)));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateTimeline = (state, timeline, status, references) => {
|
const updateTimeline = (state, timeline, status, references) => {
|
||||||
|
@ -157,7 +174,7 @@ const deleteStatus = (state, id, accountId, references, reblogOf) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove references from account timelines
|
// Remove references from account timelines
|
||||||
state = state.updateIn(['accounts_timelines', accountId], Immutable.List([]), list => list.filterNot(item => item === id));
|
state = state.updateIn(['accounts_timelines', accountId, 'items'], Immutable.List([]), list => list.filterNot(item => item === id));
|
||||||
|
|
||||||
// Remove references from context
|
// Remove references from context
|
||||||
state.getIn(['descendants', id], Immutable.List()).forEach(descendantId => {
|
state.getIn(['descendants', id], Immutable.List()).forEach(descendantId => {
|
||||||
|
@ -207,8 +224,11 @@ const resetTimeline = (state, timeline, id) => {
|
||||||
if (timeline === 'tag' && state.getIn([timeline, 'id']) !== id) {
|
if (timeline === 'tag' && state.getIn([timeline, 'id']) !== id) {
|
||||||
state = state.update(timeline, map => map
|
state = state.update(timeline, map => map
|
||||||
.set('id', id)
|
.set('id', id)
|
||||||
|
.set('isLoading', true)
|
||||||
.set('loaded', false)
|
.set('loaded', false)
|
||||||
.update('items', list => list.clear()));
|
.update('items', list => list.clear()));
|
||||||
|
} else {
|
||||||
|
state = state.setIn([timeline, 'isLoading'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -216,27 +236,37 @@ const resetTimeline = (state, timeline, id) => {
|
||||||
|
|
||||||
export default function timelines(state = initialState, action) {
|
export default function timelines(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case TIMELINE_REFRESH_REQUEST:
|
case TIMELINE_REFRESH_REQUEST:
|
||||||
return resetTimeline(state, action.timeline, action.id);
|
case TIMELINE_EXPAND_REQUEST:
|
||||||
case TIMELINE_REFRESH_SUCCESS:
|
return resetTimeline(state, action.timeline, action.id);
|
||||||
return normalizeTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
|
case TIMELINE_REFRESH_FAIL:
|
||||||
case TIMELINE_EXPAND_SUCCESS:
|
case TIMELINE_EXPAND_FAIL:
|
||||||
return appendNormalizedTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
|
return state.setIn([action.timeline, 'isLoading'], false);
|
||||||
case TIMELINE_UPDATE:
|
case TIMELINE_REFRESH_SUCCESS:
|
||||||
return updateTimeline(state, action.timeline, Immutable.fromJS(action.status), action.references);
|
return normalizeTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_EXPAND_SUCCESS:
|
||||||
return deleteStatus(state, action.id, action.accountId, action.references, action.reblogOf);
|
return appendNormalizedTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
|
||||||
case CONTEXT_FETCH_SUCCESS:
|
case TIMELINE_UPDATE:
|
||||||
return normalizeContext(state, action.id, Immutable.fromJS(action.ancestors), Immutable.fromJS(action.descendants));
|
return updateTimeline(state, action.timeline, Immutable.fromJS(action.status), action.references);
|
||||||
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
case TIMELINE_DELETE:
|
||||||
return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace);
|
return deleteStatus(state, action.id, action.accountId, action.references, action.reblogOf);
|
||||||
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
|
case CONTEXT_FETCH_SUCCESS:
|
||||||
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
|
return normalizeContext(state, action.id, Immutable.fromJS(action.ancestors), Immutable.fromJS(action.descendants));
|
||||||
case ACCOUNT_BLOCK_SUCCESS:
|
case ACCOUNT_TIMELINE_FETCH_REQUEST:
|
||||||
return filterTimelines(state, action.relationship, action.statuses);
|
case ACCOUNT_TIMELINE_EXPAND_REQUEST:
|
||||||
case TIMELINE_SCROLL_TOP:
|
return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', true));
|
||||||
return state.setIn([action.timeline, 'top'], action.top);
|
case ACCOUNT_TIMELINE_FETCH_FAIL:
|
||||||
default:
|
case ACCOUNT_TIMELINE_EXPAND_FAIL:
|
||||||
return state;
|
return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', false));
|
||||||
|
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
||||||
|
return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace);
|
||||||
|
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
|
||||||
|
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
|
||||||
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
|
return filterTimelines(state, action.relationship, action.statuses);
|
||||||
|
case TIMELINE_SCROLL_TOP:
|
||||||
|
return state.setIn([action.timeline, 'top'], action.top);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -60,6 +60,19 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.invisible {
|
||||||
|
font-size: 0;
|
||||||
|
line-height: 0;
|
||||||
|
display: inline-block;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ellipsis {
|
||||||
|
&:after {
|
||||||
|
content: "…";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.lightbox .icon-button {
|
.lightbox .icon-button {
|
||||||
color: $color1;
|
color: $color1;
|
||||||
}
|
}
|
||||||
|
@ -699,12 +712,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@import 'boost';
|
||||||
|
|
||||||
|
|
||||||
button i.fa-retweet {
|
button i.fa-retweet {
|
||||||
height: 19px;
|
height: 19px;
|
||||||
width: 22px;
|
width: 22px;
|
||||||
background: image-url('boost_sprite.png') no-repeat;
|
|
||||||
background-position: 0 0;
|
background-position: 0 0;
|
||||||
transition: background-position 0.9s steps(11);
|
transition: background-position 0.9s steps(10);
|
||||||
transition-duration: 0s;
|
transition-duration: 0s;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
|
@ -714,7 +729,7 @@ button i.fa-retweet {
|
||||||
|
|
||||||
button.active i.fa-retweet {
|
button.active i.fa-retweet {
|
||||||
transition-duration: 0.9s;
|
transition-duration: 0.9s;
|
||||||
background-position: 0 -209px;
|
background-position: 0 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-card {
|
.status-card {
|
||||||
|
|
|
@ -16,13 +16,13 @@ class Api::V1::AccountsController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def following
|
def following
|
||||||
results = Follow.where(account: @account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
results = Follow.where(account: @account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
|
||||||
accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
|
accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
|
||||||
@accounts = results.map { |f| accounts[f.target_account_id] }
|
@accounts = results.map { |f| accounts[f.target_account_id] }
|
||||||
|
|
||||||
set_account_counters_maps(@accounts)
|
set_account_counters_maps(@accounts)
|
||||||
|
|
||||||
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -31,13 +31,13 @@ class Api::V1::AccountsController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers
|
def followers
|
||||||
results = Follow.where(target_account: @account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
results = Follow.where(target_account: @account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
|
||||||
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
||||||
@accounts = results.map { |f| accounts[f.account_id] }
|
@accounts = results.map { |f| accounts[f.account_id] }
|
||||||
|
|
||||||
set_account_counters_maps(@accounts)
|
set_account_counters_maps(@accounts)
|
||||||
|
|
||||||
next_path = followers_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = followers_api_v1_account_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -46,13 +46,13 @@ class Api::V1::AccountsController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def statuses
|
def statuses
|
||||||
@statuses = @account.statuses.permitted_for(@account, current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
@statuses = @account.statuses.permitted_for(@account, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(@statuses, Status)
|
@statuses = cache_collection(@statuses, Status)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
|
|
||||||
next_path = statuses_api_v1_account_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
|
next_path = statuses_api_v1_account_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
|
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -65,7 +65,7 @@ class Api::V1::AccountsController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def block
|
def block
|
||||||
BlockWorker.perform_async(current_user.account_id, @account.id)
|
BlockService.new.call(current_user.account, @account)
|
||||||
|
|
||||||
@following = { @account.id => false }
|
@following = { @account.id => false }
|
||||||
@followed_by = { @account.id => false }
|
@followed_by = { @account.id => false }
|
||||||
|
@ -98,8 +98,7 @@ class Api::V1::AccountsController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
limit = params[:limit] ? [DEFAULT_ACCOUNTS_LIMIT, params[:limit].to_i].min : DEFAULT_ACCOUNTS_LIMIT
|
@accounts = SearchService.new.call(params[:q], limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:resolve] == 'true')
|
||||||
@accounts = SearchService.new.call(params[:q], limit, params[:resolve] == 'true')
|
|
||||||
|
|
||||||
set_account_counters_maps(@accounts) unless @accounts.nil?
|
set_account_counters_maps(@accounts) unless @accounts.nil?
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ class Api::V1::BlocksController < ApiController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
results = Block.where(account: current_account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
results = Block.where(account: current_account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
|
||||||
accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
|
accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
|
||||||
@accounts = results.map { |f| accounts[f.target_account_id] }
|
@accounts = results.map { |f| accounts[f.target_account_id] }
|
||||||
|
|
||||||
set_account_counters_maps(@accounts)
|
set_account_counters_maps(@accounts)
|
||||||
|
|
||||||
next_path = api_v1_blocks_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = api_v1_blocks_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
prev_path = api_v1_blocks_url(since_id: results.first.id) unless results.empty?
|
prev_path = api_v1_blocks_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
|
@ -7,13 +7,13 @@ class Api::V1::FavouritesController < ApiController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
results = Favourite.where(account: current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
results = Favourite.where(account: current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(Status.where(id: results.map(&:status_id)), Status)
|
@statuses = cache_collection(Status.where(id: results.map(&:status_id)), Status)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
|
|
||||||
next_path = api_v1_favourites_url(max_id: results.last.id) if results.size == DEFAULT_STATUSES_LIMIT
|
next_path = api_v1_favourites_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = api_v1_favourites_url(since_id: results.first.id) unless results.empty?
|
prev_path = api_v1_favourites_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Api::V1::NotificationsController < ApiController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@notifications = Notification.where(account: current_account).browserable.paginate_by_max_id(20, params[:max_id], params[:since_id])
|
@notifications = Notification.where(account: current_account).browserable.paginate_by_max_id(limit_param(15), params[:max_id], params[:since_id])
|
||||||
@notifications = cache_collection(@notifications, Notification)
|
@notifications = cache_collection(@notifications, Notification)
|
||||||
statuses = @notifications.select { |n| !n.target_status.nil? }.map(&:target_status)
|
statuses = @notifications.select { |n| !n.target_status.nil? }.map(&:target_status)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Api::V1::NotificationsController < ApiController
|
||||||
set_counters_maps(statuses)
|
set_counters_maps(statuses)
|
||||||
set_account_counters_maps(@notifications.map(&:from_account))
|
set_account_counters_maps(@notifications.map(&:from_account))
|
||||||
|
|
||||||
next_path = api_v1_notifications_url(max_id: @notifications.last.id) if @notifications.size == 20
|
next_path = api_v1_notifications_url(max_id: @notifications.last.id) if @notifications.size == limit_param(15)
|
||||||
prev_path = api_v1_notifications_url(since_id: @notifications.first.id) unless @notifications.empty?
|
prev_path = api_v1_notifications_url(since_id: @notifications.first.id) unless @notifications.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
|
@ -27,13 +27,13 @@ class Api::V1::StatusesController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def reblogged_by
|
def reblogged_by
|
||||||
results = @status.reblogs.paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
results = @status.reblogs.paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
|
||||||
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
||||||
@accounts = results.map { |r| accounts[r.account_id] }
|
@accounts = results.map { |r| accounts[r.account_id] }
|
||||||
|
|
||||||
set_account_counters_maps(@accounts)
|
set_account_counters_maps(@accounts)
|
||||||
|
|
||||||
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -42,13 +42,13 @@ class Api::V1::StatusesController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def favourited_by
|
def favourited_by
|
||||||
results = @status.favourites.paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
results = @status.favourites.paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
|
||||||
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
||||||
@accounts = results.map { |f| accounts[f.account_id] }
|
@accounts = results.map { |f| accounts[f.account_id] }
|
||||||
|
|
||||||
set_account_counters_maps(@accounts)
|
set_account_counters_maps(@accounts)
|
||||||
|
|
||||||
next_path = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
|
@ -7,14 +7,14 @@ class Api::V1::TimelinesController < ApiController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def home
|
def home
|
||||||
@statuses = Feed.new(:home, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
@statuses = Feed.new(:home, current_account).get(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(@statuses)
|
@statuses = cache_collection(@statuses)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||||
|
|
||||||
next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
|
next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -23,14 +23,14 @@ class Api::V1::TimelinesController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentions
|
def mentions
|
||||||
@statuses = Feed.new(:mentions, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
@statuses = Feed.new(:mentions, current_account).get(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(@statuses)
|
@statuses = cache_collection(@statuses)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||||
|
|
||||||
next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
|
next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -39,14 +39,14 @@ class Api::V1::TimelinesController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def public
|
def public
|
||||||
@statuses = Status.as_public_timeline(current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
@statuses = Status.as_public_timeline(current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(@statuses)
|
@statuses = cache_collection(@statuses)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||||
|
|
||||||
next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
|
next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
@ -56,14 +56,14 @@ class Api::V1::TimelinesController < ApiController
|
||||||
|
|
||||||
def tag
|
def tag
|
||||||
@tag = Tag.find_by(name: params[:id].downcase)
|
@tag = Tag.find_by(name: params[:id].downcase)
|
||||||
@statuses = @tag.nil? ? [] : Status.as_tag_timeline(@tag, current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id])
|
@statuses = @tag.nil? ? [] : Status.as_tag_timeline(@tag, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
|
||||||
@statuses = cache_collection(@statuses)
|
@statuses = cache_collection(@statuses)
|
||||||
|
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||||
|
|
||||||
next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
|
next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
|
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
|
@ -62,6 +62,11 @@ class ApiController < ApplicationController
|
||||||
response.headers['Link'] = LinkHeader.new(links)
|
response.headers['Link'] = LinkHeader.new(links)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def limit_param(default_limit)
|
||||||
|
return default_limit unless params[:limit]
|
||||||
|
[params[:limit].to_i.abs, default_limit * 2].min
|
||||||
|
end
|
||||||
|
|
||||||
def current_resource_owner
|
def current_resource_owner
|
||||||
@current_user ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
@current_user ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,8 +80,11 @@ class Formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_html(url)
|
def link_html(url)
|
||||||
link_text = truncate(url.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30)
|
prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
|
||||||
"<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\">#{link_text}</a>"
|
text = url[prefix.length, 30]
|
||||||
|
suffix = url[prefix.length + 30..-1]
|
||||||
|
|
||||||
|
"<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\"><span class=\"invisible\">#{prefix}</span><span class=\"ellipsis\">#{text}</span><span class=\"invisible\">#{suffix}</span></a>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def hashtag_html(match)
|
def hashtag_html(match)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AfterBlockService < BaseService
|
||||||
|
def call(account, target_account)
|
||||||
|
clear_timelines(account, target_account)
|
||||||
|
clear_notifications(account, target_account)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def clear_timelines(account, target_account)
|
||||||
|
mentions_key = FeedManager.instance.key(:mentions, account.id)
|
||||||
|
home_key = FeedManager.instance.key(:home, account.id)
|
||||||
|
|
||||||
|
target_account.statuses.select('id').find_each do |status|
|
||||||
|
redis.zrem(mentions_key, status.id)
|
||||||
|
redis.zrem(home_key, status.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_notifications(account, target_account)
|
||||||
|
Notification.where(account: account).joins(:follow).where(activity_type: 'Follow', follows: { account_id: target_account.id }).destroy_all
|
||||||
|
Notification.where(account: account).joins(mention: :status).where(activity_type: 'Mention', statuses: { account_id: target_account.id }).destroy_all
|
||||||
|
Notification.where(account: account).joins(:favourite).where(activity_type: 'Favourite', favourites: { account_id: target_account.id }).destroy_all
|
||||||
|
Notification.where(account: account).joins(:status).where(activity_type: 'Status', statuses: { account_id: target_account.id }).destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
def redis
|
||||||
|
Redis.current
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,32 +9,7 @@ class BlockService < BaseService
|
||||||
|
|
||||||
block = account.block!(target_account)
|
block = account.block!(target_account)
|
||||||
|
|
||||||
clear_timelines(account, target_account)
|
BlockWorker.perform_async(account.id, target_account.id)
|
||||||
clear_notifications(account, target_account)
|
|
||||||
|
|
||||||
NotificationWorker.perform_async(block.stream_entry.id, target_account.id) unless target_account.local?
|
NotificationWorker.perform_async(block.stream_entry.id, target_account.id) unless target_account.local?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def clear_timelines(account, target_account)
|
|
||||||
mentions_key = FeedManager.instance.key(:mentions, account.id)
|
|
||||||
home_key = FeedManager.instance.key(:home, account.id)
|
|
||||||
|
|
||||||
target_account.statuses.select('id').find_each do |status|
|
|
||||||
redis.zrem(mentions_key, status.id)
|
|
||||||
redis.zrem(home_key, status.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_notifications(account, target_account)
|
|
||||||
Notification.where(account: account).joins(:follow).where(activity_type: 'Follow', follows: { account_id: target_account.id }).destroy_all
|
|
||||||
Notification.where(account: account).joins(mention: :status).where(activity_type: 'Mention', statuses: { account_id: target_account.id }).destroy_all
|
|
||||||
Notification.where(account: account).joins(:favourite).where(activity_type: 'Favourite', favourites: { account_id: target_account.id }).destroy_all
|
|
||||||
Notification.where(account: account).joins(:status).where(activity_type: 'Status', statuses: { account_id: target_account.id }).destroy_all
|
|
||||||
end
|
|
||||||
|
|
||||||
def redis
|
|
||||||
Redis.current
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,6 @@ class BlockWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
|
|
||||||
def perform(account_id, target_account_id)
|
def perform(account_id, target_account_id)
|
||||||
BlockService.new.call(Account.find(account_id), Account.find(target_account_id))
|
AfterBlockService.new.call(Account.find(account_id), Account.find(target_account_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ RSpec.describe Formatter do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'contains a link' do
|
it 'contains a link' do
|
||||||
expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com">google.com</a>')
|
expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com"><span class="invisible">http://</span><span class="ellipsis">google.com</span><span class="invisible"></span></a>')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue