fix: use newsletter media types for channel media downloads#201709
Open
themazim wants to merge 2 commits intowwebjs:mainfrom
Open
fix: use newsletter media types for channel media downloads#201709themazim wants to merge 2 commits intowwebjs:mainfrom
themazim wants to merge 2 commits intowwebjs:mainfrom
Conversation
WhatsApp Web uses separate, unencrypted media types for newsletter/channel content (e.g. "newsletter-image" instead of "image"). The downloadMedia() method was passing the regular msg.type to downloadAndMaybeDecrypt, which caused failures for newsletter messages because: 1. Newsletter media is unencrypted, so mediaKey may be null — but the old code required both directPath and mediaKey for direct downloads. 2. Passing type "image" instead of "newsletter-image" made the download manager select encrypted download entries for unencrypted content. 3. The internal msg.downloadMedia() resolve crashes for newsletter JIDs because getMaybeChat() returns null (not in ChatCollection). Fix by using WA Web's own getMsgMediaType() to compute the correct newsletter-prefixed type, and isMediaCryptoExpectedForMediaType() to determine whether mediaKey is actually required. For unencrypted newsletter media, directPath alone is now sufficient to attempt the download.
662c99a to
27d627b
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WhatsApp Web uses separate, unencrypted media types for newsletter/channel content (e.g.
newsletter-imageinstead ofimage). ThedownloadMedia()method was passing the regularmsg.typetodownloadAndMaybeDecrypt, which caused failures for newsletter messages because:mediaKeymay be null — but the old code required bothdirectPathandmediaKeyfor direct downloads.type: "image"instead oftype: "newsletter-image"made the download manager select encrypted download entries for unencrypted content, resulting in 404 errors or decryption failures.msg.downloadMedia()call crashes for newsletter JIDs becausegetMaybeChat()returns null (newsletter JIDs are not in ChatCollection).Fix
Uses WA Web's own internal functions to handle newsletter media correctly:
WAWebMmsMediaTypes.getMsgMediaType(msg)— computes the correct newsletter-prefixed media type (e.g.newsletter-image,newsletter-video,newsletter-gif)WAWebMediaCryptoEligibilityUtils.isMediaCryptoExpectedForMediaType(mediaType)— determines whethermediaKeyis actually required for the given typeFor unencrypted newsletter media,
directPathalone is now sufficient to attempt the download. The internalmsg.downloadMedia()resolve is skipped for non-chat JIDs (@newsletter,@broadcast) since it cannot resolve these.Behavior changes
getMsgMediaTypereturns the same type asmsg.typefor regular messages, andisMediaCryptoExpectedreturnstrue, preserving the existingdirectPath + mediaKeyrequirementMessageMediaobject — returns still usetype: "image"andmimetype: "image/jpeg", the newsletter-prefixed type is only used internally for the download callRelated Issue(s)
Testing Summary
Test Details
Environment
main)Type of Change
Checklist
npm test).index.d.ts) have been updated if necessary.example.js) / documentation have been updated if applicable.