Repository navigation
Render templates and related business messages across live traffic and history #256
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd7c3f1
Render templates and related business message content through shared …
jlucaso1 250be34
Expose business card selectors to the native render harness
jlucaso1 ae5d260
Preserve business segment selection and account for retained card con…
jlucaso1 36f4545
Read business mention and quote contexts across wrapped templates
jlucaso1 8a09538
Exercise business selection invalidation in the daemon event context
jlucaso1 503cccf
Integrate main account consolidation into template rendering branch
jlucaso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Synthetic wire-to-durable-row coverage for business cards. | ||
| mod common; | ||
| use common::*; | ||
|
|
||
| #[tokio::test] | ||
| async fn interactive_template_materializes_body_and_preserves_the_card() { | ||
| let (store, chat_store) = test_store().await; | ||
| let mut body = wa::message::interactive_message::Body::default(); | ||
| body.text = Some("*Order* is ready".into()); | ||
| let mut interactive = wa::message::InteractiveMessage::default(); | ||
| interactive.body = MessageField::some(body); | ||
| let mut template = wa::message::TemplateMessage::default(); | ||
| template.format = | ||
| Some(wa::message::template_message::Format::InteractiveMessageTemplate(interactive.into())); | ||
| let mut proto = wa::Message::default(); | ||
| proto.template_message = MessageField::some(template); | ||
| let expected = oxidezap_chat_store::business_content(&proto); | ||
| feed( | ||
| &chat_store, | ||
| [message_event( | ||
| proto, | ||
| incoming_info(PEER, PEER, "TEMPLATE-1", 1_700_000_000), | ||
| )], | ||
| ) | ||
| .await; | ||
| let rows = chat_store.messages(&jid(PEER), None, 10).await.unwrap(); | ||
| assert_eq!(rows[0].kind, MessageKind::Template); | ||
| assert_eq!(rows[0].text.as_deref(), Some("*Order* is ready")); | ||
| assert_eq!( | ||
| rows[0] | ||
| .message | ||
| .as_deref() | ||
| .and_then(oxidezap_chat_store::business_content), | ||
| expected | ||
| ); | ||
| assert_eq!( | ||
| chat_store.chats(false, 10).await.unwrap()[0] | ||
| .last_message_preview | ||
| .as_deref(), | ||
| Some("*Order* is ready") | ||
| ); | ||
| let reopened = ChatStore::new(&store).await.unwrap(); | ||
| let stored = reopened | ||
| .message(&jid(PEER), "TEMPLATE-1") | ||
| .await | ||
| .unwrap() | ||
| .unwrap(); | ||
| assert_eq!( | ||
| stored | ||
| .message | ||
| .as_deref() | ||
| .and_then(oxidezap_chat_store::business_content), | ||
| expected | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| //! Display-only business content. No response IDs, flow JSON, or executable actions. | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct BusinessContent { | ||
| pub kind: BusinessKind, | ||
| pub header: String, | ||
| pub body: String, | ||
| pub footer: String, | ||
| pub buttons: Vec<BusinessButton>, | ||
| /// A readable limitation, never raw protobuf identifiers or payloads. | ||
| pub notice: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum BusinessKind { | ||
| Template, | ||
| Buttons, | ||
| List, | ||
| Interactive, | ||
| Response, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct BusinessButton { | ||
| pub label: String, | ||
| pub action: BusinessAction, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum BusinessAction { | ||
| Reply, | ||
| OpenLink, | ||
| Call, | ||
| NativeFlow, | ||
| Unsupported, | ||
| } | ||
|
|
||
| impl BusinessAction { | ||
| pub fn unavailable_reason(self) -> &'static str { | ||
| match self { | ||
| Self::Reply => "Button replies are not supported by this client.", | ||
| Self::OpenLink => "Opening business button links is not supported by this client.", | ||
| Self::Call => "Calling business button numbers is not supported by this client.", | ||
| Self::NativeFlow => "This interactive action must be completed on your phone.", | ||
| Self::Unsupported => "This button action is not supported by this client.", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl BusinessContent { | ||
| /// Human-readable output for CLI clients which do not draw a business card. | ||
| pub fn summary(&self) -> String { | ||
| let mut lines: Vec<&str> = [&self.header, &self.body, &self.footer] | ||
| .into_iter() | ||
| .map(String::as_str) | ||
| .filter(|s| !s.is_empty()) | ||
| .collect(); | ||
| lines.extend(self.buttons.iter().map(|button| button.label.as_str())); | ||
| lines.extend(self.notice.as_deref()); | ||
| lines.join("\n") | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| #[test] | ||
| fn business_cards_cross_daemon_serialization_and_old_messages_still_decode() { | ||
| let mut message = crate::ChatMessage::new_incoming( | ||
| "synthetic".into(), | ||
| "example@lid".into(), | ||
| "Ready".into(), | ||
| ); | ||
| message.business = Some(BusinessContent { | ||
| kind: BusinessKind::Template, | ||
| header: "Order".into(), | ||
| body: "Ready".into(), | ||
| footer: "Example shop".into(), | ||
| buttons: vec![BusinessButton { | ||
| label: "Thanks".into(), | ||
| action: BusinessAction::Reply, | ||
| }], | ||
| notice: None, | ||
| }); | ||
| let encoded = serde_json::to_value(&message).unwrap(); | ||
| assert_eq!( | ||
| serde_json::from_value::<crate::ChatMessage>(encoded.clone()).unwrap(), | ||
| message | ||
| ); | ||
| let mut old = encoded; | ||
| old.as_object_mut().unwrap().remove("business"); | ||
| assert!( | ||
| serde_json::from_value::<crate::ChatMessage>(old) | ||
| .unwrap() | ||
| .business | ||
| .is_none() | ||
| ); | ||
| message.status = crate::MessageStatus::Failed; | ||
| message.is_from_me = true; | ||
| assert!( | ||
| message.resend().is_none(), | ||
| "a business body must not become a button response or resend" | ||
| ); | ||
| } | ||
| #[test] | ||
| fn accepted_revoke_discards_business_text_and_choices() { | ||
| let mut message = | ||
| crate::ChatMessage::new_outgoing("synthetic".into(), "original body".into()); | ||
| message.business = Some(BusinessContent { | ||
| kind: BusinessKind::Template, | ||
| header: "original header".into(), | ||
| body: "original body".into(), | ||
| footer: "original footer".into(), | ||
| buttons: vec![BusinessButton { | ||
| label: "original choice".into(), | ||
| action: BusinessAction::Reply, | ||
| }], | ||
| notice: None, | ||
| }); | ||
| message.mark_revoked(); | ||
| assert!(message.revoked); | ||
| assert!(message.business.is_none()); | ||
| assert_eq!(message.preview_text(), "[Message deleted]"); | ||
| assert!( | ||
| !serde_json::to_string(&message) | ||
| .unwrap() | ||
| .contains("original") | ||
| ); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.