Adds back boolean for unsubscribe
This commit is contained in:
Родитель
eb949d7e85
Коммит
b9755e3766
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -1,5 +1,17 @@
|
|||
# v115.0 (In progress)
|
||||
|
||||
## Push
|
||||
### ⚠️ Breaking Changes ⚠️
|
||||
- The constructor for the Push Manager has changed. ([#5389](https://github.com/mozilla/application-services/pull/5389))
|
||||
- Push manager now takes only one argument, a Push Configuration object
|
||||
- Push manager no longer takes in the registration_id (token) in construction
|
||||
- Push manager now takes a new `verifyConnectionRateLimiter` parameter in its configuration, it defines the number of seconds between consecutive verify connection requests.
|
||||
- The `update` function no longer returns a boolean, the consumers did not use the return value. ([#5389](https://github.com/mozilla/application-services/pull/5389))
|
||||
- The Error exposed by push is now `PushApiError`, which is reduced to the set of errors the consumer is expected to handle. ([#5389](https://github.com/mozilla/application-services/pull/5389)):
|
||||
- `PushApiError::UAIDNotRecognizedError`: The server lost the client's uaid. The app should call `verify_connection(true)` and notify all consumers of push
|
||||
- `RecordNotFoundError`: The record containing the private key cannot be found. The consumer should call `verify_connection(true)` and notify all consumers of push
|
||||
- `InternalError`: Consumer should report the error, but ignore it
|
||||
|
||||
## Nimbus ⛅️🔬🔭
|
||||
|
||||
### 🦊 What's Changed 🦊
|
||||
|
|
|
@ -155,16 +155,17 @@ impl<Co: Connection, Cr: Cryptography, S: Storage> PushManager<Co, Cr, S> {
|
|||
.transpose()
|
||||
}
|
||||
|
||||
pub fn unsubscribe(&mut self, scope: &str) -> Result<()> {
|
||||
pub fn unsubscribe(&mut self, scope: &str) -> Result<bool> {
|
||||
let (uaid, auth) = self.ensure_auth_pair()?;
|
||||
let record = self.store.get_record_by_scope(scope)?;
|
||||
if let Some(record) = record {
|
||||
self.connection
|
||||
.unsubscribe(&record.channel_id, uaid, auth)?;
|
||||
self.store.delete_record(&record.channel_id)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn unsubscribe_all(&mut self) -> Result<()> {
|
||||
|
|
|
@ -287,7 +287,8 @@ impl PushManager {
|
|||
/// - `channel_id` - Channel ID (UUID) for subscription to remove
|
||||
///
|
||||
/// # Returns
|
||||
/// Returns a boolean indicating if un-subscription was successful
|
||||
/// Returns a boolean. Boolean is False if the subscription was already
|
||||
/// terminated in the past.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an error in the following cases:
|
||||
|
@ -295,7 +296,7 @@ impl PushManager {
|
|||
/// - An error occurred sending an unsubscribe request to the autopush server
|
||||
/// - An error occurred accessing the PushManager's persisted storage
|
||||
#[handle_error(PushError)]
|
||||
pub fn unsubscribe(&self, channel_id: &str) -> ApiResult<()> {
|
||||
pub fn unsubscribe(&self, channel_id: &str) -> ApiResult<bool> {
|
||||
self.internal.lock().unwrap().unsubscribe(channel_id)
|
||||
}
|
||||
|
||||
|
|
|
@ -69,14 +69,15 @@ interface PushManager {
|
|||
// - `scope` - The scope for the channel to remove
|
||||
//
|
||||
// # Returns
|
||||
// Returns a boolean indicating if un-subscription was successful
|
||||
// Returns a boolean. Boolean is False if the subscription was already
|
||||
// terminated in the past.
|
||||
//
|
||||
// # Errors
|
||||
// Returns an error in the following cases:
|
||||
// - An error occurred sending an unsubscribe request to the autopush server
|
||||
// - An error occurred accessing the PushManager's persisted storage
|
||||
[Throws=PushApiError]
|
||||
void unsubscribe([ByRef] string scope);
|
||||
boolean unsubscribe([ByRef] string scope);
|
||||
|
||||
// Unsubscribe all channels for the user
|
||||
//
|
||||
|
|
|
@ -11,15 +11,8 @@ use push::{BridgeType, PushConfiguration, PushManager};
|
|||
* test database under "/tmp". This database should be deleted before
|
||||
* you re-run this test.
|
||||
*
|
||||
* NOTE: if you wish to do a "live" test inside of the kotlin layer,
|
||||
* See `PushTest.kt` and look for "LIVETEST".
|
||||
*/
|
||||
|
||||
fn dummy_uuid() -> String {
|
||||
// Use easily findable "test" UUIDs
|
||||
"deadbeef-ab-dc-ef-abcdef".to_string()
|
||||
}
|
||||
|
||||
fn test_live_server() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
viaduct_reqwest::use_reqwest_backend();
|
||||
|
@ -35,25 +28,23 @@ fn test_live_server() {
|
|||
};
|
||||
|
||||
let pm = PushManager::new(push_config).unwrap();
|
||||
let channel1 = dummy_uuid();
|
||||
let channel2 = dummy_uuid();
|
||||
let scope1 = "scope1";
|
||||
let scope2 = "scope2";
|
||||
|
||||
pm.update("new-token").unwrap();
|
||||
|
||||
println!("Channels: [{}, {}]", channel1, channel2);
|
||||
println!("Scopes: [{}, {}]", scope1, scope2);
|
||||
|
||||
println!("\n == Subscribing channels");
|
||||
let sub1 = pm
|
||||
.subscribe(&channel1, "", &None)
|
||||
.expect("subscribe failed");
|
||||
let sub1 = pm.subscribe(scope1, &None).expect("subscribe failed");
|
||||
|
||||
println!("## Subscription 1: {:?}", sub1);
|
||||
println!("## Info: {:?}", pm.dispatch_info_for_chid(&channel1));
|
||||
let sub2 = pm.subscribe(&channel2, "", &None).unwrap();
|
||||
println!("## Info: {:?}", pm.get_subscription(scope1));
|
||||
let sub2 = pm.subscribe(scope2, &None).unwrap();
|
||||
println!("## Subscription 2: {:?}", sub2);
|
||||
|
||||
println!("\n == Unsubscribing single channel");
|
||||
pm.unsubscribe(&channel1).expect("chid unsub failed");
|
||||
pm.unsubscribe(scope1).expect("chid unsub failed");
|
||||
|
||||
// the list of known channels should come from whatever is
|
||||
// holding the index of channels to recipient applications.
|
||||
|
|
Загрузка…
Ссылка в новой задаче