Room list: remove unused sorting ManualAlgorithm (#32724)
* chore: remove unused `ManualAlgorithm` In the old room list ui, we can"t manually sort the rooms or the sections. Neither in a menu or by drag and drop * fix: add `undefined` to `tagRoom` signature since the code allows it * test: add tests to `RoomListActions` * chore: remuve unuseful comment * refactor: remove unused ``newIndex * doc: remove typing in tsdoc
This commit is contained in:
@@ -15,8 +15,6 @@ import Modal from "../Modal";
|
||||
import * as Rooms from "../Rooms";
|
||||
import { _t } from "../languageHandler";
|
||||
import { type AsyncActionPayload } from "../dispatcher/payloads";
|
||||
import RoomListStore from "../stores/room-list/RoomListStore";
|
||||
import { SortAlgorithm } from "../stores/room-list/algorithms/models";
|
||||
import { DefaultTagID, type TagID } from "../stores/room-list-v3/skip-list/tag";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
|
||||
@@ -25,45 +23,22 @@ export default class RoomListActions {
|
||||
* Creates an action thunk that will do an asynchronous request to
|
||||
* tag room.
|
||||
*
|
||||
* @param {MatrixClient} matrixClient the matrix client to set the
|
||||
* @param matrixClient the matrix client to set the
|
||||
* account data on.
|
||||
* @param {Room} room the room to tag.
|
||||
* @param {string} oldTag the tag to remove (unless oldTag ==== newTag)
|
||||
* @param {string} newTag the tag with which to tag the room.
|
||||
* @param {?number} oldIndex the previous position of the room in the
|
||||
* @param room the room to tag.
|
||||
* @param oldTag the tag to remove (unless oldTag ==== newTag)
|
||||
* @param newTag the tag with which to tag the room.
|
||||
* @param oldIndex the previous position of the room in the
|
||||
* list of rooms.
|
||||
* @param {?number} newIndex the new position of the room in the list
|
||||
* of rooms.
|
||||
* @returns {AsyncActionPayload} an async action payload
|
||||
* @returns an async action payload
|
||||
* @see asyncAction
|
||||
*/
|
||||
public static tagRoom(
|
||||
matrixClient: MatrixClient,
|
||||
room: Room,
|
||||
oldTag: TagID | null,
|
||||
newTag: TagID | null,
|
||||
newIndex: number,
|
||||
oldTag: TagID | null | undefined,
|
||||
newTag: TagID | null | undefined,
|
||||
): AsyncActionPayload {
|
||||
let metaData: Parameters<MatrixClient["setRoomTag"]>[2] | undefined;
|
||||
|
||||
// Is the tag ordered manually?
|
||||
const store = RoomListStore.instance;
|
||||
if (newTag && store.getTagSorting(newTag) === SortAlgorithm.Manual) {
|
||||
const newList = [...store.orderedLists[newTag]];
|
||||
|
||||
newList.sort((a, b) => a.tags[newTag].order - b.tags[newTag].order);
|
||||
|
||||
const indexBefore = newIndex - 1;
|
||||
const indexAfter = newIndex;
|
||||
|
||||
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",
|
||||
() => {
|
||||
@@ -103,8 +78,8 @@ export default class RoomListActions {
|
||||
}
|
||||
|
||||
// if we moved lists or the ordering changed, add the new tag
|
||||
if (newTag && newTag !== DefaultTagID.DM && (hasChangedSubLists || metaData)) {
|
||||
const promiseToAdd = matrixClient.setRoomTag(roomId, newTag, metaData).catch(function (err) {
|
||||
if (newTag && newTag !== DefaultTagID.DM && hasChangedSubLists) {
|
||||
const promiseToAdd = matrixClient.setRoomTag(roomId, newTag).catch(function (err) {
|
||||
logger.error("Failed to add tag " + newTag + " to room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("room_list|failed_add_tag", { tagName: newTag }),
|
||||
@@ -125,7 +100,6 @@ export default class RoomListActions {
|
||||
room,
|
||||
oldTag,
|
||||
newTag,
|
||||
metaData,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user