@@ -104,6 +104,8 @@ pub struct DesktopQueryParams {
104104 pub base : QueryParamsBase ,
105105 pub bid_window : String ,
106106 pub bid_afk : String ,
107+ #[ serde( default ) ]
108+ pub always_active_pattern : Option < String > ,
107109}
108110
109111/// Query parameters specific to Android
@@ -180,11 +182,26 @@ pub fn build_desktop_canonical_events(params: &DesktopQueryParams) -> String {
180182
181183 // Fetch not-afk events
182184 if params. base . filter_afk {
183- query . push ( format ! (
185+ let mut not_afk_query = format ! (
184186 "not_afk = flood(query_bucket(find_bucket(\" {}\" )));
185187not_afk = filter_keyvals(not_afk, \" status\" , [\" not-afk\" ])" ,
186188 escape_doublequote( & params. bid_afk)
187- ) ) ;
189+ ) ;
190+
191+ // Add treat_as_active functionality if pattern is provided
192+ if let Some ( ref pattern) = params. always_active_pattern {
193+ not_afk_query. push_str ( & format ! (
194+ ";
195+ not_treat_as_afk = filter_keyvals_regex(events, \" app\" , \" {}\" );
196+ not_afk = period_union(not_afk, not_treat_as_afk);
197+ not_treat_as_afk = filter_keyvals_regex(events, \" title\" , \" {}\" );
198+ not_afk = period_union(not_afk, not_treat_as_afk)" ,
199+ escape_doublequote( pattern) ,
200+ escape_doublequote( pattern)
201+ ) ) ;
202+ }
203+
204+ query. push ( not_afk_query) ;
188205 }
189206
190207 // Add browser events if any browser buckets specified
@@ -362,6 +379,7 @@ mod tests {
362379 } ,
363380 bid_window : "aw-watcher-window_" . to_string ( ) ,
364381 bid_afk : "aw-watcher-afk_" . to_string ( ) ,
382+ always_active_pattern : None ,
365383 } ;
366384
367385 let query = full_desktop_query ( & params) ;
@@ -414,6 +432,7 @@ mod tests {
414432 } ,
415433 bid_window : "test-window" . to_string ( ) ,
416434 bid_afk : "test-afk" . to_string ( ) ,
435+ always_active_pattern : None ,
417436 } ;
418437
419438 let query_params = QueryParams :: Desktop ( params) ;
@@ -445,6 +464,7 @@ mod tests {
445464 } ,
446465 bid_window : "test-window" . to_string ( ) ,
447466 bid_afk : "test-afk" . to_string ( ) ,
467+ always_active_pattern : None ,
448468 } ;
449469
450470 let query_params = QueryParams :: Desktop ( params) ;
0 commit comments