Skip to content

Commit

Permalink
fixed deleteMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Mar 3, 2020
1 parent 81b5381 commit 9d04db8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/api/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare module WAPI {
const onAddedToGroup: (callback: Function) => any;
const onParticipantsChanged: (groupId: string, callback: Function) => any;
const onLiveLocation: (chatId: string, callback: Function) => any;
const sendMessage: (to: string, content: string) => void;
const sendMessage: (to: string, content: string) => string;
const setChatState: (chatState: ChatState, chatId: string) => void;
const reply: (to: string, content: string, quotedMsg: string | Message) => void;
const getGeneratedUserAgent: (userAgent?: string) => string;
Expand Down Expand Up @@ -92,7 +92,7 @@ declare module WAPI {
const getContact: (contactId: string) => Contact;
const checkNumberStatus: (contactId: string) => any;
const getChatById: (contactId: string) => Chat;
const smartDeleteMessages: (contactId: string, messageId: string[] | string) => any;
const smartDeleteMessages: (contactId: string, messageId: string[] | string, onlyLocal:boolean) => any;
const sendContact: (to: string, contact: string | string[]) => any;
const simulateTyping: (to: string, on: boolean) => void;
const isConnected: () => Boolean;
Expand Down Expand Up @@ -788,13 +788,15 @@ public async getStatus(contactId: string) {

/**
* Deletes message of given message id
* @param messageId
* @param contactId 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.
* @returns nothing
*/
public async deleteMessage(contactId: string, messageId: string[] | string) {
public async deleteMessage(contactId: string, messageId: string[] | string, onlyLocal : boolean = false) {
return await this.page.evaluate(
({ contactId, messageId }) => WAPI.smartDeleteMessages(contactId, messageId),
{ contactId, messageId }
({ contactId, messageId, onlyLocal }) => WAPI.smartDeleteMessages(contactId, messageId, onlyLocal),
{ contactId, messageId, onlyLocal }
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ window.WAPI.deleteConversation = function (chatId, done) {
return true;
};

window.WAPI.smartDeleteMessages = function (chatId, messageArray, done) {
window.WAPI.smartDeleteMessages = function (chatId, messageArray, onlyLocal, done) {
var userId = new Store.WidFactory.createWid(chatId);
let conversation = WAPI.getChat(userId);
if (!conversation) {
Expand All @@ -1215,7 +1215,7 @@ window.WAPI.smartDeleteMessages = function (chatId, messageArray, done) {
}

let messagesToDelete = messageArray.map(msgId => (typeof msgId == 'string')?window.Store.Msg.get(msgId):msgId);
let jobs = [
let jobs = onlyLocal ? [conversation.sendDeleteMsgs(messagesToDelete,conversation)] :[
conversation.sendRevokeMsgs(messagesToDelete.filter(msg=>msg.isSentByMe),conversation),
conversation.sendDeleteMsgs(messagesToDelete.filter(msg=>!msg.isSentByMe),conversation)
]
Expand Down

0 comments on commit 9d04db8

Please sign in to comment.