Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Block messages from unknown numbers #1071

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Socket/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Boom } from '@hapi/boom'
import NodeCache from 'node-cache'
import { proto } from '../../WAProto'
import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults'
import { ALL_WA_PATCH_NAMES, ChatModification, ChatMutation, LTHashState, MessageUpsertType, PresenceData, SocketConfig, WABusinessHoursConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPatchName, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types'
import { ALL_WA_PATCH_NAMES, ChatModification, ChatMutation, LTHashState, MessageUpsertType, PresenceData, SocketConfig, WABusinessHoursConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPatchName, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types'
import { LabelActionBody } from '../Types/Label'
import { chatModificationToAppPatch, ChatMutationMap, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils'
import { makeMutex } from '../Utils/make-mutex'
import processMessage from '../Utils/process-message'
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary'
import { makeSocket } from './socket'
import { Label, LabelActionBody } from '../Types/Label'

const MAX_SYNC_ATTEMPTS = 2

Expand Down Expand Up @@ -94,6 +94,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
})
}

const updateMessagesPrivacy = async(value: WAPrivacyMessagesValue) => {
await privacyQuery('messages', value)
}

const updateCallPrivacy = async(value: WAPrivacyCallValue) => {
await privacyQuery('calladd', value)
}
Expand Down Expand Up @@ -221,7 +225,7 @@ export const makeChatsSocket = (config: SocketConfig) => {

/** update the profile picture for yourself or a group */
const updateProfilePicture = async(jid: string, content: WAMediaUpload) => {
let targetJid;
let targetJid
if(!jid) {
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
}
Expand Down Expand Up @@ -251,7 +255,7 @@ export const makeChatsSocket = (config: SocketConfig) => {

/** remove the profile picture for yourself or a group */
const removeProfilePicture = async(jid: string) => {
let targetJid;
let targetJid
if(!jid) {
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
}
Expand Down Expand Up @@ -1025,6 +1029,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
updateProfileName,
updateBlockStatus,
updateCallPrivacy,
updateMessagesPrivacy,
updateLastSeenPrivacy,
updateOnlinePrivacy,
updateProfilePicturePrivacy,
Expand Down
2 changes: 2 additions & 0 deletions src/Types/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type WAReadReceiptsValue = 'all' | 'none'

export type WAPrivacyCallValue = 'all' | 'known'

export type WAPrivacyMessagesValue = 'all' | 'contacts'

/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'

Expand Down
Loading