mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
feat(threads): gateway, messages and push thread support (#3250)
This commit is contained in:
1 parent
4e730832c7
commit
5f4295e399
108 files changed
+15857
-176
No files matched your search
@@ -53,6 +53,7 @@ impl Job {
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
enum Audience {
|
||||
Standard,
|
||||
Thread,
|
||||
Ring,
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ impl Audience {
|
||||
fn admits(self, subscription: &Subscription) -> bool {
|
||||
match self {
|
||||
Self::Standard => subscription.platform() != Some(Platform::IosApnsVoip),
|
||||
Self::Thread => Self::Standard.admits(subscription) && subscription.thread_channels,
|
||||
Self::Ring => Self::rings(subscription),
|
||||
}
|
||||
}
|
||||
@@ -377,7 +379,11 @@ async fn run_message_job(
|
||||
&subscriptions,
|
||||
envelopes,
|
||||
deadline,
|
||||
Audience::Standard,
|
||||
if job.is_thread() {
|
||||
Audience::Thread
|
||||
} else {
|
||||
Audience::Standard
|
||||
},
|
||||
)
|
||||
.await;
|
||||
let duration_ms = elapsed_ms(started_ms);
|
||||
@@ -672,3 +678,34 @@ fn reap(result: Result<(), tokio::task::JoinError>) {
|
||||
warn!(error = %error, "push job task failed");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn subscription(platform: &str, thread_channels: bool) -> Subscription {
|
||||
Subscription {
|
||||
subscription_id: "sub".to_owned(),
|
||||
endpoint: "token".to_owned(),
|
||||
p256dh_key: None,
|
||||
auth_key: None,
|
||||
platform: Some(platform.to_owned()),
|
||||
app_id: None,
|
||||
provider_environment: None,
|
||||
thread_channels,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_thread_push_reaches_only_devices_that_registered_the_capability() {
|
||||
assert!(Audience::Thread.admits(&subscription("android_fcm", true)));
|
||||
assert!(!Audience::Thread.admits(&subscription("android_fcm", false)));
|
||||
assert!(!Audience::Thread.admits(&subscription("ios_apns_voip", true)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_standard_push_ignores_the_capability() {
|
||||
assert!(Audience::Standard.admits(&subscription("ios_apns", false)));
|
||||
assert!(Audience::Standard.admits(&subscription("ios_apns", true)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user