Skip to content

Commit

Permalink
fix: Fixed constants definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Feb 25, 2022
1 parent 3f641f9 commit 4d7a546
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 440 deletions.
5 changes: 3 additions & 2 deletions src/auth/functions/isIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/

import { Constants, State } from '../../whatsapp';
import { State } from '../../whatsapp';
import { SOCKET_STATE } from '../../whatsapp/enums/SOCKET_STATE';

export function isIdle(): boolean {
return State.state === Constants.SOCKET_STATE.UNPAIRED_IDLE;
return State.state === SOCKET_STATE.UNPAIRED_IDLE;
}
6 changes: 3 additions & 3 deletions src/chat/functions/deleteMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { assertGetChat } from '../../assert';
import { Constants, Wid } from '../../whatsapp';
import { SendMsgResult } from '../../whatsapp/enums';
import { Wid } from '../../whatsapp';
import { MSG_TYPE, SendMsgResult } from '../../whatsapp/enums';
import { getMessageById } from '.';

export interface DeleteMessageReturn {
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function deleteMessage(
let isRevoked = false;
let isDeleted = false;

if (msg.type === Constants.MSG_TYPE.REVOKED) {
if (msg.type === MSG_TYPE.REVOKED) {
// Message is already revoked
sendMsgResult = SendMsgResult.ERROR_UNKNOWN;
isRevoked = true;
Expand Down
4 changes: 2 additions & 2 deletions src/chat/functions/prepareRawMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { WPPError } from '../../util';
import {
ChatModel,
Clock,
Constants,
MsgKey,
MsgModel,
UserPrefs,
Wid,
} from '../../whatsapp';
import { ACK } from '../../whatsapp/enums';
import { defaultSendMessageOptions, RawMessage, SendMessageOptions } from '..';
import { generateMessageID, getMessageById } from '.';

Expand All @@ -50,7 +50,7 @@ export async function prepareRawMessage<T extends RawMessage>(
self: 'out',
isNewMsg: true,
local: true,
ack: Constants.ACK.CLOCK,
ack: ACK.CLOCK,
...message,
};

Expand Down
61 changes: 61 additions & 0 deletions src/whatsapp/enums/ACK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*!
* 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 { exportModule } from '../exportModule';

/** @whatsapp 35470 */
export declare enum ACK {
MD_DOWNGRADE = -7,
INACTIVE = -6,
CONTENT_UNUPLOADABLE = -5,
CONTENT_TOO_BIG = -4,
CONTENT_GONE = -3,
EXPIRED = -2,
FAILED = -1,
CLOCK = 0,
SENT = 1,
RECEIVED = 2,
READ = 3,
PLAYED = 4,
PEER = 5,
}

/** @whatsapp 35470 */
export declare enum EDIT_ATTR {
SENDER_REVOKE = 7,
ADMIN_REVOKE = 8,
}

/** @whatsapp 35470 */
export declare enum ACK_STRING {
SENDER = 'sender',
DELIVERY = 'delivery',
READ = 'read',
PLAYED = 'played',
INACTIVE = 'inactive',
READ_SELF = 'read-self',
PLAYED_SELF = 'played-self',
}

exportModule(
exports,
{
ACK: (m) => m.ACK || m.default.ACK,
EDIT_ATTR: (m) => m.EDIT_ATTR || m.default.EDIT_ATTR,
ACK_STRING: (m) => m.ACK_STRING || m.default.ACK_STRING,
},
(m) => m.ACK || m.default.ACK
);
7 changes: 4 additions & 3 deletions src/whatsapp/enums/GROUP_SETTING_TYPE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

/** @whatsapp 11547 */
/** @whatsapp 12380 */
export declare enum GROUP_SETTING_TYPE {
ANNOUNCEMENT = 'announcement',
RESTRICT = 'restrict',
Expand All @@ -27,7 +27,8 @@ export declare enum GROUP_SETTING_TYPE {
exportModule(
exports,
{
GROUP_SETTING_TYPE: 'default.GROUP_SETTING_TYPE',
GROUP_SETTING_TYPE: (m) =>
m.GROUP_SETTING_TYPE || m.default.GROUP_SETTING_TYPE,
},
(m) => m.default.GROUP_SETTING_TYPE
(m) => m.GROUP_SETTING_TYPE || m.default.GROUP_SETTING_TYPE
);
68 changes: 68 additions & 0 deletions src/whatsapp/enums/MSG_TYPE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*!
* 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 { exportModule } from '../exportModule';

/** @whatsapp 15461 */
export declare enum MSG_TYPE {
NOTIFICATION = 'notification',
NOTIFICATION_TEMPLATE = 'notification_template',
GROUP_NOTIFICATION = 'group_notification',
GP2 = 'gp2',
BROADCAST_NOTIFICATION = 'broadcast_notification',
E2E_NOTIFICATION = 'e2e_notification',
CALL_LOG = 'call_log',
PROTOCOL = 'protocol',
CHAT = 'chat',
LOCATION = 'location',
PAYMENT = 'payment',
VCARD = 'vcard',
CIPHERTEXT = 'ciphertext',
MULTI_VCARD = 'multi_vcard',
REVOKED = 'revoked',
OVERSIZED = 'oversized',
GROUPS_V4_INVITE = 'groups_v4_invite',
HSM = 'hsm',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
IMAGE = 'image',
VIDEO = 'video',
AUDIO = 'audio',
PTT = 'ptt',
STICKER = 'sticker',
DOCUMENT = 'document',
PRODUCT = 'product',
ORDER = 'order',
LIST = 'list',
INTERACTIVE = 'interactive',
LIST_RESPONSE = 'list_response',
BUTTONS_RESPONSE = 'buttons_response',
REACTION = 'reaction',
NATIVE_FLOW = 'native_flow',
UNKNOWN = 'unknown',
}

/** @whatsapp 15461 */
export declare const SYSTEM_MESSAGE_TYPES: string[];

exportModule(
exports,
{
MSG_TYPE: (m) => m.MSG_TYPE || m.default.MSG_TYPE,
SYSTEM_MESSAGE_TYPES: (m) =>
m.SYSTEM_MESSAGE_TYPES || m.default.SYSTEM_MESSAGE_TYPES,
},
(m) => m.MSG_TYPE || m.default.MSG_TYPE
);
58 changes: 58 additions & 0 deletions src/whatsapp/enums/SOCKET_STATE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*!
* 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 { exportModule } from '../exportModule';

/** @whatsapp 62583 */
export declare enum SOCKET_STATE {
OPENING = 'OPENING',
PAIRING = 'PAIRING',
UNPAIRED = 'UNPAIRED',
UNPAIRED_IDLE = 'UNPAIRED_IDLE',
CONNECTED = 'CONNECTED',
TIMEOUT = 'TIMEOUT',
CONFLICT = 'CONFLICT',
UNLAUNCHED = 'UNLAUNCHED',
PROXYBLOCK = 'PROXYBLOCK',
TOS_BLOCK = 'TOS_BLOCK',
SMB_TOS_BLOCK = 'SMB_TOS_BLOCK',
DEPRECATED_VERSION = 'DEPRECATED_VERSION',
}

/** @whatsapp 62583 */
export declare enum SOCKET_STREAM {
DISCONNECTED = 'DISCONNECTED',
SYNCING = 'SYNCING',
RESUMING = 'RESUMING',
CONNECTED = 'CONNECTED',
}

/** @whatsapp 62583 */
export declare enum WATCHED_SOCKET_STATE {
OPEN = 'OPEN',
CLOSED = 'CLOSED',
}

exportModule(
exports,
{
SOCKET_STATE: (m) => m.SOCKET_STATE || m.default.SOCKET_STATE,
SOCKET_STREAM: (m) => m.SOCKET_STREAM || m.default.SOCKET_STREAM,
WATCHED_SOCKET_STATE: (m) =>
m.WATCHED_SOCKET_STATE || m.default.WATCHED_SOCKET_STATE,
},
(m) => m.SOCKET_STATE || m.default.SOCKET_STATE
);
2 changes: 2 additions & 0 deletions src/whatsapp/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

export * from './ACK';
export * from './GROUP_SETTING_TYPE';
export * from './LogoutReason';
export * from './MSG_TYPE';
export * from './OUTWARD_TYPES';
export * from './SendMsgResult';
Loading

0 comments on commit 4d7a546

Please sign in to comment.