Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -34,7 +34,7 @@ import { ActionPayload } from "../dispatcher/payloads";
|
|||
*/
|
||||
function createSyncAction(matrixClient: MatrixClient, state: string, prevState: string): ActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.sync',
|
||||
action: "MatrixActions.sync",
|
||||
state,
|
||||
prevState,
|
||||
matrixClient,
|
||||
|
@ -60,7 +60,7 @@ function createSyncAction(matrixClient: MatrixClient, state: string, prevState:
|
|||
*/
|
||||
function createAccountDataAction(matrixClient: MatrixClient, accountDataEvent: MatrixEvent): ActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.accountData',
|
||||
action: "MatrixActions.accountData",
|
||||
event: accountDataEvent,
|
||||
event_type: accountDataEvent.getType(),
|
||||
event_content: accountDataEvent.getContent(),
|
||||
|
@ -92,7 +92,7 @@ function createRoomAccountDataAction(
|
|||
room: Room,
|
||||
): ActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.Room.accountData',
|
||||
action: "MatrixActions.Room.accountData",
|
||||
event: accountDataEvent,
|
||||
event_type: accountDataEvent.getType(),
|
||||
event_content: accountDataEvent.getContent(),
|
||||
|
@ -116,7 +116,7 @@ function createRoomAccountDataAction(
|
|||
* @returns {RoomAction} an action of type `MatrixActions.Room`.
|
||||
*/
|
||||
function createRoomAction(matrixClient: MatrixClient, room: Room): ActionPayload {
|
||||
return { action: 'MatrixActions.Room', room };
|
||||
return { action: "MatrixActions.Room", room };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,7 @@ function createRoomAction(matrixClient: MatrixClient, room: Room): ActionPayload
|
|||
* @returns {RoomTagsAction} an action of type `MatrixActions.Room.tags`.
|
||||
*/
|
||||
function createRoomTagsAction(matrixClient: MatrixClient, roomTagsEvent: MatrixEvent, room: Room): ActionPayload {
|
||||
return { action: 'MatrixActions.Room.tags', room };
|
||||
return { action: "MatrixActions.Room.tags", room };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,7 +151,7 @@ function createRoomTagsAction(matrixClient: MatrixClient, roomTagsEvent: MatrixE
|
|||
*/
|
||||
function createRoomReceiptAction(matrixClient: MatrixClient, event: MatrixEvent, room: Room): ActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.Room.receipt',
|
||||
action: "MatrixActions.Room.receipt",
|
||||
event,
|
||||
room,
|
||||
matrixClient,
|
||||
|
@ -169,7 +169,7 @@ function createRoomReceiptAction(matrixClient: MatrixClient, event: MatrixEvent,
|
|||
* @property {Room} room the Room whose tags changed.
|
||||
*/
|
||||
export interface IRoomTimelineActionPayload extends Pick<ActionPayload, "action"> {
|
||||
action: 'MatrixActions.Room.timeline';
|
||||
action: "MatrixActions.Room.timeline";
|
||||
event: MatrixEvent;
|
||||
room: Room | null;
|
||||
isLiveEvent?: boolean;
|
||||
|
@ -185,7 +185,7 @@ export interface IRoomTimelineActionPayload extends Pick<ActionPayload, "action"
|
|||
* @property {MatrixEvent | null} lastStateEvent the previous value for this (event-type, state-key) tuple in room state
|
||||
*/
|
||||
export interface IRoomStateEventsActionPayload extends Pick<ActionPayload, "action"> {
|
||||
action: 'MatrixActions.RoomState.events';
|
||||
action: "MatrixActions.RoomState.events";
|
||||
event: MatrixEvent;
|
||||
state: RoomState;
|
||||
lastStateEvent: MatrixEvent | null;
|
||||
|
@ -218,7 +218,7 @@ function createRoomTimelineAction(
|
|||
data: IRoomTimelineData,
|
||||
): IRoomTimelineActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.Room.timeline',
|
||||
action: "MatrixActions.Room.timeline",
|
||||
event: timelineEvent,
|
||||
isLiveEvent: data.liveEvent,
|
||||
isLiveUnfilteredRoomTimelineEvent: room && data.timeline.getTimelineSet() === room.getUnfilteredTimelineSet(),
|
||||
|
@ -244,7 +244,7 @@ function createRoomStateEventsAction(
|
|||
lastStateEvent: MatrixEvent | null,
|
||||
): IRoomStateEventsActionPayload {
|
||||
return {
|
||||
action: 'MatrixActions.RoomState.events',
|
||||
action: "MatrixActions.RoomState.events",
|
||||
event,
|
||||
state,
|
||||
lastStateEvent,
|
||||
|
@ -277,7 +277,7 @@ function createSelfMembershipAction(
|
|||
membership: string,
|
||||
oldMembership: string,
|
||||
): ActionPayload {
|
||||
return { action: 'MatrixActions.Room.myMembership', room, membership, oldMembership };
|
||||
return { action: "MatrixActions.Room.myMembership", room, membership, oldMembership };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,7 +297,7 @@ function createSelfMembershipAction(
|
|||
* @returns {EventDecryptedAction} an action of type `MatrixActions.Event.decrypted`.
|
||||
*/
|
||||
function createEventDecryptedAction(matrixClient: MatrixClient, event: MatrixEvent): ActionPayload {
|
||||
return { action: 'MatrixActions.Event.decrypted', event };
|
||||
return { action: "MatrixActions.Event.decrypted", event };
|
||||
}
|
||||
|
||||
type Listener = () => void;
|
||||
|
|
|
@ -19,15 +19,15 @@ import { MatrixClient } from "matrix-js-sdk/src/client";
|
|||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { asyncAction } from './actionCreators';
|
||||
import Modal from '../Modal';
|
||||
import * as Rooms from '../Rooms';
|
||||
import { _t } from '../languageHandler';
|
||||
import { asyncAction } from "./actionCreators";
|
||||
import Modal from "../Modal";
|
||||
import * as Rooms from "../Rooms";
|
||||
import { _t } from "../languageHandler";
|
||||
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||
import RoomListStore from "../stores/room-list/RoomListStore";
|
||||
import { SortAlgorithm } from "../stores/room-list/algorithms/models";
|
||||
import { DefaultTagID } from "../stores/room-list/models";
|
||||
import ErrorDialog from '../components/views/dialogs/ErrorDialog';
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
|
||||
export default class RoomListActions {
|
||||
/**
|
||||
|
@ -47,9 +47,12 @@ export default class RoomListActions {
|
|||
* @see asyncAction
|
||||
*/
|
||||
public static tagRoom(
|
||||
matrixClient: MatrixClient, room: Room,
|
||||
oldTag: string, newTag: string,
|
||||
oldIndex: number | null, newIndex: number | null,
|
||||
matrixClient: MatrixClient,
|
||||
room: Room,
|
||||
oldTag: string,
|
||||
newTag: string,
|
||||
oldIndex: number | null,
|
||||
newIndex: number | null,
|
||||
): AsyncActionPayload {
|
||||
let metaData = null;
|
||||
|
||||
|
@ -62,91 +65,87 @@ export default class RoomListActions {
|
|||
|
||||
// If the room was moved "down" (increasing index) in the same list we
|
||||
// need to use the orders of the tiles with indices shifted by +1
|
||||
const offset = (
|
||||
newTag === oldTag && oldIndex < newIndex
|
||||
) ? 1 : 0;
|
||||
const offset = newTag === oldTag && oldIndex < newIndex ? 1 : 0;
|
||||
|
||||
const indexBefore = offset + newIndex - 1;
|
||||
const indexAfter = offset + newIndex;
|
||||
|
||||
const prevOrder = indexBefore <= 0 ?
|
||||
0 : newList[indexBefore].tags[newTag].order;
|
||||
const nextOrder = indexAfter >= newList.length ?
|
||||
1 : newList[indexAfter].tags[newTag].order;
|
||||
const prevOrder = indexBefore <= 0 ? 0 : newList[indexBefore].tags[newTag].order;
|
||||
const nextOrder = indexAfter >= newList.length ? 1 : newList[indexAfter].tags[newTag].order;
|
||||
|
||||
metaData = {
|
||||
order: (prevOrder + nextOrder) / 2.0,
|
||||
};
|
||||
}
|
||||
|
||||
return asyncAction('RoomListActions.tagRoom', () => {
|
||||
const promises = [];
|
||||
const roomId = room.roomId;
|
||||
return asyncAction(
|
||||
"RoomListActions.tagRoom",
|
||||
() => {
|
||||
const promises = [];
|
||||
const roomId = room.roomId;
|
||||
|
||||
// Evil hack to get DMs behaving
|
||||
if ((oldTag === undefined && newTag === DefaultTagID.DM) ||
|
||||
(oldTag === DefaultTagID.DM && newTag === undefined)
|
||||
) {
|
||||
return Rooms.guessAndSetDMRoom(
|
||||
room, newTag === DefaultTagID.DM,
|
||||
).catch((err) => {
|
||||
logger.error("Failed to set DM tag " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t('Failed to set direct message tag'),
|
||||
description: ((err && err.message) ? err.message : _t('Operation failed')),
|
||||
// Evil hack to get DMs behaving
|
||||
if (
|
||||
(oldTag === undefined && newTag === DefaultTagID.DM) ||
|
||||
(oldTag === DefaultTagID.DM && newTag === undefined)
|
||||
) {
|
||||
return Rooms.guessAndSetDMRoom(room, newTag === DefaultTagID.DM).catch((err) => {
|
||||
logger.error("Failed to set DM tag " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Failed to set direct message tag"),
|
||||
description: err && err.message ? err.message : _t("Operation failed"),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const hasChangedSubLists = oldTag !== newTag;
|
||||
const hasChangedSubLists = oldTag !== newTag;
|
||||
|
||||
// More evilness: We will still be dealing with moving to favourites/low prio,
|
||||
// but we avoid ever doing a request with TAG_DM.
|
||||
//
|
||||
// if we moved lists, remove the old tag
|
||||
if (oldTag && oldTag !== DefaultTagID.DM &&
|
||||
hasChangedSubLists
|
||||
) {
|
||||
const promiseToDelete = matrixClient.deleteRoomTag(
|
||||
roomId, oldTag,
|
||||
).catch(function(err) {
|
||||
logger.error("Failed to remove tag " + oldTag + " from room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t('Failed to remove tag %(tagName)s from room', { tagName: oldTag }),
|
||||
description: ((err && err.message) ? err.message : _t('Operation failed')),
|
||||
});
|
||||
});
|
||||
|
||||
promises.push(promiseToDelete);
|
||||
}
|
||||
|
||||
// if we moved lists or the ordering changed, add the new tag
|
||||
if (newTag && newTag !== DefaultTagID.DM &&
|
||||
(hasChangedSubLists || metaData)
|
||||
) {
|
||||
// metaData is the body of the PUT to set the tag, so it must
|
||||
// at least be an empty object.
|
||||
metaData = metaData || {};
|
||||
|
||||
const promiseToAdd = matrixClient.setRoomTag(roomId, newTag, metaData).catch(function(err) {
|
||||
logger.error("Failed to add tag " + newTag + " to room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t('Failed to add tag %(tagName)s to room', { tagName: newTag }),
|
||||
description: ((err && err.message) ? err.message : _t('Operation failed')),
|
||||
// More evilness: We will still be dealing with moving to favourites/low prio,
|
||||
// but we avoid ever doing a request with TAG_DM.
|
||||
//
|
||||
// if we moved lists, remove the old tag
|
||||
if (oldTag && oldTag !== DefaultTagID.DM && hasChangedSubLists) {
|
||||
const promiseToDelete = matrixClient.deleteRoomTag(roomId, oldTag).catch(function (err) {
|
||||
logger.error("Failed to remove tag " + oldTag + " from room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Failed to remove tag %(tagName)s from room", { tagName: oldTag }),
|
||||
description: err && err.message ? err.message : _t("Operation failed"),
|
||||
});
|
||||
});
|
||||
|
||||
throw err;
|
||||
});
|
||||
promises.push(promiseToDelete);
|
||||
}
|
||||
|
||||
promises.push(promiseToAdd);
|
||||
}
|
||||
// if we moved lists or the ordering changed, add the new tag
|
||||
if (newTag && newTag !== DefaultTagID.DM && (hasChangedSubLists || metaData)) {
|
||||
// metaData is the body of the PUT to set the tag, so it must
|
||||
// at least be an empty object.
|
||||
metaData = metaData || {};
|
||||
|
||||
return Promise.all(promises);
|
||||
}, () => {
|
||||
// For an optimistic update
|
||||
return {
|
||||
room, oldTag, newTag, metaData,
|
||||
};
|
||||
});
|
||||
const promiseToAdd = matrixClient.setRoomTag(roomId, newTag, metaData).catch(function (err) {
|
||||
logger.error("Failed to add tag " + newTag + " to room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Failed to add tag %(tagName)s to room", { tagName: newTag }),
|
||||
description: err && err.message ? err.message : _t("Operation failed"),
|
||||
});
|
||||
|
||||
throw err;
|
||||
});
|
||||
|
||||
promises.push(promiseToAdd);
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
},
|
||||
() => {
|
||||
// For an optimistic update
|
||||
return {
|
||||
room,
|
||||
oldTag,
|
||||
newTag,
|
||||
metaData,
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,14 +47,16 @@ import { AsyncActionPayload } from "../dispatcher/payloads";
|
|||
export function asyncAction(id: string, fn: () => Promise<any>, pendingFn: () => any | null): AsyncActionPayload {
|
||||
const helper = (dispatch) => {
|
||||
dispatch({
|
||||
action: id + '.pending',
|
||||
request: typeof pendingFn === 'function' ? pendingFn() : undefined,
|
||||
});
|
||||
fn().then((result) => {
|
||||
dispatch({ action: id + '.success', result });
|
||||
}).catch((err) => {
|
||||
dispatch({ action: id + '.failure', err });
|
||||
action: id + ".pending",
|
||||
request: typeof pendingFn === "function" ? pendingFn() : undefined,
|
||||
});
|
||||
fn()
|
||||
.then((result) => {
|
||||
dispatch({ action: id + ".success", result });
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch({ action: id + ".failure", err });
|
||||
});
|
||||
};
|
||||
return new AsyncActionPayload(helper);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue