Skip to content

Commit a12231a

Browse files
committed
fix: Adjusts in settings with options always_online, read_messages and read_status
1 parent 183efd4 commit a12231a

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.4.3 (homolog)
2+
3+
### Fixed
4+
5+
* Adjusts in settings with options always_online, read_messages and read_status
6+
17
# 1.4.2 (2023-07-24 20:52)
28

39
### Fixed

src/validate/validate.schema.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ export const readMessageSchema: JSONSchema7 = {
455455
$id: v4(),
456456
type: 'object',
457457
properties: {
458-
readMessages: {
458+
read_messages: {
459459
type: 'array',
460460
minItems: 1,
461461
uniqueItems: true,
@@ -470,7 +470,7 @@ export const readMessageSchema: JSONSchema7 = {
470470
},
471471
},
472472
},
473-
required: ['readMessages'],
473+
required: ['read_messages'],
474474
};
475475

476476
export const privacySettingsSchema: JSONSchema7 = {
@@ -884,7 +884,22 @@ export const settingsSchema: JSONSchema7 = {
884884
reject_call: { type: 'boolean', enum: [true, false] },
885885
msg_call: { type: 'string' },
886886
groups_ignore: { type: 'boolean', enum: [true, false] },
887-
},
888-
required: ['reject_call'],
889-
...isNotEmpty('reject_call'),
887+
always_online: { type: 'boolean', enum: [true, false] },
888+
read_messages: { type: 'boolean', enum: [true, false] },
889+
read_status: { type: 'boolean', enum: [true, false] },
890+
},
891+
required: [
892+
'reject_call',
893+
'groups_ignore',
894+
'always_online',
895+
'read_messages',
896+
'read_status',
897+
],
898+
...isNotEmpty(
899+
'reject_call',
900+
'groups_ignore',
901+
'always_online',
902+
'read_messages',
903+
'read_status',
904+
),
890905
};

src/whatsapp/dto/chat.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Key {
5959
remoteJid: string;
6060
}
6161
export class ReadMessageDto {
62-
readMessages: Key[];
62+
read_messages: Key[];
6363
}
6464

6565
class LastMessage {

src/whatsapp/dto/settings.dto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ export class SettingsDto {
22
reject_call?: boolean;
33
msg_call?: string;
44
groups_ignore?: boolean;
5+
always_online?: boolean;
6+
read_messages?: boolean;
7+
read_status?: boolean;
58
}

src/whatsapp/models/settings.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ export class SettingsRaw {
66
reject_call?: boolean;
77
msg_call?: string;
88
groups_ignore?: boolean;
9+
always_online?: boolean;
10+
read_messages?: boolean;
11+
read_status?: boolean;
912
}
1013

1114
const settingsSchema = new Schema<SettingsRaw>({
1215
_id: { type: String, _id: true },
1316
reject_call: { type: Boolean, required: true },
1417
msg_call: { type: String, required: true },
1518
groups_ignore: { type: Boolean, required: true },
19+
always_online: { type: Boolean, required: true },
20+
read_messages: { type: Boolean, required: true },
21+
read_status: { type: Boolean, required: true },
1622
});
1723

1824
export const SettingsModel = dbserver?.model(

src/whatsapp/services/whatsapp.service.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ export class WAStartupService {
362362
this.localSettings.groups_ignore = data?.groups_ignore;
363363
this.logger.verbose(`Settings groups_ignore: ${this.localSettings.groups_ignore}`);
364364

365+
this.localSettings.always_online = data?.always_online;
366+
this.logger.verbose(`Settings always_online: ${this.localSettings.always_online}`);
367+
368+
this.localSettings.read_messages = data?.read_messages;
369+
this.logger.verbose(`Settings read_messages: ${this.localSettings.read_messages}`);
370+
371+
this.localSettings.read_status = data?.read_status;
372+
this.logger.verbose(`Settings read_status: ${this.localSettings.read_status}`);
373+
365374
this.logger.verbose('Settings loaded');
366375
}
367376

@@ -371,8 +380,13 @@ export class WAStartupService {
371380
this.logger.verbose(`Settings reject_call: ${data.reject_call}`);
372381
this.logger.verbose(`Settings msg_call: ${data.msg_call}`);
373382
this.logger.verbose(`Settings groups_ignore: ${data.groups_ignore}`);
383+
this.logger.verbose(`Settings always_online: ${data.always_online}`);
384+
this.logger.verbose(`Settings read_messages: ${data.read_messages}`);
385+
this.logger.verbose(`Settings read_status: ${data.read_status}`);
374386
Object.assign(this.localSettings, data);
375387
this.logger.verbose('Settings set');
388+
389+
this.client?.ws?.close();
376390
}
377391

378392
public async findSettings() {
@@ -387,6 +401,9 @@ export class WAStartupService {
387401
this.logger.verbose(`Settings url: ${data.reject_call}`);
388402
this.logger.verbose(`Settings msg_call: ${data.msg_call}`);
389403
this.logger.verbose(`Settings groups_ignore: ${data.groups_ignore}`);
404+
this.logger.verbose(`Settings always_online: ${data.always_online}`);
405+
this.logger.verbose(`Settings read_messages: ${data.read_messages}`);
406+
this.logger.verbose(`Settings read_status: ${data.read_status}`);
390407
return data;
391408
}
392409

@@ -847,6 +864,7 @@ export class WAStartupService {
847864
printQRInTerminal: false,
848865
browser,
849866
version,
867+
markOnlineOnConnect: this.localSettings.always_online,
850868
connectTimeoutMs: 60_000,
851869
qrTimeout: 40_000,
852870
defaultQueryTimeoutMs: undefined,
@@ -1143,6 +1161,14 @@ export class WAStartupService {
11431161
source: getDevice(received.key.id),
11441162
};
11451163

1164+
if (this.localSettings.read_messages && received.key.id !== 'status@broadcast') {
1165+
await this.client.readMessages([received.key]);
1166+
}
1167+
1168+
if (this.localSettings.read_status && received.key.id === 'status@broadcast') {
1169+
await this.client.readMessages([received.key]);
1170+
}
1171+
11461172
this.logger.log(messageRaw);
11471173

11481174
this.logger.verbose('Sending data to webhook in event MESSAGES_UPSERT');
@@ -2400,7 +2426,7 @@ export class WAStartupService {
24002426
this.logger.verbose('Marking message as read');
24012427
try {
24022428
const keys: proto.IMessageKey[] = [];
2403-
data.readMessages.forEach((read) => {
2429+
data.read_messages.forEach((read) => {
24042430
if (isJidGroup(read.remoteJid) || isJidUser(read.remoteJid)) {
24052431
keys.push({
24062432
remoteJid: read.remoteJid,
@@ -2640,7 +2666,6 @@ export class WAStartupService {
26402666
await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd);
26412667
this.logger.verbose('Groups add privacy updated');
26422668

2643-
// reinicia a instancia
26442669
this.client?.ws?.close();
26452670

26462671
return {

src/whatsapp/types/wa.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export declare namespace wa {
6161
reject_call?: boolean;
6262
msg_call?: string;
6363
groups_ignore?: boolean;
64+
always_online?: boolean;
65+
read_messages?: boolean;
66+
read_status?: boolean;
6467
};
6568

6669
export type StateConnection = {

0 commit comments

Comments
 (0)