Fix #55 - Filter self from pre-filled mentions

This commit is contained in:
Eugen Rochko 2016-09-26 15:49:28 +02:00
parent 693383234c
commit 0bd4608ad1

View file

@ -10,9 +10,10 @@ import {
COMPOSE_UPLOAD_FAIL, COMPOSE_UPLOAD_FAIL,
COMPOSE_UPLOAD_UNDO, COMPOSE_UPLOAD_UNDO,
COMPOSE_UPLOAD_PROGRESS COMPOSE_UPLOAD_PROGRESS
} from '../actions/compose'; } from '../actions/compose';
import { TIMELINE_DELETE } from '../actions/timelines'; import { TIMELINE_DELETE } from '../actions/timelines';
import Immutable from 'immutable'; import { ACCOUNT_SET_SELF } from '../actions/accounts';
import Immutable from 'immutable';
const initialState = Immutable.Map({ const initialState = Immutable.Map({
text: '', text: '',
@ -20,11 +21,19 @@ const initialState = Immutable.Map({
is_submitting: false, is_submitting: false,
is_uploading: false, is_uploading: false,
progress: 0, progress: 0,
media_attachments: Immutable.List([]) media_attachments: Immutable.List([]),
me: null
}); });
function statusToTextMentions(status) { function statusToTextMentions(state, status) {
return Immutable.OrderedSet([`@${status.getIn(['account', 'acct'])} `]).union(status.get('mentions').map(mention => `@${mention.get('acct')} `)).join(''); let set = Immutable.OrderedSet([]);
let me = state.get('me');
if (status.getIn(['account', 'id']) !== me) {
set = set.add(`@${status.getIn(['account', 'acct'])} `);
}
return set.union(status.get('mentions').filterNot(mention => mention.get('id') === me).map(mention => `@${mention.get('acct')} `)).join('');
}; };
function clearAll(state) { function clearAll(state) {
@ -60,7 +69,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_REPLY: case COMPOSE_REPLY:
return state.withMutations(map => { return state.withMutations(map => {
map.set('in_reply_to', action.status.get('id')); map.set('in_reply_to', action.status.get('id'));
map.set('text', statusToTextMentions(action.status)); map.set('text', statusToTextMentions(state, action.status));
}); });
case COMPOSE_REPLY_CANCEL: case COMPOSE_REPLY_CANCEL:
return state.withMutations(map => { return state.withMutations(map => {
@ -89,6 +98,8 @@ export default function compose(state = initialState, action) {
} else { } else {
return state; return state;
} }
case ACCOUNT_SET_SELF:
return state.set('me', action.account.id);
default: default:
return state; return state;
} }