|
7 | 7 | ajv, |
8 | 8 | isGETRoomsNameExists, |
9 | 9 | isRoomsImagesProps, |
10 | | - isRoomsMuteUnmuteUserProps, |
11 | 10 | isRoomsExportProps, |
12 | 11 | isRoomsIsMemberProps, |
13 | 12 | isRoomsCleanHistoryProps, |
@@ -875,42 +874,6 @@ API.v1.addRoute( |
875 | 874 | }, |
876 | 875 | ); |
877 | 876 |
|
878 | | -API.v1.addRoute( |
879 | | - 'rooms.muteUser', |
880 | | - { authRequired: true, validateParams: isRoomsMuteUnmuteUserProps }, |
881 | | - { |
882 | | - async post() { |
883 | | - const user = await getUserFromParams(this.bodyParams); |
884 | | - |
885 | | - if (!user.username) { |
886 | | - return API.v1.failure('Invalid user'); |
887 | | - } |
888 | | - |
889 | | - await muteUserInRoom(this.userId, { rid: this.bodyParams.roomId, username: user.username }); |
890 | | - |
891 | | - return API.v1.success(); |
892 | | - }, |
893 | | - }, |
894 | | -); |
895 | | - |
896 | | -API.v1.addRoute( |
897 | | - 'rooms.unmuteUser', |
898 | | - { authRequired: true, validateParams: isRoomsMuteUnmuteUserProps }, |
899 | | - { |
900 | | - async post() { |
901 | | - const user = await getUserFromParams(this.bodyParams); |
902 | | - |
903 | | - if (!user.username) { |
904 | | - return API.v1.failure('Invalid user'); |
905 | | - } |
906 | | - |
907 | | - await unmuteUserInRoom(this.userId, { rid: this.bodyParams.roomId, username: user.username }); |
908 | | - |
909 | | - return API.v1.success(); |
910 | | - }, |
911 | | - }, |
912 | | -); |
913 | | - |
914 | 877 | API.v1.addRoute( |
915 | 878 | 'rooms.open', |
916 | 879 | { authRequired: true, validateParams: isRoomsOpenProps }, |
@@ -1027,6 +990,44 @@ const isRoomsLeavePropsSchema = { |
1027 | 990 | const isRoomsFavoriteProps = ajv.compile<RoomsFavorite>(RoomsFavoriteSchema); |
1028 | 991 | const isRoomsLeaveProps = ajv.compile<RoomsLeave>(isRoomsLeavePropsSchema); |
1029 | 992 |
|
| 993 | +type RoomsMuteUnmuteUser = { userId: string; roomId: string } | { username: string; roomId: string }; |
| 994 | + |
| 995 | +const RoomsMuteUnmuteUserSchema = { |
| 996 | + type: 'object', |
| 997 | + oneOf: [ |
| 998 | + { |
| 999 | + properties: { |
| 1000 | + userId: { |
| 1001 | + type: 'string', |
| 1002 | + minLength: 1, |
| 1003 | + }, |
| 1004 | + roomId: { |
| 1005 | + type: 'string', |
| 1006 | + minLength: 1, |
| 1007 | + }, |
| 1008 | + }, |
| 1009 | + required: ['userId', 'roomId'], |
| 1010 | + additionalProperties: false, |
| 1011 | + }, |
| 1012 | + { |
| 1013 | + properties: { |
| 1014 | + username: { |
| 1015 | + type: 'string', |
| 1016 | + minLength: 1, |
| 1017 | + }, |
| 1018 | + roomId: { |
| 1019 | + type: 'string', |
| 1020 | + minLength: 1, |
| 1021 | + }, |
| 1022 | + }, |
| 1023 | + required: ['username', 'roomId'], |
| 1024 | + additionalProperties: false, |
| 1025 | + }, |
| 1026 | + ], |
| 1027 | +}; |
| 1028 | + |
| 1029 | +const isRoomsMuteUnmuteUserProps = ajv.compile<RoomsMuteUnmuteUser>(RoomsMuteUnmuteUserSchema); |
| 1030 | + |
1030 | 1031 | export const roomEndpoints = API.v1 |
1031 | 1032 | .get( |
1032 | 1033 | 'rooms.roles', |
@@ -1233,6 +1234,66 @@ export const roomEndpoints = API.v1 |
1233 | 1234 |
|
1234 | 1235 | return API.v1.success(); |
1235 | 1236 | }, |
| 1237 | + ) |
| 1238 | + .post( |
| 1239 | + 'rooms.muteUser', |
| 1240 | + { |
| 1241 | + authRequired: true, |
| 1242 | + body: isRoomsMuteUnmuteUserProps, |
| 1243 | + response: { |
| 1244 | + 200: ajv.compile<{ success: true }>({ |
| 1245 | + type: 'object', |
| 1246 | + properties: { |
| 1247 | + success: { type: 'boolean', enum: [true] }, |
| 1248 | + }, |
| 1249 | + required: ['success'], |
| 1250 | + additionalProperties: false, |
| 1251 | + }), |
| 1252 | + 400: validateBadRequestErrorResponse, |
| 1253 | + 401: validateUnauthorizedErrorResponse, |
| 1254 | + }, |
| 1255 | + }, |
| 1256 | + async function action() { |
| 1257 | + const user = await getUserFromParams(this.bodyParams); |
| 1258 | + |
| 1259 | + if (!user.username) { |
| 1260 | + return API.v1.failure('Invalid user'); |
| 1261 | + } |
| 1262 | + |
| 1263 | + await muteUserInRoom(this.userId, { rid: this.bodyParams.roomId, username: user.username }); |
| 1264 | + |
| 1265 | + return API.v1.success({ success: true }); |
| 1266 | + }, |
| 1267 | + ) |
| 1268 | + .post( |
| 1269 | + 'rooms.unmuteUser', |
| 1270 | + { |
| 1271 | + authRequired: true, |
| 1272 | + body: isRoomsMuteUnmuteUserProps, |
| 1273 | + response: { |
| 1274 | + 200: ajv.compile<{ success: true }>({ |
| 1275 | + type: 'object', |
| 1276 | + properties: { |
| 1277 | + success: { type: 'boolean', enum: [true] }, |
| 1278 | + }, |
| 1279 | + required: ['success'], |
| 1280 | + additionalProperties: false, |
| 1281 | + }), |
| 1282 | + 400: validateBadRequestErrorResponse, |
| 1283 | + 401: validateUnauthorizedErrorResponse, |
| 1284 | + }, |
| 1285 | + }, |
| 1286 | + async function action() { |
| 1287 | + const user = await getUserFromParams(this.bodyParams); |
| 1288 | + |
| 1289 | + if (!user.username) { |
| 1290 | + return API.v1.failure('Invalid user'); |
| 1291 | + } |
| 1292 | + |
| 1293 | + await unmuteUserInRoom(this.userId, { rid: this.bodyParams.roomId, username: user.username }); |
| 1294 | + |
| 1295 | + return API.v1.success({ success: true }); |
| 1296 | + }, |
1236 | 1297 | ); |
1237 | 1298 |
|
1238 | 1299 | type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> & |
|
0 commit comments