mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-23 13:43:07 +01:00
fix dm room util function
This commit is contained in:
parent
2c6b4b4c52
commit
8458c6c578
2 changed files with 5 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
import { MatrixClient, Room } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { hasDMWith, isRoomAlias, isRoomId, isUserId } from '../utils/matrix';
|
||||
import { getDMRoomFor, isRoomAlias, isRoomId, isUserId } from '../utils/matrix';
|
||||
import { selectRoom } from '../../client/action/navigation';
|
||||
import { hasDevices } from '../../util/matrixUtil';
|
||||
import * as roomActions from '../../client/action/room';
|
||||
|
@ -84,7 +84,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
|||
const userIds = rawIds.filter((id) => isUserId(id) && id !== mx.getUserId());
|
||||
if (userIds.length === 0) return;
|
||||
if (userIds.length === 1) {
|
||||
const dmRoomId = hasDMWith(mx, userIds[0]);
|
||||
const dmRoomId = getDMRoomFor(mx, userIds[0])?.roomId;
|
||||
if (dmRoomId) {
|
||||
selectRoom(dmRoomId);
|
||||
return;
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
MatrixClient,
|
||||
MatrixError,
|
||||
MatrixEvent,
|
||||
Room,
|
||||
UploadProgress,
|
||||
UploadResponse,
|
||||
} from 'matrix-js-sdk';
|
||||
|
@ -164,10 +165,10 @@ export const factoryEventSentBy = (senderId: string) => (ev: MatrixEvent) =>
|
|||
export const eventWithShortcode = (ev: MatrixEvent) =>
|
||||
typeof ev.getContent().shortcode === 'string';
|
||||
|
||||
export function hasDMWith(mx: MatrixClient, userId: string) {
|
||||
export const getDMRoomFor = (mx: MatrixClient, userId: string): Room | undefined => {
|
||||
const dmLikeRooms = mx
|
||||
.getRooms()
|
||||
.filter((room) => mx.isRoomEncrypted(room.roomId) && room.getMembers().length <= 2);
|
||||
|
||||
return dmLikeRooms.find((room) => room.getMember(userId));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue