Skip to content

Commit

Permalink
Merge pull request #59 from Michael-F-Bryan/link-devices
Browse files Browse the repository at this point in the history
Link devices: some extra methods
  • Loading branch information
rubdos committed Jan 23, 2021
2 parents eb87069 + c347460 commit 51d9b5d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libsignal-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ libsignal-protocol = { git = "https://github.com/Michael-F-Bryan/libsignal-proto
async-trait = "0.1.30"
url = { version = "2.1.1", features = ["serde"] }
base64 = "0.13"
chrono = { version = "0.4", features = ["serde"] }
bytes = "0.5"
futures = "0.3"
pin-project = "1.0"
thiserror = "1.0"
serde = {version = "1.0", features=["derive"]}
serde = { version = "1.0", features=["derive"] }
prost = "0.6"
http = "0.2.1"
log = "0.4.8"
Expand Down
27 changes: 27 additions & 0 deletions libsignal-service/src/push_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use aes_gcm::{
Aes256Gcm, NewAead,
};

use chrono::prelude::*;

use libsignal_protocol::{keys::PublicKey, Context, PreKeyBundle};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -76,6 +78,17 @@ pub struct DeviceId {
pub device_id: i32,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeviceInfo {
pub id: i64,
pub name: Option<String>,
#[serde(with = "chrono::serde::ts_milliseconds")]
pub created: DateTime<Utc>,
#[serde(with = "chrono::serde::ts_milliseconds")]
pub last_seen: DateTime<Utc>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfirmDeviceMessage {
Expand Down Expand Up @@ -357,6 +370,20 @@ pub trait PushService {
Ok(VoiceVerificationCodeResponse::CallIssued)
}

/// Fetches a list of all devices tied to the authenticated account.
///
/// This list include the device that sends the request.
async fn devices(&mut self) -> Result<Vec<DeviceInfo>, ServiceError> {
#[derive(serde::Deserialize)]
struct DeviceInfoList {
devices: Vec<DeviceInfo>,
}

let devices: DeviceInfoList = self.get("/v1/devices/").await?;

Ok(devices.devices)
}

async fn confirm_verification_code(
&mut self,
confirm_code: u32,
Expand Down

0 comments on commit 51d9b5d

Please sign in to comment.