[core] Refresh profile picture

This commit is contained in:
devlikepro committed 2024-12-24 13:33:39 +07:00
1 parent 3ee3355e81
commit c9f7814f5d
3 files changed
+25 -4

No files matched your search

+7 -2
View File
@@ -16,6 +16,7 @@ import {
WANumberExistResult,
} from '../structures/chatting.dto';
import {
ContactProfilePictureQuery,
ContactQuery,
ContactRequest,
ContactsPaginationParams,
@@ -75,9 +76,13 @@ export class ContactsController {
description:
'If privacy settings do not allow to get the picture, the method will return null.',
})
async getProfilePicture(@Query() query: ContactQuery) {
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
async getProfilePicture(@Query() query: ContactProfilePictureQuery) {
const whatsapp = await this.manager.getWorkingSession(query.session);
const url = await whatsapp.getContactProfilePicture(query.contactId, false);
const url = await whatsapp.getContactProfilePicture(
query.contactId,
query.refresh,
);
return { profilePictureURL: url };
}
+2 -1
View File
@@ -1,4 +1,4 @@
import { IsNotEmpty } from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';
export const WHATSAPP_DEFAULT_SESSION_NAME = 'default';
@@ -7,6 +7,7 @@ export const WHATSAPP_DEFAULT_SESSION_NAME = 'default';
*/
export class SessionQuery {
@IsNotEmpty()
@IsString()
session: string = WHATSAPP_DEFAULT_SESSION_NAME;
}
+16 -1
View File
@@ -1,7 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { BooleanString } from '@waha/nestjs/validation/BooleanString';
import { PaginationParams } from '@waha/structures/pagination.dto';
import { ChatIdProperty } from '@waha/structures/properties.dto';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { Transform } from 'class-transformer';
import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator';
import { SessionBaseRequest, SessionQuery } from './base.dto';
@@ -15,6 +17,19 @@ export class ContactQuery extends SessionQuery {
contactId: string;
}
export class ContactProfilePictureQuery extends ContactQuery {
@Transform(BooleanString)
@IsBoolean()
@IsOptional()
@ApiProperty({
example: false,
required: false,
description:
'Refresh the picture from the server (24h cache by default). Do not refresh if not needed, you can get rate limit error',
})
refresh?: boolean = false;
}
enum ContactSortField {
ID = 'id',
NAME = 'name',