-
Notifications
You must be signed in to change notification settings - Fork 315
feat: MSC 4278 implementation #5014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ use ruma::{ | |
assign, | ||
events::{ | ||
ignored_user_list::{IgnoredUser, IgnoredUserListEventContent}, | ||
media_preview_config::{ | ||
InviteAvatars, MediaPreviewConfigEventContent, MediaPreviews, | ||
UnstableMediaPreviewConfigEventContent, | ||
}, | ||
push_rules::PushRulesEventContent, | ||
room::MediaSource, | ||
AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent, | ||
|
@@ -916,6 +920,88 @@ impl Account { | |
Ok(ignored_user_list) | ||
} | ||
|
||
/// Set the media previews display policy for the account. | ||
/// | ||
/// This is an unstable event, so we always default to setting the unstable | ||
/// version of the event for now. | ||
pub async fn set_media_previews_setting(&self, new_setting: MediaPreviews) -> Result<()> { | ||
let mut media_preview_config_to_update = | ||
self.get_unstable_media_preview_config().await?.unwrap_or_else(|| { | ||
UnstableMediaPreviewConfigEventContent::new(Default::default(), Default::default()) | ||
}); | ||
media_preview_config_to_update.media_previews = new_setting; | ||
|
||
// Updating the account data | ||
self.set_account_data(media_preview_config_to_update).await?; | ||
// TODO: I think I should reset all the storage and perform a new local sync | ||
// here but I don't know how | ||
Comment on lines
+936
to
+937
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure what to do here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was actually looking at this recently and was surprised to see the store not getting updated when we set some account data. @poljar is there a way to tell the store that a piece of account data has been changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the assumption is that a sync is running. Or maybe I'm misunderstanding what a local sync would be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just looked at the the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as a sync takes, you can subscribe to listen to account data events. There's actually a PR in flight to add exactly this to the bindings: #4994. I suppose you'll have to subscribe to this anyways, in case the value gets updated on another device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice this would be very useful! |
||
Ok(()) | ||
} | ||
|
||
/// Set the avatars in invite requests display policy for the account. | ||
/// | ||
/// This is an unstable event, so we always default to setting the unstable | ||
/// version of the event for now. | ||
pub async fn set_invite_avatars_setting(&self, new_setting: InviteAvatars) -> Result<()> { | ||
let mut media_preview_config_to_update = | ||
self.get_unstable_media_preview_config().await?.unwrap_or_else(|| { | ||
UnstableMediaPreviewConfigEventContent::new(Default::default(), Default::default()) | ||
}); | ||
media_preview_config_to_update.invite_avatars = new_setting; | ||
// Updating the account data | ||
self.set_account_data(media_preview_config_to_update).await?; | ||
// TODO: I think I should reset all the storage and perform a new local sync | ||
// here but I don't know how | ||
Comment on lines
+953
to
+954
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure what to do here |
||
Ok(()) | ||
} | ||
|
||
/// Get the current media previews display policy for the account. | ||
pub async fn get_media_previews_setting(&self) -> Result<MediaPreviews> { | ||
if let Some(media_preview_config) = self.get_media_preview_config().await? { | ||
Ok(media_preview_config.media_previews) | ||
} else if let Some(unstable_media_preview_config) = | ||
self.get_unstable_media_preview_config().await? | ||
{ | ||
Ok(unstable_media_preview_config.media_previews) | ||
} else { | ||
Ok(Default::default()) | ||
} | ||
} | ||
|
||
/// Get the current avatars in invite requests display policy for the | ||
/// account. | ||
pub async fn get_invite_avatars_setting(&self) -> Result<InviteAvatars> { | ||
if let Some(media_preview_config) = self.get_media_preview_config().await? { | ||
Ok(media_preview_config.invite_avatars) | ||
} else if let Some(unstable_media_preview_config) = | ||
self.get_unstable_media_preview_config().await? | ||
{ | ||
Ok(unstable_media_preview_config.invite_avatars) | ||
} else { | ||
Ok(Default::default()) | ||
} | ||
Velin92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
async fn get_unstable_media_preview_config( | ||
&self, | ||
) -> Result<Option<UnstableMediaPreviewConfigEventContent>> { | ||
let unstable_media_preview_config = self | ||
.account_data::<UnstableMediaPreviewConfigEventContent>() | ||
.await? | ||
.map(|c| c.deserialize()) | ||
.transpose()?; | ||
Ok(unstable_media_preview_config) | ||
} | ||
|
||
async fn get_media_preview_config(&self) -> Result<Option<MediaPreviewConfigEventContent>> { | ||
let media_preview_config = self | ||
.account_data::<MediaPreviewConfigEventContent>() | ||
.await? | ||
.map(|c| c.deserialize()) | ||
.transpose()?; | ||
Ok(media_preview_config) | ||
} | ||
|
||
/// Get the current push rules from storage. | ||
/// | ||
/// If no push rules event was found, or it fails to deserialize, a ruleset | ||
|
Uh oh!
There was an error while loading. Please reload this page.