Skip to content

Commit

Permalink
feat: Added WPP.conn.setLimit function (#1069)
Browse files Browse the repository at this point in the history
Co-authored-by: Edgard Lorraine Messias <edgardmessias@gmail.com>
  • Loading branch information
vphelipe and edgardmessias committed Apr 28, 2023
1 parent 9708d49 commit 9988fc7
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/chat/functions/prepareLinkPreview.ts
Expand Up @@ -24,6 +24,7 @@ import {
fetchLinkPreview,
findFirstWebLink,
genMinimalLinkPreview,
getABPropConfigValue

Check failure on line 27 in src/chat/functions/prepareLinkPreview.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
} from '../../whatsapp/functions';
import { RawMessage } from '..';

Expand Down Expand Up @@ -105,6 +106,16 @@ export async function prepareLinkPreview<T extends RawMessage>(
}

webpack.onReady(() => {

Check failure on line 109 in src/chat/functions/prepareLinkPreview.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎··`
wrapModuleFunction(getABPropConfigValue, (func, ...args) => {
const [key] = args;
switch (key) {
case "high_quality_link_preview_enabled": return true

Check failure on line 113 in src/chat/functions/prepareLinkPreview.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"high_quality_link_preview_enabled":·return·true` with `'high_quality_link_preview_enabled':⏎········return·true;`
case "link_preview_wait_time": return 1

Check failure on line 114 in src/chat/functions/prepareLinkPreview.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"link_preview_wait_time":·return·1` with `'link_preview_wait_time':⏎········return·1;`
}
return func(...args);
});

Check failure on line 118 in src/chat/functions/prepareLinkPreview.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
wrapModuleFunction(genMinimalLinkPreview, async (func, ...args) => {
const [uri] = args;

Expand Down
1 change: 1 addition & 0 deletions src/conn/functions/index.ts
Expand Up @@ -35,3 +35,4 @@ export { needsUpdate } from './needsUpdate';
export { refreshQR } from './refreshQR';
export { setKeepAlive } from './setKeepAlive';
export { setMultiDevice } from './setMultiDevice';
export { setLimit } from './setLimit';
127 changes: 127 additions & 0 deletions src/conn/functions/setLimit.ts
@@ -0,0 +1,127 @@
/*!
* 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 { wrapModuleFunction } from '../../whatsapp/exportModule';

Check failure on line 17 in src/conn/functions/setLimit.ts

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import { WPPError } from '../../util';
import { ServerProps } from '../../whatsapp';
import { getNumChatsPinned } from '../../whatsapp/functions';
import * as webpack from '../../webpack';

/**
* Change limits
*
* @example
* ```javascript
* //Change the maximum size (bytes) for uploading media (max 70MB)
* WPP.conn.setLimit('maxMediaSize',16777216);
*

Check failure on line 30 in src/conn/functions/setLimit.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* //Change the maximum size (bytes) for uploading files (max 1GB)
* WPP.conn.setLimit('maxFileSize',104857600);
*

Check failure on line 33 in src/conn/functions/setLimit.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* //Change the maximum number of contacts that can be selected when sharing (Default 5)
* WPP.conn.setLimit('maxShare',100);
*

Check failure on line 36 in src/conn/functions/setLimit.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* //Change the maximum time (seconds) of a video status
* WPP.conn.setLimit('statusVideoMaxDuration',120);
*
* //Remove pinned conversation limit (only whatsapp web) (Default 3)
* WPP.conn.setLimit('unlimitedPin',true);
* ```
*/

let unlimitedPin: undefined | boolean = undefined;

webpack.onInjected(() => {

wrapModuleFunction(getNumChatsPinned, (func,...args) => {
const getNumChatsPinnedOriginal = func(...args);
return unlimitedPin ? 1 : getNumChatsPinnedOriginal
});

});

export function setLimit(key: string, value: boolean | number): any {
switch (key) {

case "maxMediaSize": {
if (typeof value !== 'number' || value > 73400320) {
throw new WPPError(
`maxMediaSize_error`,
typeof value !== 'number' ? `Value type invalid!` : `Maximum value is 70MB`
);
}
ServerProps.media = value;
return ServerProps.media;
}

case "maxFileSize": {
if (typeof value !== 'number' || (value > 1073741824)) {
throw new WPPError(
`maxFileSize_error`,
typeof value !== 'number' ? `Value type invalid!`: `Maximum value is 1GB`
);
}
ServerProps.maxFileSize = value
return ServerProps.maxFileSize
}

case "maxShare": {
if (typeof value !== 'number') {
throw new WPPError(
`maxShare_error`,
`Value type invalid!`
);
}
ServerProps.multicastLimitGlobal = value;
ServerProps.frequentlyForwardedMax = value;
ServerProps.frequentlyForwardedThreshold = value;
return ServerProps.multicastLimitGlobal;
}

case "statusVideoMaxDuration": {
if (typeof value !== 'number') {
throw new WPPError(
`statusVideoMaxDuration_error`,
`Value type invalid!`
);
}
ServerProps.statusVideoMaxDuration = value;
return ServerProps.statusVideoMaxDuration;
}

case "unlimitedPin": {
if (typeof value !== 'boolean') {
throw new WPPError(
`unlimitedPin_error`,
`Value type invalid!`
);
}
value ? unlimitedPin = value : unlimitedPin = undefined;
return value
}

default: {
throw new WPPError(
`setLimit_error`,
`Key type invalid!`
);
}

}

}


10 changes: 5 additions & 5 deletions src/util/linkPreview.ts
Expand Up @@ -156,11 +156,11 @@ export async function generateThumbnailLinkPreviewData(url: string) {
const thumbnail = await generateThumbnail(download.data);

// Only display High Quality in link preview for wide images
if (download.width / download.height < 1.4) {
return {
thumbnail,
};
}
// if (download.width / download.height < 1.4) {
// return {
// thumbnail,
// };
// }

const thumbnailHQ = download.data.replace('data:image/jpeg;base64,', '');

Expand Down
33 changes: 33 additions & 0 deletions src/whatsapp/functions/getABPropConfigValue.ts
@@ -0,0 +1,33 @@
/*!
* 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 95547
* @whatsapp 695547 >= 2.2222.8
* @whatsapp 925080 >= 2.2228.4
*/

export declare function getABPropConfigValue(value: any): any;

exportModule(
exports,
{
getABPropConfigValue: 'getABPropConfigValue',
},
(m) => m.getABPropConfigValue
);
32 changes: 32 additions & 0 deletions src/whatsapp/functions/getNumChatsPinned.ts
@@ -0,0 +1,32 @@
/*!
* 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 95547
* @whatsapp 695547 >= 2.2222.8
* @whatsapp 925080 >= 2.2228.4
*/
export declare function getNumChatsPinned(value: any): any;

exportModule(
exports,
{
getNumChatsPinned: 'getNumChatsPinned',
},
(m) => m.getNumChatsPinned
);
2 changes: 2 additions & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -33,6 +33,7 @@ export * from './fetchLinkPreview';
export * from './findChat';
export * from './findFirstWebLink';
export * from './generateVideoThumbsAndDuration';
export * from './getNumChatsPinned';
export * from './genMinimalLinkPreview';
export * from './getCommunityParticipants';
export * from './getFanOutList';
Expand Down Expand Up @@ -90,3 +91,4 @@ export * from './updateParticipants';
export * from './uploadProductImage';
export * from './uploadThumbnail';
export * from './upsertVotes';
export * from './getABPropConfigValue';
31 changes: 31 additions & 0 deletions src/whatsapp/misc/ServerProps.ts
@@ -0,0 +1,31 @@
/*!
* 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';
import { ServerPropsModel } from '../models';

/** @whatsapp 8080
* @whatsapp 608080 >= 2.2222.8
*/
export declare const ServerProps: ServerPropsModel

exportModule(
exports,
{
ServerProps: 'ServerProps',
},
(m) => m.getMaxFilesSizeServerProp && m.ServerProps
);
1 change: 1 addition & 0 deletions src/whatsapp/misc/index.ts
Expand Up @@ -39,3 +39,4 @@ export * from './UserPrefs';
export * from './VCard';
export * from './Wid';
export * from './WidFactory';
export * from './ServerProps';
62 changes: 62 additions & 0 deletions src/whatsapp/models/ServerPropsModel.ts
@@ -0,0 +1,62 @@
/*!
* 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';
import {
Model,
ModelOptions,
ModelPropertiesContructor,
ModelProxy,
} from './Model';

interface Props {
statusVideoMaxDuration: number;
multicastLimitGlobal: number;
frequentlyForwardedThreshold: number;
frequentlyForwardedMax: number;
maxFileSize: number;
media: number;
}

interface Session {
}

interface Derived {
}

/** @whatsapp 17239
* @whatsapp 317239 >= 2.2222.8
*/
export declare interface ServerPropsModel
extends ModelProxy<Props, Session, Derived> {}

/** @whatsapp 17239
* @whatsapp 317239 >= 2.2222.8
*/
export declare class ServerPropsModel extends Model {
constructor(
proterties?: ModelPropertiesContructor<ServerPropsModel>,
options?: ModelOptions
);
}

exportModule(
exports,
{
ServerPropsModel: 'ServerProps',
},
(m) => m.getMaxFilesSizeServerProp && m.ServerProps
);
1 change: 1 addition & 0 deletions src/whatsapp/models/index.ts
Expand Up @@ -67,3 +67,4 @@ export * from './StickerPackModel';
export * from './StreamModel';
export * from './TemplateButtonModel';
export * from './UnreadMentionModel';
export * from './ServerPropsModel';

0 comments on commit 9988fc7

Please sign in to comment.