Skip to content

Commit

Permalink
feat: Added WPP.chat.getLastSeen function (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 25, 2022
1 parent 804812e commit 925920d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/chat/functions/getLastSeen.ts
@@ -0,0 +1,41 @@
/*!
* 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 { assertWid } from '../../assert';
import { ChatStore, Wid } from '../../whatsapp';

/**
* Get timestamp of last seen
* @example
* ```javascript
* WPP.chat.getLastSeen('[number]@c.us');
* ```
* @category Chat
*/
export async function getLastSeen(
chatId: string | Wid
): Promise<number | boolean> {
const wid = assertWid(chatId);
const chat = await ChatStore.get(wid);
if (!chat) {
return false;
}
if (!chat.presence.hasData) {
await chat.presence.subscribe();
await new Promise((resolve) => setTimeout(resolve, 100));
}
return chat.presence.chatstate.t || false;
}
1 change: 1 addition & 0 deletions src/chat/functions/index.ts
Expand Up @@ -23,6 +23,7 @@ export { downloadMedia } from './downloadMedia';
export { find } from './find';
export { generateMessageID } from './generateMessageID';
export { get } from './get';
export { getLastSeen } from './getLastSeen';
export { getMessageById } from './getMessageById';
export { getMessages, GetMessagesOptions } from './getMessages';
export { ChatListOptions, list } from './list';
Expand Down

0 comments on commit 925920d

Please sign in to comment.