Add public room visibility to public chats
This commit is contained in:
parent
ef86d6e369
commit
997ebf3ebb
@ -1,4 +1,9 @@
|
|||||||
import { MatrixRoomPresets, RcRoomTypes, mapRoom } from './rooms'
|
import {
|
||||||
|
MatrixRoomPresets,
|
||||||
|
MatrixRoomVisibility,
|
||||||
|
RcRoomTypes,
|
||||||
|
mapRoom,
|
||||||
|
} from './rooms'
|
||||||
|
|
||||||
const roomCreator = {
|
const roomCreator = {
|
||||||
_id: 'roomcreatorid',
|
_id: 'roomcreatorid',
|
||||||
@ -44,6 +49,7 @@ test('mapping public rooms', () => {
|
|||||||
creation_content: {
|
creation_content: {
|
||||||
'm.federate': false,
|
'm.federate': false,
|
||||||
},
|
},
|
||||||
|
visibility: MatrixRoomVisibility.public,
|
||||||
_creatorId: roomCreator._id,
|
_creatorId: roomCreator._id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -27,6 +27,11 @@ export const enum MatrixRoomPresets {
|
|||||||
trusted = 'trusted_private_chat',
|
trusted = 'trusted_private_chat',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const enum MatrixRoomVisibility {
|
||||||
|
private = 'private',
|
||||||
|
public = 'public',
|
||||||
|
}
|
||||||
|
|
||||||
export type MatrixRoom = {
|
export type MatrixRoom = {
|
||||||
room_id?: string
|
room_id?: string
|
||||||
name?: string
|
name?: string
|
||||||
@ -35,6 +40,7 @@ export type MatrixRoom = {
|
|||||||
topic?: string
|
topic?: string
|
||||||
is_direct?: boolean
|
is_direct?: boolean
|
||||||
preset?: MatrixRoomPresets
|
preset?: MatrixRoomPresets
|
||||||
|
visibility?: MatrixRoomVisibility
|
||||||
_creatorId?: string
|
_creatorId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,24 +56,26 @@ export function mapRoom(rcRoom: RcRoom): MatrixRoom {
|
|||||||
rcRoom.description && (room.topic = rcRoom.description)
|
rcRoom.description && (room.topic = rcRoom.description)
|
||||||
|
|
||||||
switch (rcRoom.t) {
|
switch (rcRoom.t) {
|
||||||
case 'd':
|
case RcRoomTypes.direct:
|
||||||
room.is_direct = true
|
room.is_direct = true
|
||||||
room.preset = MatrixRoomPresets.trusted
|
room.preset = MatrixRoomPresets.trusted
|
||||||
room._creatorId = rcRoom.uids?.[0] || ''
|
room._creatorId = rcRoom.uids?.[0] || ''
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'c':
|
case RcRoomTypes.chat:
|
||||||
room.preset = MatrixRoomPresets.public
|
room.preset = MatrixRoomPresets.public
|
||||||
|
room.visibility = MatrixRoomVisibility.public
|
||||||
room._creatorId = rcRoom.u?._id || ''
|
room._creatorId = rcRoom.u?._id || ''
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'p':
|
case RcRoomTypes.private:
|
||||||
room.preset = MatrixRoomPresets.private
|
room.preset = MatrixRoomPresets.private
|
||||||
room._creatorId = rcRoom.u?._id || ''
|
room._creatorId = rcRoom.u?._id || ''
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case RcRoomTypes.live:
|
||||||
default:
|
default:
|
||||||
const message = `Room type ${rcRoom.t} is unknown`
|
const message = `Room type ${rcRoom.t} is unknown or unimplemented`
|
||||||
log.error(message)
|
log.error(message)
|
||||||
throw new Error(message)
|
throw new Error(message)
|
||||||
}
|
}
|
||||||
@ -98,7 +106,7 @@ export async function createRoom(rcRoom: RcRoom): Promise<MatrixRoom> {
|
|||||||
await axios.post('/_matrix/client/v3/createRoom', room, sessionOptions)
|
await axios.post('/_matrix/client/v3/createRoom', room, sessionOptions)
|
||||||
).data.room_id
|
).data.room_id
|
||||||
|
|
||||||
// TODO: Add members
|
// TODO: Invite members and let them join
|
||||||
|
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user