forked from danielcardeenas/sulla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.layer.ts
58 lines (53 loc) Β· 1.51 KB
/
controls.layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Page } from 'puppeteer';
import { GroupLayer } from './group.layer';
import { UILayer } from './ui.layer';
declare module WAPI {
const deleteConversation: (chatId: string) => boolean;
const clearChat: (chatId: string) => void;
const deleteMessages: (
contactId: string,
messageId: string[] | string,
onlyLocal: boolean
) => any;
}
export class ControlsLayer extends UILayer {
constructor(page: Page) {
super(page);
}
/**
* Deletes the given chat
* @param chatId
* @returns boolean
*/
public async deleteChat(chatId: string) {
return this.page.evaluate(
(chatId) => WAPI.deleteConversation(chatId),
chatId
);
}
/**
* Deletes all messages of given chat
* @param chatId
* @returns boolean
*/
public async clearChat(chatId: string) {
return this.page.evaluate((chatId) => WAPI.clearChat(chatId), chatId);
}
/**
* Deletes message of given message id
* @param chatId The chat id from which to delete the message.
* @param messageId The specific message id of the message to be deleted
* @param onlyLocal If it should only delete locally (message remains on the other recipienct's phone). Defaults to false.
*/
public async deleteMessage(
chatId: string,
messageId: string[] | string,
onlyLocal = false
) {
return await this.page.evaluate(
({ contactId, messageId, onlyLocal }) =>
WAPI.deleteMessages(contactId, messageId, onlyLocal),
{ contactId: chatId, messageId, onlyLocal }
);
}
}