Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion apps/meteor/server/api/v1/im.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
validateBadRequestErrorResponse,
isDmBlockUserProps,
isDmFileProps,
isDmLeaveProps,
isDmMemberProps,
isDmMessagesProps,
isDmCreateProps,
Expand All @@ -31,6 +32,7 @@ import { normalizeMessagesForUser } from '../../lib/utils/lib/normalizeMessagesF
import { createDirectMessage } from '../../meteor-methods/messages/createDirectMessage';
import { getChannelHistory } from '../../meteor-methods/messages/getChannelHistory';
import { hideRoomMethod } from '../../meteor-methods/rooms/hideRoom';
import { leaveRoomMethod } from '../../meteor-methods/rooms/leaveRoom';
import { saveRoomSettings } from '../../meteor-methods/rooms/saveRoomSettings';
import { settings } from '../../settings';
import type { ExtractRoutesFromAPI } from '../ApiClass';
Expand Down Expand Up @@ -927,6 +929,35 @@ const dmCreateAction = <Path extends string>(_path: Path): TypedAction<typeof dm
});
};

const dmLeaveEndpointsProps = {
authRequired: true,
body: isDmLeaveProps,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<void>({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
additionalProperties: false,
}),
},
} as const;

const dmLeaveAction = <Path extends string>(_path: Path): TypedAction<typeof dmLeaveEndpointsProps, Path> =>
async function action() {
const { room } = await findDirectMessageRoom(
'roomId' in this.bodyParams ? { roomId: this.bodyParams.roomId } : { username: this.bodyParams.roomName },
this.userId,
);

await leaveRoomMethod(this.user, room._id);

return API.v1.success();
};

const dmBlockUserEndpointsProps = {
authRequired: true,
body: isDmBlockUserProps,
Expand Down Expand Up @@ -990,7 +1021,10 @@ const dmEndpoints = API.v1
.get('im.list', dmListEndpointsProps, dmListAction('im.list'))
.get('dm.list.everyone', dmListEveryoneEndpointsProps, dmListEveryoneAction('dm.list.everyone'))
.get('im.list.everyone', dmListEveryoneEndpointsProps, dmListEveryoneAction('im.list.everyone'))
.post('im.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('im.blockUser'));
.post('im.leave', dmLeaveEndpointsProps, dmLeaveAction('im.leave'))
.post('dm.leave', dmLeaveEndpointsProps, dmLeaveAction('dm.leave'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The DmEndpoints type in packages/rest-typings/src/v1/dm/dm.ts is missing entries for the new dm.leave and dm.blockUser endpoints. These endpoints were added server-side but aren't represented in the DmEndpoints type definition, which means TypeScript consumers calling these endpoints won't get type-checking support and may see type errors. All other dm.* endpoints follow a consistent mapping pattern using ImEndpoints['/v1/im.*'] — the missing entries should follow the same pattern: '/v1/dm.leave': ImEndpoints['/v1/im.leave'] and '/v1/dm.blockUser': ImEndpoints['/v1/im.blockUser'].

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/server/api/v1/im.ts, line 1025:

<comment>The `DmEndpoints` type in `packages/rest-typings/src/v1/dm/dm.ts` is missing entries for the new `dm.leave` and `dm.blockUser` endpoints. These endpoints were added server-side but aren't represented in the `DmEndpoints` type definition, which means TypeScript consumers calling these endpoints won't get type-checking support and may see type errors. All other `dm.*` endpoints follow a consistent mapping pattern using `ImEndpoints['/v1/im.*']` — the missing entries should follow the same pattern: `'/v1/dm.leave': ImEndpoints['/v1/im.leave']` and `'/v1/dm.blockUser': ImEndpoints['/v1/im.blockUser']`.</comment>

<file context>
@@ -990,7 +1021,10 @@ const dmEndpoints = API.v1
 	.get('im.list.everyone', dmListEveryoneEndpointsProps, dmListEveryoneAction('im.list.everyone'))
-	.post('im.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('im.blockUser'));
+	.post('im.leave', dmLeaveEndpointsProps, dmLeaveAction('im.leave'))
+	.post('dm.leave', dmLeaveEndpointsProps, dmLeaveAction('dm.leave'))
+	.post('im.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('im.blockUser'))
+	.post('dm.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('dm.blockUser'));
</file context>

.post('im.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('im.blockUser'))
.post('dm.blockUser', dmBlockUserEndpointsProps, dmBlockUserAction('dm.blockUser'));

export type DmEndpoints = ExtractRoutesFromAPI<typeof dmEndpoints>;

Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/v1/dm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export type * from './im';
export * from './DmBlockUserProps';
export * from './DmCreateProps';
export * from './DmFileProps';
export * from './DmLeaveProps';
export * from './DmMembersProps';
export * from './DmMessagesProps';
Loading