Skip to main content

MessageExt

Trait MessageExt 

Source
pub trait MessageExt {
Show 13 methods // Required methods fn get_base_message(&self) -> &Message; fn into_base_message(self) -> Message; fn is_ephemeral(&self) -> bool; fn is_view_once(&self) -> bool; fn get_caption(&self) -> Option<&str>; fn text_content(&self) -> Option<&str>; fn prepare_for_quote(&self) -> Box<Message>; fn prepare_for_forward(&self) -> Box<Message>; fn set_context_info(&mut self, context: ContextInfo) -> bool; fn get_ephemeral_expiration(&self) -> Option<u32>; fn set_ephemeral_expiration(&mut self, expiration: u32) -> bool; fn is_forwarded(&self) -> bool; fn mentions_any_bot(&self) -> bool;
}
Expand description

Extension trait for wa::Message

Required Methods§

Source

fn get_base_message(&self) -> &Message

Recursively unwraps ephemeral/view-once/document_with_caption/edited wrappers to get the core message.

Source

fn into_base_message(self) -> Message

Consuming version of get_base_message. Moves the innermost message out of wrapper types (device_sent, ephemeral, view_once, etc.) without cloning.

Source

fn is_ephemeral(&self) -> bool

Source

fn is_view_once(&self) -> bool

Covers the legacy view_once_message{_v2,_v2_extension} wrappers (in any nesting order under device_sent/ephemeral) and the inline view_once flag on modern image/video/audio/extended-text payloads.

Source

fn get_caption(&self) -> Option<&str>

Gets the caption for media messages (Image, Video, Document).

Source

fn text_content(&self) -> Option<&str>

Gets the primary text content of a message (from conversation or extendedTextMessage).

Source

fn prepare_for_quote(&self) -> Box<Message>

Prepares a message to be quoted by stripping nested mentions and quote-chain fields.

WhatsApp Web builds a fresh ContextInfo and does not carry over nested mentions.

§Example
use wacore::proto_helpers::MessageExt;

let context_info = wa::ContextInfo {
    stanza_id: Some(message_id.clone()),
    participant: Some(sender_jid.to_string()),
    quoted_message: buffa::MessageField::from_box(original_message.prepare_for_quote()),
    ..Default::default()
};
Source

fn prepare_for_forward(&self) -> Box<Message>

Prepares a copy of this message to be forwarded.

Mirrors WA Web WAWebChatForwardMessage + getMsgForwardingScoreWhenForwarded: strips the reply/quote chain and mentions, sets context_info.is_forwarded, bumps forwarding_score (source score plus 1 if the source was already shown as forwarded, jumping to the 127 frequently-forwarded sentinel at >= 5), and drops message_context_info so the send path mints a fresh message_secret instead of reusing the source’s.

Forwards the message body as-is, so existing media is relayed from the same CDN blob (mediaKey/url are carried over) rather than re-uploaded.

Source

fn set_context_info(&mut self, context: ContextInfo) -> bool

Sets context_info on the first supported message field.

Returns true if context was set, otherwise false.

§Example
use wacore::proto_helpers::MessageExt;

let mut reply = wa::Message {
    image_message: buffa::MessageField::some(wa::message::ImageMessage {
        // ... image data
        ..Default::default()
    }),
    ..Default::default()
};

let context = wa::ContextInfo {
    stanza_id: Some("original-msg-id".to_string()),
    participant: Some("sender@s.whatsapp.net".to_string()),
    quoted_message: buffa::MessageField::from_box(original_msg.prepare_for_quote()),
    ..Default::default()
};

reply.set_context_info(context);
Source

fn get_ephemeral_expiration(&self) -> Option<u32>

Reads context_info.expiration from the first message type that has it.

Source

fn set_ephemeral_expiration(&mut self, expiration: u32) -> bool

Sets context_info.expiration on the first message type found, creating a default context_info if needed. A bare conversation body is promoted to extended_text_message { text, context_info { expiration } } (mirrors WAWebMessageSendUtils). Returns true on success or promotion, false only when no body can carry the timer.

Source

fn is_forwarded(&self) -> bool

context_info.is_forwarded == Some(true) on the first base message that carries a context_info. Mirrors WA Web’s x.isForwarded guard in processRenderableMessages (which skips caching messageSecret for forwarded payloads).

Source

fn mentions_any_bot(&self) -> bool

true if context_info.mentioned_jid on any base message contains a JID whose user-form ends with @bot. Mirrors WA Web’s mentionedJidList.find(jid.isBot()) lookup used to derive invokedBotWid when messageSecret is present.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§