Skip to content
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

Add is_remote flag to HistoryVisitInfo #4810

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/places/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ pub struct HistoryVisitInfo {
pub visit_type: VisitTransition,
pub is_hidden: bool,
pub preview_image_url: Option<Url>,
pub is_remote: bool,
}
#[derive(Clone, PartialEq)]
pub struct HistoryVisitInfosWithBound {
Expand Down
1 change: 1 addition & 0 deletions components/places/src/places.udl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ dictionary HistoryVisitInfo {
VisitTransition visit_type;
boolean is_hidden;
Url? preview_image_url;
boolean is_remote;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 uniffi!

};

dictionary HistoryVisitInfosWithBound {
Expand Down
15 changes: 10 additions & 5 deletions components/places/src/storage/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,8 @@ pub fn get_visit_infos(
) -> Result<Vec<HistoryVisitInfo>> {
let allowed_types = exclude_types.complement();
let infos = db.query_rows_and_then_named_cached(
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url,
v.is_local
FROM moz_places h
JOIN moz_historyvisits v
ON h.id = v.place_id
Expand Down Expand Up @@ -1308,7 +1309,8 @@ pub fn get_visit_page(
) -> Result<Vec<HistoryVisitInfo>> {
let allowed_types = exclude_types.complement();
let infos = db.query_rows_and_then_named_cached(
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url,
v.is_local
FROM moz_places h
JOIN moz_historyvisits v
ON h.id = v.place_id
Expand Down Expand Up @@ -1336,7 +1338,8 @@ pub fn get_visit_page_with_bound(
) -> Result<HistoryVisitInfosWithBound> {
let allowed_types = exclude_types.complement();
let infos = db.query_rows_and_then_named_cached(
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url
"SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url,
v.is_local
FROM moz_places h
JOIN moz_historyvisits v
ON h.id = v.place_id
Expand Down Expand Up @@ -2897,7 +2900,7 @@ mod tests {
let now: Timestamp = SystemTime::now().into();
let now_u64 = now.0;
let now_i64 = now.0 as i64;
// (url, when, is_remote, (expected_always, expected_only_local)
// (url, title, when, is_remote, (expected_always, expected_only_local)
let to_add = [
(
"https://www.example.com/0",
Expand All @@ -2910,7 +2913,7 @@ mod tests {
"https://www.example.com/1",
"older 1",
now_u64 - 200_100,
false,
true,
(true, false),
),
(
Expand Down Expand Up @@ -3003,7 +3006,9 @@ mod tests {
.unwrap();
let infos = infos_with_bound.infos;
assert_eq!(infos[0].title.as_ref().unwrap().as_str(), "older 1",);
assert!(infos[0].is_remote); // "older 1" is remote
assert_eq!(infos[1].title.as_ref().unwrap().as_str(), "older 2",);
assert!(!infos[1].is_remote); // "older 2" is local
assert_eq!(infos_with_bound.bound, now_i64 - 200_200,);
assert_eq!(infos_with_bound.offset, 1,);

Expand Down
3 changes: 2 additions & 1 deletion components/places/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn new_page_info(db: &PlacesDb, url: &Url, new_guid: Option<SyncGuid>) -> Result
}

impl HistoryVisitInfo {
pub(crate) fn from_row(row: &rusqlite::Row<'_>) -> Result<Self> {
fn from_row(row: &rusqlite::Row<'_>) -> Result<Self> {
let visit_type = VisitTransition::from_primitive(row.get::<_, u8>("visit_type")?)
// Do we have an existing error we use for this? For now they
// probably don't care too much about VisitTransition, so this
Expand All @@ -203,6 +203,7 @@ impl HistoryVisitInfo {
Some(s) => Some(Url::parse(&s)?),
None => None,
},
is_remote: !row.get("is_local")?,
})
}
}
Expand Down