{"record":{"id":"d55bbb261314610f","repo":"RocketChat/Rocket.Chat","slug":"error-user-not-in-room-d55bbb","errorCode":"error-user-not-in-room","errorMessage":"User is not in this room","messagePattern":"User is not in this room","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/unmuteUserInRoom.ts","lineNumber":46,"sourceCode":"\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', {\n\t\t\tmethod: 'unmuteUserInRoom',\n\t\t});\n\t}\n\n\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.MUTE, fromId))) {\n\t\tthrow new Meteor.Error('error-invalid-room-type', `${room.t} is not a valid room type`, {\n\t\t\tmethod: 'unmuteUserInRoom',\n\t\t\ttype: room.t,\n\t\t});\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUsername(data.rid, data.username, {\n\t\tprojection: { _id: 1 },\n\t});\n\n\tif (!subscription) {\n\t\tthrow new Meteor.Error('error-user-not-in-room', 'User is not in this room', {\n\t\t\tmethod: 'unmuteUserInRoom',\n\t\t});\n\t}\n\n\tconst unmutedUser = await Users.findOneByUsernameIgnoringCase(data.username);\n\tif (!unmutedUser?.username) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user to unmute', {\n\t\t\tmethod: 'unmuteUserInRoom',\n\t\t});\n\t}\n\n\tconst fromUser = await Users.findOneById(fromId);\n\tif (!fromUser) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'unmuteUserInRoom',\n\t\t});\n\t}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/unmuteUserInRoom.ts#L28-L64","documentation":"Thrown by the `unmuteUserInRoom` Meteor method when `Subscriptions.findOneByRoomIdAndUsername(data.rid, data.username)` returns null, i.e. the user you are trying to unmute has no subscription document in the target room. The method first checks that the room type allows the MUTE member action, then requires the target to actually be a member. Since there is no membership record, there is nothing to unmute and the whole operation is aborted before any DB write.","triggerScenarios":"Calling `Meteor.call('unmuteUserInRoom', { rid, username })` where `username` is not subscribed to `rid`: the target user left or was kicked/removed from the room, the client member list is stale and still renders an unmute action, or the username passed does not exactly match the username stored on the subscription (e.g. after a rename).","commonSituations":"Stale room member UI after another moderator removes the user; race between a kick and an unmute from two admins; moderation bots unmuting by cached username after the user was removed; usernames renamed between the action trigger and the method call.","solutions":["Re-fetch the current room members before showing the unmute action, and only enable it for users still subscribed.","Verify the subscription first (server-side `Subscriptions.findOneByRoomIdAndUsername(rid, username)`, or the room members data on the client).","Pass the username exactly as recorded on the subscription (`sub.u.username`) instead of a possibly renamed copy.","In UI code, treat this error as benign: toast 'user is not in this room' and refresh the room state."],"exampleFix":"// before\nMeteor.call('unmuteUserInRoom', { rid, username });\n\n// after - only unmute current members, using the subscribed username\nconst sub = Subscriptions.findOne({ rid, 'u.username': username });\nif (!sub) {\n  // stale UI: user already left the room - refresh members and skip\n  return;\n}\nMeteor.call('unmuteUserInRoom', { rid, username: sub.u.username });","handlingStrategy":"validation","validationCode":"// server-side: confirm membership before unmuting\nconst isRoomMember = async (rid: string, username: string) =>\n  Boolean(await Subscriptions.findOneByRoomIdAndUsername(rid, username, { projections: { _id: 1 } }));\n\nif (await isRoomMember(rid, username)) {\n  await Meteor.callAsync('unmuteUserInRoom', { rid, username });\n}","typeGuard":"const isRoomMember = (rid: string, username: string): boolean =>\n  !!Subscriptions.findOne({ rid, 'u.username': username }, { fields: { _id: 1 } });","tryCatchPattern":"try {\n  await Meteor.callAsync('unmuteUserInRoom', { rid, username });\n} catch (e: any) {\n  if (e?.error === 'error-user-not-in-room') {\n    // benign: target already left the room - refresh the member list and continue\n    return;\n  }\n  throw e;\n}","preventionTips":["Render unmute actions from live subscription/member data, not cached lists.","After any removeUser/leaveRoom flow, clear pending moderation actions for that user.","Pass usernames taken from the subscription record to survive renames and casing differences."],"tags":["meteor","rooms","moderation","mute","subscriptions"],"backgroundTag":"user-not-in-room","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}