-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WBOT: UPDATE PRIVACY MODAL --------- Co-authored-by: Claudemir Todo Bom <[email protected]>
- Loading branch information
Showing
10 changed files
with
3,108 additions
and
2,421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Request, Response } from "express"; | ||
import ShowPrivacyService from "../services/PrivacyService/ShowPrivacyService"; | ||
import Whatsapp from "../models/Whatsapp"; | ||
import AppError from "../errors/AppError"; | ||
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService"; | ||
import UpdatePrivacyWhatsapp from "../services/PrivacyService/UpdatePrivacyWhatsapp"; | ||
|
||
interface PrivacyData { | ||
readreceipts?: 'all' | 'none'; | ||
profile?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
status?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
online?: 'all' | 'match_last_seen'; | ||
last?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
groupadd?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
calladd?: 'all' | 'known'; | ||
disappearing?: '86400' | '604800' | '7776000' | '0' | ||
whatsappId?: number; | ||
} | ||
export const show = async (req: Request, res: Response): Promise<Response> => { | ||
const { whatsappId } = req.params; | ||
const { companyId } = req.user; | ||
|
||
const whatsapp: Whatsapp = await ShowWhatsAppService(whatsappId, companyId); | ||
|
||
if(whatsapp) { | ||
const privacy: PrivacyData = await ShowPrivacyService(whatsappId); | ||
return res.status(200).json(privacy); | ||
} | ||
|
||
throw new AppError("ERR_NO_PRIVACY_FOUND", 404); | ||
} | ||
|
||
export const update = async (req: Request, res: Response): Promise<Response> => { | ||
const { whatsappId } = req.params; | ||
const { companyId } = req.user; | ||
|
||
const whatsapp: Whatsapp = await ShowWhatsAppService(whatsappId, companyId); | ||
|
||
if(whatsapp) { | ||
const privacyData: PrivacyData = req.body; | ||
const privacy: PrivacyData = await UpdatePrivacyWhatsapp(whatsapp.id, privacyData, true); | ||
return res.status(200).json(privacy); | ||
} | ||
|
||
throw new AppError("ERR_NO_PRIVACY_FOUND", 404); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import AppError from "../../errors/AppError"; | ||
import { getWbot, Session } from "../../libs/wbot"; | ||
|
||
interface PrivacyData { | ||
readreceipts?: 'all' | 'none'; | ||
profile?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
status?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
online?: 'all' | 'match_last_seen'; | ||
last?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
groupadd?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
calladd?: 'all' | 'known'; | ||
disappearing?: '86400' | '604800' | '7776000' | '0' | ||
whatsappId?: number; | ||
} | ||
|
||
const ShowPrivacyService = async (whatsappId: number | string): Promise<PrivacyData> => { | ||
if(typeof whatsappId === "string"){ | ||
whatsappId = parseInt(whatsappId); | ||
} | ||
const wbot:Session = getWbot(whatsappId); | ||
const privacy: PrivacyData = await wbot.fetchPrivacySettings(true) | ||
|
||
if (!privacy) { | ||
throw new AppError("ERR_NO_PRIVACY_FOUND", 404); | ||
} | ||
|
||
return privacy; | ||
}; | ||
|
||
export default ShowPrivacyService; |
41 changes: 41 additions & 0 deletions
41
backend/src/services/PrivacyService/UpdatePrivacyWhatsapp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getWbot, Session } from "../../libs/wbot"; | ||
import { logger } from "../../utils/logger"; | ||
import ShowPrivacyService from "./ShowPrivacyService"; | ||
|
||
interface Request { | ||
readreceipts?: 'all' | 'none'; | ||
profile?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
status?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
online?: 'all' | 'match_last_seen'; | ||
last?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
groupadd?: 'all' | 'contacts' | 'contact_blacklist' | 'none'; | ||
calladd?: 'all' | 'known'; | ||
disappearing?: '86400' | '604800' | '7776000' | '0' | ||
whatsappId?: number; | ||
} | ||
|
||
const UpdatePrivacyWhatsapp = async (whatsappId: number, privacySettings: Request, update: boolean = false): Promise<Request> => { | ||
try { | ||
const privacy: Request = await ShowPrivacyService(whatsappId); | ||
if(privacy) { | ||
if(update) { | ||
const wbot: Session = getWbot(whatsappId); | ||
privacy.readreceipts !== privacySettings.readreceipts ? wbot.updateReadReceiptsPrivacy(privacySettings.readreceipts) : null; | ||
privacy.profile !== privacySettings.profile ? wbot.updateProfilePicturePrivacy(privacySettings.profile) : null; | ||
privacy.status !== privacySettings.status ? wbot.updateStatusPrivacy(privacySettings.status) : null; | ||
privacy.online !== privacySettings.online ? wbot.updateOnlinePrivacy(privacySettings.online) : null; | ||
privacy.last !== privacySettings.last ? wbot.updateLastSeenPrivacy(privacySettings.last) : null; | ||
privacy.groupadd !== privacySettings.groupadd ? wbot.updateGroupsAddPrivacy(privacySettings.groupadd) : null; | ||
privacy.calladd !== privacySettings.calladd ? wbot.updateCallPrivacy(privacySettings.calladd) : null; | ||
privacy.disappearing !== privacySettings.disappearing ? wbot.updateDefaultDisappearingMode(parseInt(privacySettings.disappearing)) : null; | ||
} | ||
|
||
return privacy; | ||
} else { | ||
return privacy; | ||
} | ||
} catch(err) { | ||
logger.error(err); | ||
} | ||
} | ||
export default UpdatePrivacyWhatsapp; |
Oops, something went wrong.