feat: Update device metadata upon hitting hot endpoints

This commit is contained in:
timedout
2025-12-02 13:38:24 +00:00
parent b3fa4705ef
commit f3115e14ab
7 changed files with 113 additions and 10 deletions
+19 -1
View File
@@ -2,7 +2,10 @@ use std::collections::BTreeMap;
use axum::extract::State;
use conduwuit::{Err, Result, err, matrix::pdu::PduBuilder, utils};
use ruma::{api::client::message::send_message_event, events::MessageLikeEventType};
use ruma::{
MilliSecondsSinceUnixEpoch, api::client::message::send_message_event,
events::MessageLikeEventType,
};
use serde_json::from_str;
use crate::Ruma;
@@ -27,6 +30,21 @@ pub(crate) async fn send_message_event_route(
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
}
if sender_device.is_some() {
// Increment the "device last active" metadata
let device_id = sender_device.clone().unwrap();
let mut device = services
.users
.get_device_metadata(sender_user, device_id)
.await
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
services
.users
.update_device_metadata(sender_user, device_id, &device)
.await?;
}
// Forbid m.room.encrypted if encryption is disabled
if MessageLikeEventType::RoomEncrypted == body.event_type && !services.config.allow_encryption
{