app/api/server/v1/channels.js
// Returns the channel IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Returns the channel IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Returns the channel IF found otherwise it will return the failure of why it didn ' t . Check the ` statusCode ` property
function findChannelByIdOrName({ params, checkedArchived = true, userId }) {
	if ((!params.roomId || !params.roomId.trim()) && (!params.roomName || !params.roomName.trim())) {
		throw new Meteor.Error('error-roomid-param-not-provided', 'The parameter "roomId" or "roomName" is required');
	}
	const fields = { ...API.v1.defaultFieldsToExclude };
	let room;
	if (params.roomId) {
		room = Rooms.findOneById(params.roomId, { fields });
	} else if (params.roomName) {
		room = Rooms.findOneByName(params.roomName, { fields });
	}
	if (!room || (room.t !== 'c' && room.t !== 'l')) {
		throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any channel');
	}
	if (checkedArchived && room.archived) {
		throw new Meteor.Error('error-room-archived', `The channel, ${ room.name }, is archived`);
	}
	if (userId && room.lastMessage) {
		const [lastMessage] = normalizeMessagesForUser([room.lastMessage], userId);
		room.lastMessage = lastMessage;
	}
	return room;
}
function findChannelByIdOrName ( { params , checkedArchived = true , userId } ) { if ( ( ! params . roomId || ! params . roomId . trim ( ) ) && ( ! params . roomName || ! params . roomName . trim ( ) ) ) { throw new Meteor . Error ( 'error-roomid-param-not-provided' , 'The parameter "roomId" or "roomName" is required' ) ; } const fields = { ... API . v1 . defaultFieldsToExclude } ; let room ; if ( params . roomId ) { room = Rooms . findOneById ( params . roomId , { fields } ) ; } else if ( params . roomName ) { room = Rooms . findOneByName ( params . roomName , { fields } ) ; } if ( ! room || ( room . t !== 'c' && room . t !== 'l' ) ) { throw new Meteor . Error ( 'error-room-not-found' , 'The required "roomId" or "roomName" param provided does not match any channel' ) ; } if ( checkedArchived && room . archived ) { throw new Meteor . Error ( 'error-room-archived' , ` ${ room . name } ` ) ; } if ( userId && room . lastMessage ) { const [ lastMessage ] = normalizeMessagesForUser ( [ room . lastMessage ] , userId ) ; room . lastMessage = lastMessage ; } return room ; }
Returns the channel IF found otherwise it will return the failure of why it didn't.
Returns the channel IF found otherwise it will return the failure of why it didn ' t .