Skip to content

Commit

Permalink
Add circle post to history in web ui when post
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 24, 2023
1 parent c3d665f commit 18b4b43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/javascript/mastodon/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const COMPOSE_DIRECT = 'COMPOSE_DIRECT';
export const COMPOSE_MENTION = 'COMPOSE_MENTION';
export const COMPOSE_RESET = 'COMPOSE_RESET';

export const COMPOSE_WITH_CIRCLE_SUCCESS = 'COMPOSE_WITH_CIRCLE_SUCCESS';

export const COMPOSE_UPLOAD_REQUEST = 'COMPOSE_UPLOAD_REQUEST';
export const COMPOSE_UPLOAD_SUCCESS = 'COMPOSE_UPLOAD_SUCCESS';
export const COMPOSE_UPLOAD_FAIL = 'COMPOSE_UPLOAD_FAIL';
Expand Down Expand Up @@ -174,6 +176,7 @@ export function submitCompose(routerHistory) {
const status = getState().getIn(['compose', 'text'], '');
const media = getState().getIn(['compose', 'media_attachments']);
const statusId = getState().getIn(['compose', 'id'], null);
const circleId = getState().getIn(['compose', 'circle_id'], null);

if ((!status || !status.length) && media.size === 0) {
return;
Expand Down Expand Up @@ -253,6 +256,10 @@ export function submitCompose(routerHistory) {
insertIfOnline(`account:${response.data.account.id}`);
}

if (statusId === null && circleId !== null && circleId !== 0) {
dispatch(submitComposeWithCircleSuccess({ ...response.data }, circleId));
}

dispatch(showAlert({
message: statusId === null ? messages.published : messages.saved,
action: messages.open,
Expand All @@ -278,6 +285,14 @@ export function submitComposeSuccess(status) {
};
}

export function submitComposeWithCircleSuccess(status, circleId) {
return {
type: COMPOSE_WITH_CIRCLE_SUCCESS,
status,
circleId,
}
}

export function submitComposeFail(error) {
return {
type: COMPOSE_SUBMIT_FAIL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
BookmarkCategoryStatuses,
AntennaSetting,
AntennaTimeline,
CircleStatuses,
} from '../util/async-components';

import BundleColumnError from './bundle_column_error';
Expand All @@ -45,6 +46,7 @@ const componentMap = {
'EMOJI_REACTIONS': EmojiReactedStatuses,
'BOOKMARKS': BookmarkedStatuses,
'BOOKMARKS_EX': BookmarkCategoryStatuses,
'CIRCLE_STATUSES': CircleStatuses,
'ANTENNA': AntennaSetting,
'ANTENNA_TIMELINE': AntennaTimeline,
'LIST': ListTimeline,
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/mastodon/reducers/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
CIRCLE_STATUSES_EXPAND_SUCCESS,
CIRCLE_STATUSES_EXPAND_FAIL,
} from '../actions/circles';
import {
COMPOSE_WITH_CIRCLE_SUCCESS,
} from '../actions/compose';

const initialState = ImmutableList();

Expand Down Expand Up @@ -71,6 +74,16 @@ const appendToCircleStatusesById = (state, circleId, statuses, next) => {
}));
};

const prependToCircleStatusById = (state, circleId, statusId) => {
if (!state.get(circleId)) return state;

return state.updateIn([circleId], circle => circle.withMutations(map => {
if (map.getIn(['statuses', 'items'])) {
map.updateIn(['statuses', 'items'], list => ImmutableOrderedSet([statusId]).union(list));
}
}));
}

export default function circles(state = initialState, action) {
switch(action.type) {
case CIRCLE_FETCH_SUCCESS:
Expand All @@ -92,6 +105,8 @@ export default function circles(state = initialState, action) {
return normalizeCircleStatuses(state, action.id, action.statuses, action.next);
case CIRCLE_STATUSES_EXPAND_SUCCESS:
return appendToCircleStatuses(state, action.id, action.statuses, action.next);
case COMPOSE_WITH_CIRCLE_SUCCESS:
return prependToCircleStatusById(state, action.circleId, action.status.id);
default:
return state;
}
Expand Down

0 comments on commit 18b4b43

Please sign in to comment.