Repository navigation
feat(scheduling): add scheduled messages with headless delivery - #882
Open
KrAsH-CoD3 wants to merge 7 commits into
Open
KrAsH-CoD3 wants to merge 7 commits into
KrAsH-CoD3 wants to merge 7 commits into
Conversation
- Add a scheduling feature that delivers text, media and stickers at a chosen time from the conversation overflow menu - Send text through WhatsApp's own ActionUser API, walking the class hierarchy to locate the entry point rather than scanning the concrete class only - Fall back to the share intent and View.performClick when the headless API is missing, polling the current activity instead of waiting for a resume event - Persist schedules in a dedicated SQLite store inside WhatsApp's data directory, kept separate from the module's Room schema - Arm exact alarms with AlarmManager and re-arm or fire pending rows when the process starts - Sweep for overdue schedules on activity resume so a schedule survives the process being dead at fire time - Register the alarm receiver at runtime and broadcast implicitly, since an explicit PendingIntent cannot reach a receiver that no manifest declares - Add a Scheduled messages switch under General preferences and a matching settings search entry
- Replace the 22-parameter capture-and-replay path with a direct (Jid, String) send resolved on the class that owns userActionSendTextMessages, so scheduled messages no longer need a prior manual send to seed the parameters - Resolve the handler instance from the captured object, a static self-reference, or a no-arg constructor, and report at startup how many of its injected fields are populated - Retarget both the recipient and the body when replaying a captured call, fixing a bug where a scheduled message could be delivered to whichever chat was open when the capture was taken - Try the (Jid, String) and (?, Jid, String) -> List candidates in order and fall back to the captured template only when both fail - Log the handler's methods, its instance field population, and every captured argument so send failures can be diagnosed from the log alone
- Add a "Scheduled messages" entry to the chat menu that lists every schedule with its time, chat, preview and delivery state, and deletes a tapped row after confirmation - Cancel the pending alarm when a schedule is deleted, so a removed row cannot still fire - Make the PENDING to SENDING transition a single conditional UPDATE so the alarm broadcast and the activity-resume sweep cannot both send the same message - Never register the alarm receiver without RECEIVER_NOT_EXPORTED on API 33 and above, since an exported receiver would let any app force a scheduled message out early - Remove the marker-file self-test trigger and log message bodies by length only, because the capture hook observes every message the user sends - Refuse to arm an alarm when insert returns -1, instead of scheduling an id that can never resolve to a row
- Let a pending schedule be edited from the list, reusing the creation form so validation stays in one place and re-arming the alarm once the trigger time changes - Offer Edit or Delete for pending rows, while sent and failed rows can only be removed from the list - Show the chat's display name on each row, resolving it from the chat title or our own profile name rather than leaving the JID's local part as a bare number - Resolve and store the name when a schedule is created, and re-resolve rows whose stored value is only the JID's local part - Add ScheduledMessageStore.update, which rewrites a row and forces it back to PENDING with any previous error cleared
- Added display name to saved message log for better traceability - Enhanced row label generation to resolve names from contact database - Implemented contactName lookup using WhatsApp contact database - Ensured own chats show profile name, others show contact name if available - Improved fallback to local part of JID when no name is found
- Change ScheduledMessage to use a list of media URIs instead of a single URI - Update database schema and migration to add media_uris column - Modify sending intent to handle single and multiple attachments explicitly - Update media picker to allow multi-select and persist URI permissions for all picked items - Implement attachment preview UI with thumbnails, file name chips, and removal functionality - Increase text input min lines and widen schedule dialogs for better usability - Replace deprecated dialog show calls with a custom wide dialog function - Add localized strings for attachment UI and handling - Ensure backward compatibility by falling back on the original single media URI when no multiple URIs exist
- Implement MediaSender to build and send media attachments directly via WhatsApp's API - Integrate MediaSender into MessageSender to try headless media sending before falling back to UI intent - Pass captions along with attachments both in headless and share-intent routes - Enhance ScheduledMessage preview to include captions for media and sticker kinds - Modify ScheduledMessages registration and firing logic to use explicit data scheme in alarm intents - Improve logging and error handling for media send resolution and failure cases
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.
Summary
Adds scheduled messages to the conversation overflow menu: pick a time, type text, attach files, and the message is delivered later without the app being opened.
Delivery calls WhatsApp's own send APIs from inside its process — text through the text send API, attachments by building the same media message the share screen would have built. Nothing is displayed, so a schedule fires with the app backgrounded and the device locked.
Changes
PendingIntentis distinct, and the receiver'sIntentFilternow declares that scheme. Without it Android matches no receiver and silently drops the broadcast, so schedules only went out on the next activity resume.userActionSendTextMessagesanchor, so it needs no prior manual send to seed parameters.FMessage/FMediapair directly and hands it toUserActionsMediaMessageSending. Resolved entirely by signature shape, never by obfuscated name. The share intent remains only as a fallback.wae_scheduled_messages.db, schema v2) kept apart from the module's Room schema, with an atomic PENDING→SENDING claim so the alarm and the resume sweep cannot both send the same row.setAlarmClockalarm, plus a sweep on activity resume and a catch-up pass at process start.How to Test
the alarm no longer fires.
Notes
Breaking Changes
None. The feature sits behind a preference.