Skip to content

Commit

Permalink
Update immutable imports for v5 (mastodon#33037)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni authored Nov 22, 2024
1 parent 21a8612 commit 27e79da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/javascript/mastodon/features/status/components/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FormattedMessage } from 'react-intl';
import classNames from 'classnames';


import Immutable from 'immutable';
import { is } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';

import DescriptionIcon from '@/material-icons/400-24px/description-fill.svg?react';
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class Card extends PureComponent {
};

UNSAFE_componentWillReceiveProps (nextProps) {
if (!Immutable.is(this.props.card, nextProps.card)) {
if (!is(this.props.card, nextProps.card)) {
this.setState({ embedded: false, previewLoaded: false });
}

Expand Down
10 changes: 5 additions & 5 deletions app/javascript/mastodon/features/status/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Helmet } from 'react-helmet';
import { withRouter } from 'react-router-dom';

import { createSelector } from '@reduxjs/toolkit';
import Immutable from 'immutable';
import { List as ImmutableList } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -87,7 +87,7 @@ const makeMapStateToProps = () => {
(_, { id }) => id,
state => state.getIn(['contexts', 'inReplyTos']),
], (statusId, inReplyTos) => {
let ancestorsIds = Immutable.List();
let ancestorsIds = ImmutableList();
ancestorsIds = ancestorsIds.withMutations(mutable => {
let id = statusId;

Expand Down Expand Up @@ -134,14 +134,14 @@ const makeMapStateToProps = () => {
});
}

return Immutable.List(descendantsIds);
return ImmutableList(descendantsIds);
});

const mapStateToProps = (state, props) => {
const status = getStatus(state, { id: props.params.statusId });

let ancestorsIds = Immutable.List();
let descendantsIds = Immutable.List();
let ancestorsIds = ImmutableList();
let descendantsIds = ImmutableList();

if (status) {
ancestorsIds = getAncestorsIds(state, { id: status.get('in_reply_to_id') });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getAccountLanguages = createSelector([
(state, accountId) => state.getIn(['timelines', `account:${accountId}`, 'items'], ImmutableList()),
state => state.get('statuses'),
], (statusIds, statuses) =>
new ImmutableSet(statusIds.map(statusId => statuses.get(statusId)).filter(status => !status.get('reblog')).map(status => status.get('language'))));
ImmutableSet(statusIds.map(statusId => statuses.get(statusId)).filter(status => !status.get('reblog')).map(status => status.get('language'))));

const mapStateToProps = (state, { accountId }) => ({
acct: state.getIn(['accounts', accountId, 'acct']),
Expand Down
24 changes: 14 additions & 10 deletions app/javascript/mastodon/models/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RecordOf } from 'immutable';
import { List, Record as ImmutableRecord } from 'immutable';
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';

import escapeTextContentForBrowser from 'escape-html';

Expand Down Expand Up @@ -48,9 +48,9 @@ export interface AccountShape
extends Required<
Omit<ApiAccountJSON, 'emojis' | 'fields' | 'roles' | 'moved'>
> {
emojis: List<CustomEmoji>;
fields: List<AccountField>;
roles: List<AccountRole>;
emojis: ImmutableList<CustomEmoji>;
fields: ImmutableList<AccountField>;
roles: ImmutableList<AccountRole>;
display_name_html: string;
note_emojified: string;
note_plain: string | null;
Expand All @@ -70,8 +70,8 @@ export const accountDefaultValues: AccountShape = {
indexable: false,
display_name: '',
display_name_html: '',
emojis: List<CustomEmoji>(),
fields: List<AccountField>(),
emojis: ImmutableList<CustomEmoji>(),
fields: ImmutableList<AccountField>(),
group: false,
header: '',
header_static: '',
Expand All @@ -82,7 +82,7 @@ export const accountDefaultValues: AccountShape = {
note: '',
note_emojified: '',
note_plain: 'string',
roles: List<AccountRole>(),
roles: ImmutableList<AccountRole>(),
uri: '',
url: '',
username: '',
Expand Down Expand Up @@ -139,11 +139,15 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) {
return AccountFactory({
...accountJSON,
moved: moved?.id,
fields: List(
fields: ImmutableList(
serverJSON.fields.map((field) => createAccountField(field, emojiMap)),
),
emojis: List(serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji))),
roles: List(serverJSON.roles?.map((role) => AccountRoleFactory(role))),
emojis: ImmutableList(
serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji)),
),
roles: ImmutableList(
serverJSON.roles?.map((role) => AccountRoleFactory(role)),
),
display_name_html: emojify(
escapeTextContentForBrowser(displayName),
emojiMap,
Expand Down
12 changes: 6 additions & 6 deletions app/javascript/mastodon/reducers/push_notifications.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Immutable from 'immutable';
import { Map as ImmutableMap } from 'immutable';

import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from '../actions/push_notifications';
import { STORE_HYDRATE } from '../actions/store';

const initialState = Immutable.Map({
const initialState = ImmutableMap({
subscription: null,
alerts: new Immutable.Map({
alerts: ImmutableMap({
follow: false,
follow_request: false,
favourite: false,
Expand All @@ -24,7 +24,7 @@ export default function push_subscriptions(state = initialState, action) {

if (push_subscription) {
return state
.set('subscription', new Immutable.Map({
.set('subscription', ImmutableMap({
id: push_subscription.get('id'),
endpoint: push_subscription.get('endpoint'),
}))
Expand All @@ -36,11 +36,11 @@ export default function push_subscriptions(state = initialState, action) {
}
case SET_SUBSCRIPTION:
return state
.set('subscription', new Immutable.Map({
.set('subscription', ImmutableMap({
id: action.subscription.id,
endpoint: action.subscription.endpoint,
}))
.set('alerts', new Immutable.Map(action.subscription.alerts))
.set('alerts', ImmutableMap(action.subscription.alerts))
.set('isSubscribed', true);
case SET_BROWSER_SUPPORT:
return state.set('browserSupport', action.value);
Expand Down

0 comments on commit 27e79da

Please sign in to comment.