Skip to content

Commit

Permalink
feat: Added WPP.chat.markPlayed function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Aug 13, 2022
1 parent 3762ada commit c21941f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/chat/functions/index.ts
Expand Up @@ -15,6 +15,7 @@
*/

export { archive, unarchive } from './archive';
export { canMarkPlayed } from './canMarkPlayed';
export { canMute } from './canMute';
export { clear } from './clear';
export { delete } from './delete';
Expand All @@ -32,6 +33,7 @@ export { markIsPaused } from './markIsPaused';
export { markIsRead } from './markIsRead';
export { markIsRecording } from './markIsRecording';
export { markIsUnread } from './markIsUnread';
export { markPlayed } from './markPlayed';
export { mute } from './mute';
export { openChatAt } from './openChatAt';
export { openChatBottom } from './openChatBottom';
Expand Down
50 changes: 50 additions & 0 deletions src/chat/functions/markPlayed.ts
@@ -0,0 +1,50 @@
/*!
* Copyright 2022 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 { Stringable } from '../../types';
import { WPPError } from '../../util';
import { MsgKey, MsgModel } from '../../whatsapp';
import { markPlayed as MarkPlayed } from '../../whatsapp/functions';
import { getMessageById } from './getMessageById';

/**
* Mark message as played
*
* @example
* ```javascript
* WPP.chat.markPlayed('[message_id]');
* ```
* @category Message
*/
export async function markPlayed(
messageId: string | MsgKey | MsgModel | Stringable
): Promise<any> {
if (
!(messageId instanceof MsgModel) &&
typeof messageId !== 'string' &&
typeof messageId.toString === 'function'
) {
messageId = messageId.toString();
}

const msg =
messageId instanceof MsgModel
? messageId
: await getMessageById(messageId.toString());

await MarkPlayed(msg);
return await getMessageById(messageId.toString());
}

0 comments on commit c21941f

Please sign in to comment.