-
Notifications
You must be signed in to change notification settings - Fork 3
Add an 'extras' property to comments #807
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
8 commits
Select commit
Hold shift + click to select a range
2e2cdc9
Add an 'extras' property to comments
crazytonyli d685335
Parse additional data in WP.com comments API
crazytonyli 5da4075
Use the new attribute
crazytonyli c0cbafd
Fix WpContextualExcludeFromFields filtering in test helpers
oguzkocer b7f1bc3
Rename the parse_extension function
crazytonyli ada9d88
Move wpcom comments tests
crazytonyli a912680
Breakdown into three test functions for each context
crazytonyli 0a4ab1f
Format code
crazytonyli 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
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
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,42 @@ | ||
use serde::Deserialize; | ||
|
||
use crate::{AnyJson, uniffi_serde::UniffiSerializationError}; | ||
|
||
#[derive(Debug, Deserialize, uniffi::Record)] | ||
pub struct WpComCommentExtension { | ||
#[serde(rename = "extended_post")] | ||
pub post: Option<WpComCommentExtensionPostInfo>, | ||
#[serde(rename = "extended_i_replied")] | ||
pub i_replied: bool, | ||
#[serde(rename = "extended_like_count")] | ||
pub like_count: u32, | ||
#[serde(rename = "extended_i_like")] | ||
pub i_like: bool, | ||
} | ||
|
||
#[derive(Debug, Deserialize, uniffi::Record)] | ||
pub struct WpComCommentExtensionPostInfo { | ||
pub id: u64, | ||
pub title: String, | ||
#[serde(rename = "type")] | ||
pub kind: String, | ||
pub link: String, | ||
} | ||
|
||
#[uniffi::export(with_foreign)] | ||
pub trait WpComCommentExtensionProvider: Send + Sync { | ||
fn parse_wpcom_comments_extension( | ||
&self, | ||
) -> Result<WpComCommentExtension, UniffiSerializationError>; | ||
} | ||
|
||
#[uniffi::export] | ||
impl WpComCommentExtensionProvider for AnyJson { | ||
fn parse_wpcom_comments_extension( | ||
&self, | ||
) -> Result<WpComCommentExtension, UniffiSerializationError> { | ||
serde_json::to_string(&self.raw) | ||
.and_then(|json| serde_json::from_str(&json)) | ||
.map_err(Into::into) | ||
} | ||
} |
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 @@ | ||
pub mod comments; |
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
72 changes: 72 additions & 0 deletions
72
wp_api_integration_tests/tests/test_wp_com_comments_immut.rs
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,72 @@ | ||
use wp_api::{ | ||
comments::{CommentId, CommentRetrieveParams}, | ||
wp_com::endpoint::extensions::comments::WpComCommentExtensionProvider, | ||
}; | ||
|
||
use wp_api_integration_tests::{WpComTestCredentials, api_client_backed_by_wp_com, prelude::*}; | ||
|
||
#[tokio::test] | ||
#[parallel] | ||
#[ignore] | ||
async fn parse_extension_view_context() { | ||
let site_id = WpComTestCredentials::instance().site_id.to_string(); | ||
let comment_id = CommentId(WpComTestCredentials::instance().comment_id); | ||
let client = api_client_backed_by_wp_com(site_id); | ||
|
||
let comment = client | ||
.comments() | ||
.retrieve_with_view_context(&comment_id, &CommentRetrieveParams::default()) | ||
.await | ||
.assert_response() | ||
.data; | ||
assert!( | ||
comment | ||
.additional_fields | ||
.parse_wpcom_comments_extension() | ||
.is_ok() | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
#[parallel] | ||
#[ignore] | ||
async fn parse_extension_edit_context() { | ||
let site_id = WpComTestCredentials::instance().site_id.to_string(); | ||
let comment_id = CommentId(WpComTestCredentials::instance().comment_id); | ||
let client = api_client_backed_by_wp_com(site_id); | ||
|
||
let comment = client | ||
.comments() | ||
.retrieve_with_edit_context(&comment_id, &CommentRetrieveParams::default()) | ||
.await | ||
.assert_response() | ||
.data; | ||
assert!( | ||
comment | ||
.additional_fields | ||
.parse_wpcom_comments_extension() | ||
.is_ok() | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
#[parallel] | ||
#[ignore] | ||
async fn parse_extension_embed_context() { | ||
let site_id = WpComTestCredentials::instance().site_id.to_string(); | ||
let comment_id = CommentId(WpComTestCredentials::instance().comment_id); | ||
let client = api_client_backed_by_wp_com(site_id); | ||
|
||
let comment = client | ||
.comments() | ||
.retrieve_with_embed_context(&comment_id, &CommentRetrieveParams::default()) | ||
.await | ||
.assert_response() | ||
.data; | ||
assert!( | ||
comment | ||
.additional_fields | ||
.parse_wpcom_comments_extension() | ||
.is_ok() | ||
); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is included in the generated
SparseCommentFields
, which it should not be. I guess we'll have to implement a logic to exclude certain fields. We can either check the#[serde(flatten)]
attribute (if that's possible), or add a new attribute like#[WpContextualExcludeFromFields]
. What do you think? @oguzkocerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was checking what needed to be done for this and figured I'd quickly implement it, so you don't have to do the same: #833
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I have got this error using the new attribute, do you mind having a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c0cbafd. (after checking with @crazytonyli that it'd be OK for me to push directly to his branch)