Fix promises to be awaited

This commit is contained in:
Henrik Hüttemann 2023-06-12 16:52:41 +02:00
parent e706451d90
commit 5d5c751de8
No known key found for this signature in database
GPG Key ID: 9F7BD10E0A8A111E
2 changed files with 7 additions and 5 deletions

View File

@ -77,7 +77,7 @@ async function loadRcExport(entity: Entities) {
log.debug('Mapping added:', mapping)
// Add user to room mapping (specific to users)
Promise.all(
await Promise.all(
rcUser.__rooms.map(async (rcRoomId: string) => {
await createMembership(rcRoomId, rcUser._id)
log.debug(`${rcUser.username} membership for ${rcRoomId} created`)
@ -123,11 +123,13 @@ async function main() {
try {
await whoami()
await initStorage()
log.info('Parsing users')
await loadRcExport(Entities.Users)
log.info('Parsing rooms')
await loadRcExport(Entities.Rooms)
log.info('Done.')
} catch (error) {
log.error(`Encountered an error while booting up: ${error}`)
log.error(`Encountered an error while booting up: ${error}`, error)
}
}

View File

@ -45,7 +45,7 @@ export type MatrixRoom = {
_creatorId?: string
}
export function mapRoom(rcRoom: RcRoom): MatrixRoom {
export async function mapRoom(rcRoom: RcRoom): Promise<MatrixRoom> {
const room: MatrixRoom = {
creation_content: {
'm.federate': false,
@ -63,7 +63,7 @@ export function mapRoom(rcRoom: RcRoom): MatrixRoom {
room._creatorId = rcRoom.uids?.[0] || ''
if (rcRoom.uids) {
Promise.all(
await Promise.all(
rcRoom.uids.map(async (uid) => {
await createMembership(rcRoom._id, uid)
log.debug(`${uid} membership in direct chat ${rcRoom._id} created`)
@ -100,7 +100,7 @@ export function mapRoom(rcRoom: RcRoom): MatrixRoom {
}
export async function createRoom(rcRoom: RcRoom): Promise<MatrixRoom> {
const room: MatrixRoom = mapRoom(rcRoom)
const room: MatrixRoom = await mapRoom(rcRoom)
let sessionOptions = {}
if (room._creatorId) {
try {