Skip to content

Commit

Permalink
fix: Fixed setChatState function (fix #188)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 18, 2021
1 parent b83fcbb commit 3351bf7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { convertToMP4GIF } from '../../utils/ffmpeg';
import {
base64MimeType,
downloadFileToBase64,
evaluateAndReturn,
fileToBase64,
stickerSelect,
} from '../helpers';
Expand Down Expand Up @@ -820,7 +821,8 @@ export class SenderLayer extends ListenerLayer {
* @param chatId
*/
public async setChatState(chatId: string, chatState: ChatState) {
return await this.page.evaluate(
return await evaluateAndReturn(
this.page,
({ chatState, chatId }) => {
WAPI.sendChatstate(chatState, chatId);
},
Expand Down
25 changes: 19 additions & 6 deletions src/lib/wapi/functions/send-chat-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@
*/

export async function sendChatstate(state, chatId) {
state = parseInt(state, 10);

const chat = window.Store.Chat.get(chatId);

if (!chat) {
throw {
error: true,
code: 'chat_not_found',
message: 'Chat not found',
};
}

switch (state) {
case '0':
await window.Store.ChatStates.sendChatStateComposing(chatId);
case 0:
window.Store.ChatStates.sendChatStateComposing(chat.id);
break;
case '1':
await window.Store.ChatStates.sendChatStateRecording(chatId);
case 1:
window.Store.ChatStates.sendChatStateRecording(chat.id);
break;
case '2':
await window.Store.ChatStates.sendChatStatePaused(chatId);
case 2:
window.Store.ChatStates.sendChatStatePaused(chat.id);
break;
default:
return false;
}

return true;
}

0 comments on commit 3351bf7

Please sign in to comment.