1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::types::*;
use serde_derive::*;
use types::Timestamp;
use url::Url;
#[derive(Debug, Serialize, Deserialize)]
pub struct VisitObservation {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub visit_type: Option<VisitTransition>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub is_error: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub is_redirect_source: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub is_permanent_redirect_source: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub at: Option<Timestamp>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub referrer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub is_remote: Option<bool>,
}
impl VisitObservation {
pub fn new(url: Url) -> Self {
VisitObservation {
url: url.into_string(),
title: None,
visit_type: None,
is_error: None,
is_redirect_source: None,
is_permanent_redirect_source: None,
at: None,
referrer: None,
is_remote: None,
}
}
pub fn with_title(mut self, t: impl Into<Option<String>>) -> Self {
self.title = t.into();
self
}
pub fn with_visit_type(mut self, t: impl Into<Option<VisitTransition>>) -> Self {
self.visit_type = t.into();
self
}
pub fn with_is_error(mut self, v: impl Into<Option<bool>>) -> Self {
self.is_error = v.into();
self
}
pub fn with_is_redirect_source(mut self, v: impl Into<Option<bool>>) -> Self {
self.is_redirect_source = v.into();
self
}
pub fn with_is_permanent_redirect_source(mut self, v: impl Into<Option<bool>>) -> Self {
self.is_permanent_redirect_source = v.into();
self
}
pub fn with_at(mut self, v: impl Into<Option<Timestamp>>) -> Self {
self.at = v.into();
self
}
pub fn with_is_remote(mut self, v: impl Into<Option<bool>>) -> Self {
self.is_remote = v.into();
self
}
pub fn with_referrer(mut self, v: impl Into<Option<Url>>) -> Self {
self.referrer = v.into().map(Url::into_string);
self
}
pub fn get_redirect_frecency_boost(&self) -> bool {
self.is_redirect_source.is_some()
&& match self.visit_type {
Some(t) => t != VisitTransition::Typed,
_ => true,
}
}
pub fn get_is_hidden(&self) -> bool {
match self.visit_type {
Some(visit_type) => {
self.is_redirect_source.is_some()
|| visit_type == VisitTransition::FramedLink
|| visit_type == VisitTransition::Embed
}
None => false,
}
}
}