Adding the typing... indicator, loading older messages, and managing members/admins after creation.

This commit is contained in:
2026-09-30 11:53:04 +03:30
parent b978708487
commit e1d456ad11
9 changed files with 992 additions and 28 deletions
@@ -128,4 +128,81 @@ export class ChatExternalClient {
return false;
}
}
/** تلاش برای افزودن عضو به اتاق روی سرویس خارجی (endpointهای رایج). */
async addRoomMembers(
host: string,
apiKey: string,
roomId: string,
members: string[],
): Promise<boolean> {
const base = this.normalizeHost(host);
if (!base || !roomId || !members.length) return false;
const attempts: Array<{ path: string; body: Record<string, unknown> }> = [
{
path: '/api/rooms/add_members',
body: { api_key: apiKey, room_id: roomId, members },
},
{
path: '/api/rooms/members/add',
body: { api_key: apiKey, room_id: roomId, members },
},
{
path: '/api/rooms/members',
body: { api_key: apiKey, room_id: roomId, members, action: 'add' },
},
];
for (const attempt of attempts) {
try {
const { ok, status } = await this.fetchJson(`https://${base}${attempt.path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify(attempt.body),
});
if (ok || status === 204) return true;
if (status === 404 || status === 405) continue;
} catch {
// try next
}
}
return false;
}
async removeRoomMembers(
host: string,
apiKey: string,
roomId: string,
members: string[],
): Promise<boolean> {
const base = this.normalizeHost(host);
if (!base || !roomId || !members.length) return false;
const attempts: Array<{ path: string; body: Record<string, unknown> }> = [
{
path: '/api/rooms/remove_members',
body: { api_key: apiKey, room_id: roomId, members },
},
{
path: '/api/rooms/members/remove',
body: { api_key: apiKey, room_id: roomId, members },
},
{
path: '/api/rooms/members',
body: { api_key: apiKey, room_id: roomId, members, action: 'remove' },
},
];
for (const attempt of attempts) {
try {
const { ok, status } = await this.fetchJson(`https://${base}${attempt.path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify(attempt.body),
});
if (ok || status === 204) return true;
if (status === 404 || status === 405) continue;
} catch {
// try next
}
}
return false;
}
}