Skip to content

Commit

Permalink
fix: Fixed compatibility with WhatsApp >= 2.2238.5
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 8, 2022
1 parent 5872e53 commit 28fd5f6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/chat/events/registerLiveLocationUpdateEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import {
ChatStore,
Clock,
LiveLocationStore,
MsgModel,
MsgStore,
Wid,
} from '../../whatsapp';
import { unixTime } from '../../whatsapp/functions';

webpack.onInjected(() => registerLiveLocationUpdateEvent());

Expand All @@ -51,7 +51,7 @@ function processLocation(e: LocationUpdate | LocationDisable) {
if (e.type === 'update') {
internalEv.emit('chat.live_location_update', {
id: e.jid,
lastUpdated: Clock.globalUnixTime() - e.elapsed,
lastUpdated: unixTime() - e.elapsed,
elapsed: e.elapsed,
lat: e.lat,
lng: e.lng,
Expand Down
7 changes: 4 additions & 3 deletions src/chat/functions/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import { assertGetChat, assertWid } from '../../assert';
import { WPPError } from '../../util';
import { Clock, Wid } from '../../whatsapp';
import { Wid } from '../../whatsapp';
import { unixTime } from '../../whatsapp/functions';

/**
* Mute a chat, you can use duration or expiration
Expand Down Expand Up @@ -55,12 +56,12 @@ export async function mute(
expiration = time.expiration.getTime() / 1000;
}
} else if ('duration' in time) {
expiration = Clock.globalUnixTime() + time.duration;
expiration = unixTime() + time.duration;
} else {
throw new WPPError('invalid_time_mute', 'Invalid time for mute', { time });
}

if (expiration < Clock.globalUnixTime()) {
if (expiration < unixTime()) {
throw new WPPError('negative_time_mute', 'Negative duration for mute', {
time,
});
Expand Down
12 changes: 3 additions & 9 deletions src/chat/functions/prepareRawMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
import { assertWid } from '../../assert';
import { getParticipants } from '../../group';
import { WPPError } from '../../util';
import {
ChatModel,
Clock,
MsgKey,
MsgModel,
UserPrefs,
Wid,
} from '../../whatsapp';
import { ChatModel, MsgKey, MsgModel, UserPrefs, Wid } from '../../whatsapp';
import { ACK } from '../../whatsapp/enums';
import { unixTime } from '../../whatsapp/functions';
import { defaultSendMessageOptions, RawMessage, SendMessageOptions } from '..';
import { generateMessageID, getMessageById } from '.';

Expand All @@ -45,7 +39,7 @@ export async function prepareRawMessage<T extends RawMessage>(
};

message = {
t: Clock.globalUnixTime(),
t: unixTime(),
from: UserPrefs.getMaybeMeUser(),
to: chat.id,
self: 'out',
Expand Down
6 changes: 3 additions & 3 deletions src/util/linkPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import Debug from 'debug';

import { config } from '../config';
import { Base64, Clock, OpaqueData } from '../whatsapp';
import { uploadThumbnail } from '../whatsapp/functions';
import { Base64, OpaqueData } from '../whatsapp';
import { unixTime, uploadThumbnail } from '../whatsapp/functions';
import { downloadImage } from './downloadImage';
import { fetchDataFromPNG } from './fetchDataFromPNG';

Expand Down Expand Up @@ -173,7 +173,7 @@ export async function generateThumbnailLinkPreviewData(url: string) {
(window.crypto.getRandomValues(e),
{
key: Base64.encodeB64(e),
timestamp: Clock.globalUnixTime(),
timestamp: unixTime(),
});

const abort = new AbortController();
Expand Down
62 changes: 0 additions & 62 deletions src/whatsapp/misc/Clock.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/whatsapp/misc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
export * from './Base64';
export * from './Browser';
export * from './ChatPresence';
export * from './Clock';
export * from './Cmd';
export * from './Conn';
export * from './Constants';
Expand Down

0 comments on commit 28fd5f6

Please sign in to comment.