set last_seen_ip on new/initial device creation

this is not automatically updating, but at least have something
useful there instead of nothing

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-07-25 23:07:54 -04:00
parent 22f8c339fc
commit 57940f38ea
4 changed files with 28 additions and 12 deletions

View file

@ -246,6 +246,7 @@ impl Data {
/// Adds a new device to a user.
pub(super) fn create_device(
&self, user_id: &UserId, device_id: &DeviceId, token: &str, initial_device_display_name: Option<String>,
client_ip: Option<String>,
) -> Result<()> {
// This method should never be called for nonexistent users. We shouldn't assert
// though...
@ -266,7 +267,7 @@ impl Data {
&serde_json::to_vec(&Device {
device_id: device_id.into(),
display_name: initial_device_display_name,
last_seen_ip: None, // TODO
last_seen_ip: client_ip,
last_seen_ts: Some(MilliSecondsSinceUnixEpoch::now()),
})
.expect("Device::to_string never fails."),

View file

@ -328,9 +328,10 @@ impl Service {
/// Adds a new device to a user.
pub fn create_device(
&self, user_id: &UserId, device_id: &DeviceId, token: &str, initial_device_display_name: Option<String>,
client_ip: Option<String>,
) -> Result<()> {
self.db
.create_device(user_id, device_id, token, initial_device_display_name)
.create_device(user_id, device_id, token, initial_device_display_name, client_ip)
}
/// Removes a device from a user.