// DEPRECATE import type { ServerMethods } from '@rocket.chat/ddp-client'; import { Rooms } from '@rocket.chat/models'; import { check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import { canAccessRoomAsync } from '../../lib/authorization'; import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger'; declare module '@rocket.chat/ddp-client' { // eslint-disable-next-line @typescript-eslint/naming-convention interface ServerMethods { getRoomIdByNameOrId(rid: string): string; } } Meteor.methods({ async getRoomIdByNameOrId(rid) { methodDeprecationLogger.method('getRoomIdByNameOrId', '9.0.0', '/v1/rooms.info'); check(rid, String); if (!Meteor.userId()) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomIdByNameOrId', }); } const room = (await Rooms.findOneById(rid)) || (await Rooms.findOneByName(rid)); if (room == null) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getRoomIdByNameOrId', }); } if (!(await canAccessRoomAsync(room, (await Meteor.userAsync()) ?? undefined))) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getRoomIdByNameOrId', }); } return room._id; }, });