mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 15:04:11 -04:00
refactor!(media): rename MediaRequest to MediaRequestParameters
Because it's not a request we send to the server; it's some of the request parameters.
This commit is contained in:
@@ -8,7 +8,8 @@ use std::{
|
||||
use anyhow::{anyhow, Context as _};
|
||||
use matrix_sdk::{
|
||||
media::{
|
||||
MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequest, MediaThumbnailSettings,
|
||||
MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequestParameters,
|
||||
MediaThumbnailSettings,
|
||||
},
|
||||
oidc::{
|
||||
registrations::{ClientId, OidcRegistrations},
|
||||
@@ -442,7 +443,7 @@ impl Client {
|
||||
.inner
|
||||
.media()
|
||||
.get_media_file(
|
||||
&MediaRequest { source, format: MediaFormat::File },
|
||||
&MediaRequestParameters { source, format: MediaFormat::File },
|
||||
filename,
|
||||
&mime_type,
|
||||
use_cache,
|
||||
@@ -721,7 +722,7 @@ impl Client {
|
||||
Ok(self
|
||||
.inner
|
||||
.media()
|
||||
.get_media_content(&MediaRequest { source, format: MediaFormat::File }, true)
|
||||
.get_media_content(&MediaRequestParameters { source, format: MediaFormat::File }, true)
|
||||
.await?)
|
||||
}
|
||||
|
||||
@@ -738,7 +739,7 @@ impl Client {
|
||||
.inner
|
||||
.media()
|
||||
.get_media_content(
|
||||
&MediaRequest {
|
||||
&MediaRequestParameters {
|
||||
source,
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings::new(
|
||||
Method::Scale,
|
||||
|
||||
@@ -20,7 +20,7 @@ use ruma::{
|
||||
};
|
||||
|
||||
use super::DynEventCacheStore;
|
||||
use crate::media::{MediaFormat, MediaRequest, MediaThumbnailSettings};
|
||||
use crate::media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings};
|
||||
|
||||
/// `EventCacheStore` integration tests.
|
||||
///
|
||||
@@ -41,9 +41,11 @@ pub trait EventCacheStoreIntegrationTests {
|
||||
impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
async fn test_media_content(&self) {
|
||||
let uri = mxc_uri!("mxc://localhost/media");
|
||||
let request_file =
|
||||
MediaRequest { source: MediaSource::Plain(uri.to_owned()), format: MediaFormat::File };
|
||||
let request_thumbnail = MediaRequest {
|
||||
let request_file = MediaRequestParameters {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
let request_thumbnail = MediaRequestParameters {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings::new(
|
||||
Method::Crop,
|
||||
@@ -53,7 +55,7 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
};
|
||||
|
||||
let other_uri = mxc_uri!("mxc://localhost/media-other");
|
||||
let request_other_file = MediaRequest {
|
||||
let request_other_file = MediaRequestParameters {
|
||||
source: MediaSource::Plain(other_uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
@@ -145,8 +147,10 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
|
||||
async fn test_replace_media_key(&self) {
|
||||
let uri = mxc_uri!("mxc://sendqueue.local/tr4n-s4ct-10n1-d");
|
||||
let req =
|
||||
MediaRequest { source: MediaSource::Plain(uri.to_owned()), format: MediaFormat::File };
|
||||
let req = MediaRequestParameters {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
let content = "hello".as_bytes().to_owned();
|
||||
|
||||
@@ -161,7 +165,7 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
|
||||
// Replacing a media request works.
|
||||
let new_uri = mxc_uri!("mxc://matrix.org/tr4n-s4ct-10n1-d");
|
||||
let new_req = MediaRequest {
|
||||
let new_req = MediaRequestParameters {
|
||||
source: MediaSource::Plain(new_uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ use matrix_sdk_common::{
|
||||
use ruma::{MxcUri, OwnedMxcUri};
|
||||
|
||||
use super::{EventCacheStore, EventCacheStoreError, Result};
|
||||
use crate::media::{MediaRequest, UniqueKey as _};
|
||||
use crate::media::{MediaRequestParameters, UniqueKey as _};
|
||||
|
||||
/// In-memory, non-persistent implementation of the `EventCacheStore`.
|
||||
///
|
||||
@@ -66,7 +66,11 @@ impl EventCacheStore for MemoryStore {
|
||||
Ok(try_take_leased_lock(&self.leases, lease_duration_ms, key, holder))
|
||||
}
|
||||
|
||||
async fn add_media_content(&self, request: &MediaRequest, data: Vec<u8>) -> Result<()> {
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
data: Vec<u8>,
|
||||
) -> Result<()> {
|
||||
// Avoid duplication. Let's try to remove it first.
|
||||
self.remove_media_content(request).await?;
|
||||
// Now, let's add it.
|
||||
@@ -77,8 +81,8 @@ impl EventCacheStore for MemoryStore {
|
||||
|
||||
async fn replace_media_key(
|
||||
&self,
|
||||
from: &MediaRequest,
|
||||
to: &MediaRequest,
|
||||
from: &MediaRequestParameters,
|
||||
to: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error> {
|
||||
let expected_key = from.unique_key();
|
||||
|
||||
@@ -91,7 +95,7 @@ impl EventCacheStore for MemoryStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_media_content(&self, request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
async fn get_media_content(&self, request: &MediaRequestParameters) -> Result<Option<Vec<u8>>> {
|
||||
let expected_key = request.unique_key();
|
||||
|
||||
let media = self.media.read().unwrap();
|
||||
@@ -100,7 +104,7 @@ impl EventCacheStore for MemoryStore {
|
||||
}))
|
||||
}
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
|
||||
let expected_key = request.unique_key();
|
||||
|
||||
let mut media = self.media.write().unwrap();
|
||||
|
||||
@@ -19,7 +19,7 @@ use matrix_sdk_common::AsyncTraitDeps;
|
||||
use ruma::MxcUri;
|
||||
|
||||
use super::EventCacheStoreError;
|
||||
use crate::media::MediaRequest;
|
||||
use crate::media::MediaRequestParameters;
|
||||
|
||||
/// An abstract trait that can be used to implement different store backends
|
||||
/// for the event cache of the SDK.
|
||||
@@ -46,7 +46,7 @@ pub trait EventCacheStore: AsyncTraitDeps {
|
||||
/// * `content` - The content of the file.
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
content: Vec<u8>,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
@@ -71,8 +71,8 @@ pub trait EventCacheStore: AsyncTraitDeps {
|
||||
/// * `to` - The new `MediaRequest` of the file.
|
||||
async fn replace_media_key(
|
||||
&self,
|
||||
from: &MediaRequest,
|
||||
to: &MediaRequest,
|
||||
from: &MediaRequestParameters,
|
||||
to: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Get a media file's content out of the media store.
|
||||
@@ -82,7 +82,7 @@ pub trait EventCacheStore: AsyncTraitDeps {
|
||||
/// * `request` - The `MediaRequest` of the file.
|
||||
async fn get_media_content(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
) -> Result<Option<Vec<u8>>, Self::Error>;
|
||||
|
||||
/// Remove a media file's content from the media store.
|
||||
@@ -90,7 +90,10 @@ pub trait EventCacheStore: AsyncTraitDeps {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `request` - The `MediaRequest` of the file.
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<(), Self::Error>;
|
||||
async fn remove_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Remove all the media files' content associated to an `MxcUri` from the
|
||||
/// media store.
|
||||
@@ -127,7 +130,7 @@ impl<T: EventCacheStore> EventCacheStore for EraseEventCacheStoreError<T> {
|
||||
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
content: Vec<u8>,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.0.add_media_content(request, content).await.map_err(Into::into)
|
||||
@@ -135,20 +138,23 @@ impl<T: EventCacheStore> EventCacheStore for EraseEventCacheStoreError<T> {
|
||||
|
||||
async fn replace_media_key(
|
||||
&self,
|
||||
from: &MediaRequest,
|
||||
to: &MediaRequest,
|
||||
from: &MediaRequestParameters,
|
||||
to: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.0.replace_media_key(from, to).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn get_media_content(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
) -> Result<Option<Vec<u8>>, Self::Error> {
|
||||
self.0.get_media_content(request).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<(), Self::Error> {
|
||||
async fn remove_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.0.remove_media_content(request).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,11 @@ impl UniqueKey for MediaSource {
|
||||
}
|
||||
}
|
||||
|
||||
/// A request for media data.
|
||||
/// Parameters for a request for retrieve media data.
|
||||
///
|
||||
/// This is used as a key in the media cache too.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct MediaRequest {
|
||||
pub struct MediaRequestParameters {
|
||||
/// The source of the media file.
|
||||
pub source: MediaSource,
|
||||
|
||||
@@ -107,7 +109,7 @@ pub struct MediaRequest {
|
||||
pub format: MediaFormat,
|
||||
}
|
||||
|
||||
impl MediaRequest {
|
||||
impl MediaRequestParameters {
|
||||
/// Get the [`MxcUri`] from `Self`.
|
||||
pub fn uri(&self) -> &MxcUri {
|
||||
match &self.source {
|
||||
@@ -117,7 +119,7 @@ impl MediaRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl UniqueKey for MediaRequest {
|
||||
impl UniqueKey for MediaRequestParameters {
|
||||
fn unique_key(&self) -> String {
|
||||
format!("{}{UNIQUE_SEPARATOR}{}", self.source.unique_key(), self.format.unique_key())
|
||||
}
|
||||
@@ -213,14 +215,14 @@ mod tests {
|
||||
fn test_media_request_url() {
|
||||
let mxc_uri = mxc_uri!("mxc://homeserver/media");
|
||||
|
||||
let plain = MediaRequest {
|
||||
let plain = MediaRequestParameters {
|
||||
source: MediaSource::Plain(mxc_uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
assert_eq!(plain.uri(), mxc_uri);
|
||||
|
||||
let file = MediaRequest {
|
||||
let file = MediaRequestParameters {
|
||||
source: MediaSource::Encrypted(Box::new(
|
||||
serde_json::from_value(json!({
|
||||
"url": mxc_uri,
|
||||
|
||||
@@ -27,7 +27,7 @@ use ruma::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::media::MediaRequest;
|
||||
use crate::media::MediaRequestParameters;
|
||||
|
||||
/// A thin wrapper to serialize a `AnyMessageLikeEventContent`.
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
@@ -95,7 +95,7 @@ pub enum QueuedRequestKind {
|
||||
|
||||
/// The cache key used to retrieve the media's bytes in the event cache
|
||||
/// store.
|
||||
cache_key: MediaRequest,
|
||||
cache_key: MediaRequestParameters,
|
||||
|
||||
/// An optional media source for a thumbnail already uploaded.
|
||||
thumbnail_source: Option<MediaSource>,
|
||||
@@ -216,7 +216,7 @@ pub enum DependentQueuedRequestKind {
|
||||
|
||||
/// Media request necessary to retrieve the file itself (not the
|
||||
/// thumbnail).
|
||||
cache_key: MediaRequest,
|
||||
cache_key: MediaRequestParameters,
|
||||
|
||||
/// To which media transaction id does this upload relate to?
|
||||
related_to: OwnedTransactionId,
|
||||
|
||||
@@ -4,7 +4,7 @@ use async_trait::async_trait;
|
||||
use deadpool_sqlite::{Object as SqliteAsyncConn, Pool as SqlitePool, Runtime};
|
||||
use matrix_sdk_base::{
|
||||
event_cache_store::EventCacheStore,
|
||||
media::{MediaRequest, UniqueKey},
|
||||
media::{MediaRequestParameters, UniqueKey},
|
||||
};
|
||||
use matrix_sdk_store_encryption::StoreCipher;
|
||||
use ruma::MilliSecondsSinceUnixEpoch;
|
||||
@@ -182,7 +182,11 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
Ok(num_touched == 1)
|
||||
}
|
||||
|
||||
async fn add_media_content(&self, request: &MediaRequest, content: Vec<u8>) -> Result<()> {
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
content: Vec<u8>,
|
||||
) -> Result<()> {
|
||||
let uri = self.encode_key(keys::MEDIA, request.source.unique_key());
|
||||
let format = self.encode_key(keys::MEDIA, request.format.unique_key());
|
||||
let data = self.encode_value(content)?;
|
||||
@@ -199,8 +203,8 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
|
||||
async fn replace_media_key(
|
||||
&self,
|
||||
from: &MediaRequest,
|
||||
to: &MediaRequest,
|
||||
from: &MediaRequestParameters,
|
||||
to: &MediaRequestParameters,
|
||||
) -> Result<(), Self::Error> {
|
||||
let prev_uri = self.encode_key(keys::MEDIA, from.source.unique_key());
|
||||
let prev_format = self.encode_key(keys::MEDIA, from.format.unique_key());
|
||||
@@ -219,7 +223,7 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_media_content(&self, request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
async fn get_media_content(&self, request: &MediaRequestParameters) -> Result<Option<Vec<u8>>> {
|
||||
let uri = self.encode_key(keys::MEDIA, request.source.unique_key());
|
||||
let format = self.encode_key(keys::MEDIA, request.format.unique_key());
|
||||
|
||||
@@ -247,7 +251,7 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
data.map(|v| self.decode_value(&v).map(Into::into)).transpose()
|
||||
}
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
|
||||
let uri = self.encode_key(keys::MEDIA, request.source.unique_key());
|
||||
let format = self.encode_key(keys::MEDIA, request.format.unique_key());
|
||||
|
||||
@@ -277,7 +281,7 @@ mod tests {
|
||||
use matrix_sdk_base::{
|
||||
event_cache_store::{EventCacheStore, EventCacheStoreError},
|
||||
event_cache_store_integration_tests, event_cache_store_integration_tests_time,
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSettings},
|
||||
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
|
||||
};
|
||||
use matrix_sdk_test::async_test;
|
||||
use once_cell::sync::Lazy;
|
||||
@@ -318,9 +322,11 @@ mod tests {
|
||||
async fn test_last_access() {
|
||||
let event_cache_store = get_event_cache_store().await.expect("creating media cache failed");
|
||||
let uri = mxc_uri!("mxc://localhost/media");
|
||||
let file_request =
|
||||
MediaRequest { source: MediaSource::Plain(uri.to_owned()), format: MediaFormat::File };
|
||||
let thumbnail_request = MediaRequest {
|
||||
let file_request = MediaRequestParameters {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
let thumbnail_request = MediaRequestParameters {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings::new(
|
||||
Method::Crop,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use matrix_sdk_base::{
|
||||
media::{MediaFormat, MediaRequest},
|
||||
media::{MediaFormat, MediaRequestParameters},
|
||||
store::StateStoreExt,
|
||||
StateStoreDataKey, StateStoreDataValue,
|
||||
};
|
||||
@@ -217,7 +217,7 @@ impl Account {
|
||||
/// ```
|
||||
pub async fn get_avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.get_avatar_url().await? {
|
||||
let request = MediaRequest { source: MediaSource::Plain(url), format };
|
||||
let request = MediaRequestParameters { source: MediaSource::Plain(url), format };
|
||||
Ok(Some(self.client.media().get_media_content(&request, true).await?))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
@@ -296,7 +296,7 @@ impl Media {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn get_media_file(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
filename: Option<String>,
|
||||
content_type: &Mime,
|
||||
use_cache: bool,
|
||||
@@ -371,7 +371,7 @@ impl Media {
|
||||
/// * `use_cache` - If we should use the media cache for this request.
|
||||
pub async fn get_media_content(
|
||||
&self,
|
||||
request: &MediaRequest,
|
||||
request: &MediaRequestParameters,
|
||||
use_cache: bool,
|
||||
) -> Result<Vec<u8>> {
|
||||
// Read from the cache.
|
||||
@@ -494,7 +494,7 @@ impl Media {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `request` - The `MediaRequest` of the content.
|
||||
pub async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
pub async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
|
||||
Ok(self.client.event_cache_store().lock().await?.remove_media_content(request).await?)
|
||||
}
|
||||
|
||||
@@ -530,7 +530,10 @@ impl Media {
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
let Some(source) = event_content.source() else { return Ok(None) };
|
||||
let file = self
|
||||
.get_media_content(&MediaRequest { source, format: MediaFormat::File }, use_cache)
|
||||
.get_media_content(
|
||||
&MediaRequestParameters { source, format: MediaFormat::File },
|
||||
use_cache,
|
||||
)
|
||||
.await?;
|
||||
Ok(Some(file))
|
||||
}
|
||||
@@ -545,7 +548,11 @@ impl Media {
|
||||
/// * `event_content` - The media event content.
|
||||
pub async fn remove_file(&self, event_content: &impl MediaEventContent) -> Result<()> {
|
||||
if let Some(source) = event_content.source() {
|
||||
self.remove_media_content(&MediaRequest { source, format: MediaFormat::File }).await?;
|
||||
self.remove_media_content(&MediaRequestParameters {
|
||||
source,
|
||||
format: MediaFormat::File,
|
||||
})
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -578,7 +585,7 @@ impl Media {
|
||||
let Some(source) = event_content.thumbnail_source() else { return Ok(None) };
|
||||
let thumbnail = self
|
||||
.get_media_content(
|
||||
&MediaRequest { source, format: MediaFormat::Thumbnail(settings) },
|
||||
&MediaRequestParameters { source, format: MediaFormat::Thumbnail(settings) },
|
||||
use_cache,
|
||||
)
|
||||
.await?;
|
||||
@@ -602,7 +609,7 @@ impl Media {
|
||||
settings: MediaThumbnailSettings,
|
||||
) -> Result<()> {
|
||||
if let Some(source) = event_content.source() {
|
||||
self.remove_media_content(&MediaRequest {
|
||||
self.remove_media_content(&MediaRequestParameters {
|
||||
source,
|
||||
format: MediaFormat::Thumbnail(settings),
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::ops::Deref;
|
||||
use ruma::events::room::MediaSource;
|
||||
|
||||
use crate::{
|
||||
media::{MediaFormat, MediaRequest},
|
||||
media::{MediaFormat, MediaRequestParameters},
|
||||
BaseRoomMember, Client, Result,
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ impl RoomMember {
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
let Some(url) = self.avatar_url() else { return Ok(None) };
|
||||
let request = MediaRequest { source: MediaSource::Plain(url.to_owned()), format };
|
||||
let request = MediaRequestParameters { source: MediaSource::Plain(url.to_owned()), format };
|
||||
Ok(Some(self.client.media().get_media_content(&request, true).await?))
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ use crate::{
|
||||
error::{BeaconError, WrongRoomState},
|
||||
event_cache::{self, EventCacheDropHandles, RoomEventCache},
|
||||
event_handler::{EventHandler, EventHandlerDropGuard, EventHandlerHandle, SyncEvent},
|
||||
media::{MediaFormat, MediaRequest},
|
||||
media::{MediaFormat, MediaRequestParameters},
|
||||
notification_settings::{IsEncrypted, IsOneToOne, RoomNotificationMode},
|
||||
room::power_levels::{RoomPowerLevelChanges, RoomPowerLevelsExt},
|
||||
sync::RoomUpdate,
|
||||
@@ -264,7 +264,7 @@ impl Room {
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
let Some(url) = self.avatar_url() else { return Ok(None) };
|
||||
let request = MediaRequest { source: MediaSource::Plain(url.to_owned()), format };
|
||||
let request = MediaRequestParameters { source: MediaSource::Plain(url.to_owned()), format };
|
||||
Ok(Some(self.client.media().get_media_content(&request, true).await?))
|
||||
}
|
||||
|
||||
@@ -1994,7 +1994,8 @@ impl Room {
|
||||
// properly, so only log errors during caching.
|
||||
|
||||
debug!("caching the media");
|
||||
let request = MediaRequest { source: media_source.clone(), format: MediaFormat::File };
|
||||
let request =
|
||||
MediaRequestParameters { source: media_source.clone(), format: MediaFormat::File };
|
||||
|
||||
if let Err(err) = cache_store_lock_guard.add_media_content(&request, data).await {
|
||||
warn!("unable to cache the media after uploading it: {err}");
|
||||
@@ -2007,7 +2008,7 @@ impl Room {
|
||||
|
||||
// Do a best guess at figuring the media request: not animated, cropped
|
||||
// thumbnail of the original size.
|
||||
let request = MediaRequest {
|
||||
let request = MediaRequestParameters {
|
||||
source: source.clone(),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings {
|
||||
method: ruma::media::Method::Scale,
|
||||
|
||||
@@ -140,7 +140,7 @@ use std::{
|
||||
use as_variant::as_variant;
|
||||
use matrix_sdk_base::{
|
||||
event_cache_store::EventCacheStoreError,
|
||||
media::MediaRequest,
|
||||
media::MediaRequestParameters,
|
||||
store::{
|
||||
ChildTransactionId, DependentQueuedRequest, DependentQueuedRequestKind,
|
||||
FinishUploadThumbnailInfo, QueueWedgeError, QueuedRequest, QueuedRequestKind,
|
||||
@@ -1034,8 +1034,8 @@ impl QueueStorage {
|
||||
content_type: Mime,
|
||||
send_event_txn: OwnedTransactionId,
|
||||
upload_file_txn: OwnedTransactionId,
|
||||
file_media_request: MediaRequest,
|
||||
thumbnail: Option<(FinishUploadThumbnailInfo, MediaRequest, Mime)>,
|
||||
file_media_request: MediaRequestParameters,
|
||||
thumbnail: Option<(FinishUploadThumbnailInfo, MediaRequestParameters, Mime)>,
|
||||
) -> Result<(), RoomSendQueueStorageError> {
|
||||
// Keep the lock until we're done touching the storage.
|
||||
// TODO refactor to make the relationship between being_sent and the store more
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//! Private implementations of the media upload mechanism.
|
||||
|
||||
use matrix_sdk_base::{
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSettings},
|
||||
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
|
||||
store::{
|
||||
ChildTransactionId, FinishUploadThumbnailInfo, QueuedRequestKind, SentMediaInfo,
|
||||
SentRequestKey, SerializableEventContent,
|
||||
@@ -47,7 +47,7 @@ use crate::{
|
||||
/// sending it.
|
||||
///
|
||||
/// This uses a MXC ID that is only locally valid.
|
||||
fn make_local_file_media_request(txn_id: &TransactionId) -> MediaRequest {
|
||||
fn make_local_file_media_request(txn_id: &TransactionId) -> MediaRequestParameters {
|
||||
// This mustn't represent a potentially valid media server, otherwise it'd be
|
||||
// possible for an attacker to return malicious content under some
|
||||
// preconditions (e.g. the cache store has been cleared before the upload
|
||||
@@ -55,7 +55,7 @@ fn make_local_file_media_request(txn_id: &TransactionId) -> MediaRequest {
|
||||
// which is guaranteed to be on the local machine. As a result, the only attack
|
||||
// possible would be coming from the user themselves, which we consider a
|
||||
// non-threat.
|
||||
MediaRequest {
|
||||
MediaRequestParameters {
|
||||
source: MediaSource::Plain(OwnedMxcUri::from(format!(
|
||||
"mxc://send-queue.localhost/{txn_id}"
|
||||
))),
|
||||
@@ -71,7 +71,7 @@ fn make_local_thumbnail_media_request(
|
||||
txn_id: &TransactionId,
|
||||
height: UInt,
|
||||
width: UInt,
|
||||
) -> MediaRequest {
|
||||
) -> MediaRequestParameters {
|
||||
// See comment in [`make_local_file_media_request`].
|
||||
let source =
|
||||
MediaSource::Plain(OwnedMxcUri::from(format!("mxc://send-queue.localhost/{}", txn_id)));
|
||||
@@ -81,7 +81,7 @@ fn make_local_thumbnail_media_request(
|
||||
height,
|
||||
animated: false,
|
||||
});
|
||||
MediaRequest { source, format }
|
||||
MediaRequestParameters { source, format }
|
||||
}
|
||||
|
||||
/// Replace the source by the final ones in all the media types handled by
|
||||
@@ -300,7 +300,10 @@ impl QueueStorage {
|
||||
.event_cache_store()
|
||||
.replace_media_key(
|
||||
&from_req,
|
||||
&MediaRequest { source: sent_media.file.clone(), format: MediaFormat::File },
|
||||
&MediaRequestParameters {
|
||||
source: sent_media.file.clone(),
|
||||
format: MediaFormat::File,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(RoomSendQueueStorageError::EventCacheStoreError)?;
|
||||
@@ -321,7 +324,7 @@ impl QueueStorage {
|
||||
.event_cache_store()
|
||||
.replace_media_key(
|
||||
&from_req,
|
||||
&MediaRequest { source: new_source, format: new_format },
|
||||
&MediaRequestParameters { source: new_source, format: new_format },
|
||||
)
|
||||
.await
|
||||
.map_err(RoomSendQueueStorageError::EventCacheStoreError)?;
|
||||
@@ -358,7 +361,7 @@ impl QueueStorage {
|
||||
next_upload_txn: OwnedTransactionId,
|
||||
parent_key: SentRequestKey,
|
||||
content_type: String,
|
||||
cache_key: MediaRequest,
|
||||
cache_key: MediaRequestParameters,
|
||||
event_txn: OwnedTransactionId,
|
||||
) -> Result<(), RoomSendQueueError> {
|
||||
// The thumbnail has been sent, now transform the dependent file upload request
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use matrix_sdk::{
|
||||
config::RequestConfig,
|
||||
matrix_auth::{MatrixSession, MatrixSessionTokens},
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSettings},
|
||||
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
|
||||
test_utils::logged_in_client_with_server,
|
||||
Client, SessionMeta,
|
||||
};
|
||||
@@ -35,7 +35,7 @@ async fn test_get_media_content_no_auth() {
|
||||
|
||||
let media = client.media();
|
||||
|
||||
let request = MediaRequest {
|
||||
let request = MediaRequestParameters {
|
||||
source: MediaSource::Plain(mxc_uri!("mxc://localhost/textfile").to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ use matrix_sdk::{
|
||||
Thumbnail,
|
||||
},
|
||||
config::SyncSettings,
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSettings},
|
||||
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
|
||||
test_utils::logged_in_client_with_server,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, mocks::mock_encryption_state, test_json, DEFAULT_TEST_ROOM_ID};
|
||||
@@ -245,8 +245,8 @@ async fn test_room_attachment_send_info_thumbnail() {
|
||||
|
||||
// Preconditions: nothing is found in the cache.
|
||||
let media_request =
|
||||
MediaRequest { source: MediaSource::Plain(media_mxc), format: MediaFormat::File };
|
||||
let thumbnail_request = MediaRequest {
|
||||
MediaRequestParameters { source: MediaSource::Plain(media_mxc), format: MediaFormat::File };
|
||||
let thumbnail_request = MediaRequestParameters {
|
||||
source: MediaSource::Plain(thumbnail_mxc.clone()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings {
|
||||
method: ruma::media::Method::Scale,
|
||||
@@ -297,7 +297,7 @@ async fn test_room_attachment_send_info_thumbnail() {
|
||||
let _ = client
|
||||
.media()
|
||||
.get_media_content(
|
||||
&MediaRequest {
|
||||
&MediaRequestParameters {
|
||||
source: MediaSource::Plain(thumbnail_mxc.clone()),
|
||||
format: MediaFormat::File,
|
||||
},
|
||||
@@ -307,7 +307,7 @@ async fn test_room_attachment_send_info_thumbnail() {
|
||||
.unwrap_err();
|
||||
|
||||
// But it is not found when requesting it as a thumbnail with a different size.
|
||||
let thumbnail_request = MediaRequest {
|
||||
let thumbnail_request = MediaRequestParameters {
|
||||
source: MediaSource::Plain(thumbnail_mxc),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSettings {
|
||||
method: ruma::media::Method::Scale,
|
||||
|
||||
@@ -11,7 +11,7 @@ use assert_matches2::{assert_let, assert_matches};
|
||||
use matrix_sdk::{
|
||||
attachment::{AttachmentConfig, AttachmentInfo, BaseImageInfo, BaseThumbnailInfo, Thumbnail},
|
||||
config::{RequestConfig, StoreConfig},
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSettings},
|
||||
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
|
||||
send_queue::{
|
||||
LocalEcho, LocalEchoContent, RoomSendQueueError, RoomSendQueueStorageError,
|
||||
RoomSendQueueUpdate,
|
||||
@@ -2122,7 +2122,10 @@ async fn test_media_uploads() {
|
||||
// The media is immediately available from the cache.
|
||||
let file_media = client
|
||||
.media()
|
||||
.get_media_content(&MediaRequest { source: local_source, format: MediaFormat::File }, true)
|
||||
.get_media_content(
|
||||
&MediaRequestParameters { source: local_source, format: MediaFormat::File },
|
||||
true,
|
||||
)
|
||||
.await
|
||||
.expect("media should be found");
|
||||
assert_eq!(file_media, b"hello world");
|
||||
@@ -2145,7 +2148,7 @@ async fn test_media_uploads() {
|
||||
let thumbnail_media = client
|
||||
.media()
|
||||
.get_media_content(
|
||||
&MediaRequest {
|
||||
&MediaRequestParameters {
|
||||
source: local_thumbnail_source,
|
||||
// TODO: extract this reasonable query into a helper function shared across the
|
||||
// codebase
|
||||
@@ -2203,7 +2206,7 @@ async fn test_media_uploads() {
|
||||
let file_media = client
|
||||
.media()
|
||||
.get_media_content(
|
||||
&MediaRequest { source: new_content.source, format: MediaFormat::File },
|
||||
&MediaRequestParameters { source: new_content.source, format: MediaFormat::File },
|
||||
true,
|
||||
)
|
||||
.await
|
||||
@@ -2217,7 +2220,7 @@ async fn test_media_uploads() {
|
||||
let thumbnail_media = client
|
||||
.media()
|
||||
.get_media_content(
|
||||
&MediaRequest {
|
||||
&MediaRequestParameters {
|
||||
source: new_thumbnail_source,
|
||||
// TODO: extract this reasonable query into a helper function shared across the
|
||||
// codebase
|
||||
|
||||
Reference in New Issue
Block a user