Skip to content

Commit d642963

Browse files
committed
chore: lint and re-organize
1 parent cc3cd17 commit d642963

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

src/Signal/libsignal.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import type { LIDMapping, SignalAuthState, SignalKeyStoreWithTransaction } from
55
import type { SignalRepositoryWithLIDStore } from '../Types/Signal'
66
import { generateSignalPubKey } from '../Utils'
77
import type { ILogger } from '../Utils/logger'
8-
import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, transferDevice, WAJIDDomains } from '../WABinary'
8+
import {
9+
isHostedLidUser,
10+
isHostedPnUser,
11+
isLidUser,
12+
isPnUser,
13+
jidDecode,
14+
transferDevice,
15+
WAJIDDomains
16+
} from '../WABinary'
917
import type { SenderKeyStore } from './Group/group_cipher'
1018
import { SenderKeyName } from './Group/sender-key-name'
1119
import { SenderKeyRecord } from './Group/sender-key-record'
@@ -223,9 +231,10 @@ export function makeLibSignalRepository(
223231
if (!deviceStr) continue
224232
const deviceNum = parseInt(deviceStr)
225233
let jid = deviceNum === 0 ? `${user}@s.whatsapp.net` : `${user}:${deviceNum}@s.whatsapp.net`
226-
if (deviceNum == 99) {
234+
if (deviceNum === 99) {
227235
jid = `${user}:99@hosted`
228236
}
237+
229238
deviceJids.push(jid)
230239
}
231240
}

src/Signal/lid-mapping.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import { LRUCache } from 'lru-cache'
22
import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types'
33
import type { ILogger } from '../Utils/logger'
4-
import {
5-
isHostedLidUser,
6-
isHostedPnUser,
7-
isLidUser,
8-
isPnUser,
9-
jidDecode,
10-
jidNormalizedUser,
11-
WAJIDDomains
12-
} from '../WABinary'
4+
import { isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser, WAJIDDomains } from '../WABinary'
135

146
export class LIDMappingStore {
157
private readonly mappingCache = new LRUCache<string, string>({

src/Socket/messages-send.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
type FullJid,
4343
getBinaryNodeChild,
4444
getBinaryNodeChildren,
45-
getServerFromDomainType,
4645
isHostedLidUser,
4746
isHostedPnUser,
4847
isJidGroup,
@@ -51,7 +50,6 @@ import {
5150
jidDecode,
5251
jidEncode,
5352
jidNormalizedUser,
54-
type JidServer,
5553
type JidWithDevice,
5654
S_WHATSAPP_NET
5755
} from '../WABinary'
@@ -408,7 +406,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
408406
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
409407
...(
410408
(await signalRepository.lidMapping.getLIDsForPNs(
411-
jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)
409+
jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid))
412410
)) || []
413411
).map(a => a.lid)
414412
]

src/Utils/noise-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const makeNoiseHandler = ({
112112

113113
const certDecoded = decrypt(serverHello!.payload!)
114114

115-
const { intermediate: certIntermediate, leaf } = proto.CertChain.decode(certDecoded)
115+
const { intermediate: certIntermediate /*leaf*/ } = proto.CertChain.decode(certDecoded)
116116
// TODO: handle this leaf stuff
117117
const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
118118

src/Utils/signal.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,27 @@ export const extractDeviceJids = (
143143

144144
for (const userResult of result) {
145145
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
146-
let { user, domainType, server } = jidDecode(id)!
146+
const decoded = jidDecode(id)!,
147+
{ user, server } = decoded
148+
let { domainType } = decoded
147149
const deviceList = devices?.deviceList as DeviceListData[]
148-
if (Array.isArray(deviceList)) {
149-
for (const { id: device, keyIndex, isHosted } of deviceList) {
150-
if (
151-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
152-
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
153-
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
154-
) {
155-
if (isHosted) {
156-
if (domainType === WAJIDDomains.LID) {
157-
domainType = WAJIDDomains.HOSTED_LID
158-
} else {
159-
domainType = WAJIDDomains.HOSTED
160-
}
161-
}
162-
163-
extracted.push({
164-
user,
165-
device,
166-
domainType,
167-
server: getServerFromDomainType(server, domainType)
168-
})
150+
if (!Array.isArray(deviceList)) continue
151+
for (const { id: device, keyIndex, isHosted } of deviceList) {
152+
if (
153+
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
154+
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
155+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
156+
) {
157+
if (isHosted) {
158+
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED
169159
}
160+
161+
extracted.push({
162+
user,
163+
device,
164+
domainType,
165+
server: getServerFromDomainType(server, domainType)
166+
})
170167
}
171168
}
172169
}

0 commit comments

Comments
 (0)