Sort dms by activity

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-17 09:34:26 +05:30
parent 8da47dbdbc
commit de17005409
4 changed files with 27 additions and 52 deletions

View file

@ -4,15 +4,14 @@ import initMatrix from '../../../client/initMatrix';
import cons from '../../../client/state/cons'; import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation'; import navigation from '../../../client/state/navigation';
import Postie from '../../../util/Postie'; import Postie from '../../../util/Postie';
import { roomIdByLastActive } from '../../../util/sort';
import RoomsCategory from './RoomsCategory'; import RoomsCategory from './RoomsCategory';
import { AtoZ } from './common';
const drawerPostie = new Postie(); const drawerPostie = new Postie();
function Directs() { function Directs() {
const { roomList, notifications } = initMatrix; const { roomList, notifications } = initMatrix;
const directIds = [...roomList.directs].sort(AtoZ); const directIds = [...roomList.directs].sort(roomIdByLastActive);
useEffect(() => { useEffect(() => {
const selectorChanged = (selectedRoomId, prevSelectedRoomId) => { const selectorChanged = (selectedRoomId, prevSelectedRoomId) => {

View file

@ -5,11 +5,11 @@ import initMatrix from '../../../client/initMatrix';
import cons from '../../../client/state/cons'; import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation'; import navigation from '../../../client/state/navigation';
import Postie from '../../../util/Postie'; import Postie from '../../../util/Postie';
import { roomIdByLastActive, roomIdByAtoZ } from '../../../util/sort';
import RoomsCategory from './RoomsCategory'; import RoomsCategory from './RoomsCategory';
import { useCategorizedSpaces } from '../../hooks/useCategorizedSpaces'; import { useCategorizedSpaces } from '../../hooks/useCategorizedSpaces';
import { AtoZ, RoomToDM } from './common';
const drawerPostie = new Postie(); const drawerPostie = new Postie();
function Home({ spaceId }) { function Home({ spaceId }) {
@ -34,10 +34,6 @@ function Home({ spaceId }) {
roomIds = roomList.getOrphanRooms(); roomIds = roomList.getOrphanRooms();
} }
spaceIds.sort(AtoZ);
roomIds.sort(AtoZ);
directIds.sort(AtoZ);
if (isCategorized) { if (isCategorized) {
categories = roomList.getCategorizedSpaces(spaceIds); categories = roomList.getCategorizedSpaces(spaceIds);
categories.delete(spaceId); categories.delete(spaceId);
@ -73,26 +69,36 @@ function Home({ spaceId }) {
return ( return (
<> <>
{ !isCategorized && spaceIds.length !== 0 && ( { !isCategorized && spaceIds.length !== 0 && (
<RoomsCategory name="Spaces" roomIds={spaceIds} drawerPostie={drawerPostie} /> <RoomsCategory name="Spaces" roomIds={spaceIds.sort(roomIdByAtoZ)} drawerPostie={drawerPostie} />
)} )}
{ roomIds.length !== 0 && ( { roomIds.length !== 0 && (
<RoomsCategory name="Rooms" roomIds={roomIds} drawerPostie={drawerPostie} /> <RoomsCategory name="Rooms" roomIds={roomIds.sort(roomIdByAtoZ)} drawerPostie={drawerPostie} />
)} )}
{ directIds.length !== 0 && ( { directIds.length !== 0 && (
<RoomsCategory name="People" roomIds={directIds} drawerPostie={drawerPostie} /> <RoomsCategory name="People" roomIds={directIds.sort(roomIdByLastActive)} drawerPostie={drawerPostie} />
)} )}
{ isCategorized && [...categories].map(([catId, childIds]) => ( { isCategorized && [...categories].map(([catId, childIds]) => {
<RoomsCategory const rms = [];
key={catId} const dms = [];
spaceId={catId} childIds.forEach((id) => {
name={mx.getRoom(catId).name} if (directs.has(id)) dms.push(id);
roomIds={[...childIds].sort(AtoZ).sort(RoomToDM)} else rms.push(id);
drawerPostie={drawerPostie} });
/> rms.sort(roomIdByAtoZ);
))} dms.sort(roomIdByLastActive);
return (
<RoomsCategory
key={catId}
spaceId={catId}
name={mx.getRoom(catId).name}
roomIds={rms.concat(dms)}
drawerPostie={drawerPostie}
/>
);
})}
</> </>
); );
} }

View file

@ -1,30 +0,0 @@
import initMatrix from '../../../client/initMatrix';
function AtoZ(aId, bId) {
let aName = initMatrix.matrixClient.getRoom(aId).name;
let bName = initMatrix.matrixClient.getRoom(bId).name;
// remove "#" from the room name
// To ignore it in sorting
aName = aName.replaceAll('#', '');
bName = bName.replaceAll('#', '');
if (aName.toLowerCase() < bName.toLowerCase()) {
return -1;
}
if (aName.toLowerCase() > bName.toLowerCase()) {
return 1;
}
return 0;
}
const RoomToDM = (aId, bId) => {
const { directs } = initMatrix.roomList;
const aIsDm = directs.has(aId);
const bIsDm = directs.has(bId);
if (aIsDm && !bIsDm) return 1;
if (!aIsDm && bIsDm) return -1;
return 0;
};
export { AtoZ, RoomToDM };

View file

@ -6,6 +6,7 @@ import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation'; import navigation from '../../../client/state/navigation';
import { createSpaceShortcut, deleteSpaceShortcut } from '../../../client/action/accountData'; import { createSpaceShortcut, deleteSpaceShortcut } from '../../../client/action/accountData';
import { joinRuleToIconSrc } from '../../../util/matrixUtil'; import { joinRuleToIconSrc } from '../../../util/matrixUtil';
import { roomIdByAtoZ } from '../../../util/sort';
import Text from '../../atoms/text/Text'; import Text from '../../atoms/text/Text';
import Button from '../../atoms/button/Button'; import Button from '../../atoms/button/Button';
@ -20,7 +21,6 @@ import PinFilledIC from '../../../../public/res/ic/filled/pin.svg';
import CrossIC from '../../../../public/res/ic/outlined/cross.svg'; import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
import { useSpaceShortcut } from '../../hooks/useSpaceShortcut'; import { useSpaceShortcut } from '../../hooks/useSpaceShortcut';
import { AtoZ } from '../navigation/common';
function ShortcutSpacesContent() { function ShortcutSpacesContent() {
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
@ -29,7 +29,7 @@ function ShortcutSpacesContent() {
const [spaceShortcut] = useSpaceShortcut(); const [spaceShortcut] = useSpaceShortcut();
const spaceWithoutShortcut = [...spaces].filter( const spaceWithoutShortcut = [...spaces].filter(
(spaceId) => !spaceShortcut.includes(spaceId), (spaceId) => !spaceShortcut.includes(spaceId),
).sort(AtoZ); ).sort(roomIdByAtoZ);
const [process, setProcess] = useState(null); const [process, setProcess] = useState(null);
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);