Skip to content

Commit

Permalink
feat: Added WPP.chat.openChatAt, openChatBottom and openChatFromUnrea…
Browse files Browse the repository at this point in the history
…d functions
  • Loading branch information
edgardmessias committed Jan 29, 2022
1 parent 5023dd9 commit 5e33e2d
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/chat/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export { markIsRead } from './markIsRead';
export { markIsRecording } from './markIsRecording';
export { markIsUnread } from './markIsUnread';
export { mute } from './mute';
export { openChatAt } from './openChatAt';
export { openChatBottom } from './openChatBottom';
export { openChatFromUnread } from './openChatFromUnread';
export { LinkPreviewOptions, prepareLinkPreview } from './prepareLinkPreview';
export {
MessageButtonsOptions,
Expand Down
44 changes: 44 additions & 0 deletions src/chat/functions/openChatAt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { assertFindChat, assertWid } from '../../assert';
import { Cmd, Wid } from '../../whatsapp';
import { getMessageById } from '.';

/**
* Open the chat in the WhatsApp interface in a specific message
*
* @example
* ```javascript
* await WPP.chat.openChatAt('<number>@c.us', <message_id>);
* ```
*
* @category Chat
*/
export async function openChatAt(
chatId: string | Wid,
messageId: string
): Promise<boolean> {
const wid = assertWid(chatId);

const chat = await assertFindChat(wid);

const msg = await getMessageById(messageId);

const result = chat.getSearchContext(msg);

return await Cmd.openChatAt(chat, result);
}
36 changes: 36 additions & 0 deletions src/chat/functions/openChatBottom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { assertFindChat, assertWid } from '../../assert';
import { Cmd, Wid } from '../../whatsapp';

/**
* Open the chat in the WhatsApp interface in bottom position
*
* @example
* ```javascript
* await WPP.chat.openChatBottom('<number>@c.us');
* ```
*
* @category Chat
*/
export async function openChatBottom(chatId: string | Wid): Promise<boolean> {
const wid = assertWid(chatId);

const chat = await assertFindChat(wid);

return await Cmd.openChatBottom(chat);
}
38 changes: 38 additions & 0 deletions src/chat/functions/openChatFromUnread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { assertFindChat, assertWid } from '../../assert';
import { Cmd, Wid } from '../../whatsapp';

/**
* Open the chat in the WhatsApp interface from first unread message
*
* @example
* ```javascript
* await WPP.chat.openChatFromUnread('<number>@c.us');
* ```
*
* @category Chat
*/
export async function openChatFromUnread(
chatId: string | Wid
): Promise<boolean> {
const wid = assertWid(chatId);

const chat = await assertFindChat(wid);

return await Cmd.openChatFromUnread(chat);
}
10 changes: 7 additions & 3 deletions src/whatsapp/misc/Cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { ChatModel } from '..';
import { exportModule } from '../exportModule';
import { EventEmitter } from '.';

Expand Down Expand Up @@ -53,9 +54,12 @@ export declare class CmdClass extends EventEmitter {
sendDeleteMsgs(e?: any, t?: any, r?: any, n?: any, i?: any): void;
sendRevokeMsgs(e?: any, t?: any, r?: any, n?: any, i?: any): void;
_openChat(e?: any, t?: any): void;
openChatAt(e?: any, t?: any): void;
openChatFromUnread(e?: any): void;
openChatBottom(e?: any): void;
openChatAt(
chat: ChatModel,
context: ReturnType<ChatModel['getSearchContext']>
): Promise<boolean>;
openChatFromUnread(chat: ChatModel): Promise<boolean>;
openChatBottom(chat: ChatModel): Promise<boolean>;
scrollToPtt(e?: any): void;
_scrollToFocusedMsg(e?: any): void;
_scrollChatToBottom(): void;
Expand Down

0 comments on commit 5e33e2d

Please sign in to comment.