17
17
use futures_core:: Stream ;
18
18
use futures_util:: { stream, StreamExt } ;
19
19
use matrix_sdk_base:: {
20
+ event_cache:: store:: media,
20
21
media:: { MediaFormat , MediaRequestParameters } ,
21
22
store:: StateStoreExt ,
22
23
StateStoreDataKey , StateStoreDataValue ,
@@ -39,7 +40,7 @@ use ruma::{
39
40
events:: {
40
41
ignored_user_list:: { IgnoredUser , IgnoredUserListEventContent } ,
41
42
media_preview_config:: {
42
- InviteAvatars , MediaPreviewConfigEventContent , MediaPreviews ,
43
+ self , InviteAvatars , MediaPreviewConfigEventContent , MediaPreviews ,
43
44
UnstableMediaPreviewConfigEventContent ,
44
45
} ,
45
46
push_rules:: PushRulesEventContent ,
@@ -1027,22 +1028,7 @@ impl Account {
1027
1028
( MediaPreviewConfigEventContent , impl Stream < Item = MediaPreviewConfigEventContent > ) ,
1028
1029
Error ,
1029
1030
> {
1030
- // First we check if there is avalue in the stable event
1031
- let initial_value =
1032
- self . fetch_account_data ( GlobalAccountDataEventType :: MediaPreviewConfig ) . await ?;
1033
-
1034
- let initial_value = if let Some ( initial_value) = initial_value {
1035
- Some ( initial_value)
1036
- } else {
1037
- // If there is no value in the stable event, we check the unstable
1038
- self . fetch_account_data ( GlobalAccountDataEventType :: UnstableMediaPreviewConfig ) . await ?
1039
- } ;
1040
-
1041
- // We deserialize the content of the event, if is not found we return the
1042
- // default
1043
- let initial_value = initial_value
1044
- . and_then ( |value| value. deserialize_as :: < MediaPreviewConfigEventContent > ( ) . ok ( ) )
1045
- . unwrap_or_default ( ) ;
1031
+ let initial_value = self . get_media_preview_config_event_content ( ) . await ?;
1046
1032
1047
1033
// We need to create two observers, one for the stable event and one for the
1048
1034
// unstable and combine them into a single stream.
@@ -1074,12 +1060,35 @@ impl Account {
1074
1060
Ok ( ( initial_value, result_stream) )
1075
1061
}
1076
1062
1063
+ async fn get_media_preview_config_event_content (
1064
+ & self ,
1065
+ ) -> Result < MediaPreviewConfigEventContent > {
1066
+ // First we check if there is avalue in the stable event
1067
+ let media_preview_config =
1068
+ self . fetch_account_data ( GlobalAccountDataEventType :: MediaPreviewConfig ) . await ?;
1069
+
1070
+ let media_preview_config = if let Some ( media_preview_config) = media_preview_config {
1071
+ Some ( media_preview_config)
1072
+ } else {
1073
+ // If there is no value in the stable event, we check the unstable
1074
+ self . fetch_account_data ( GlobalAccountDataEventType :: UnstableMediaPreviewConfig ) . await ?
1075
+ } ;
1076
+
1077
+ // We deserialize the content of the event, if is not found we return the
1078
+ // default
1079
+ let media_preview_config = media_preview_config
1080
+ . and_then ( |value| value. deserialize_as :: < MediaPreviewConfigEventContent > ( ) . ok ( ) )
1081
+ . unwrap_or_default ( ) ;
1082
+
1083
+ Ok ( media_preview_config)
1084
+ }
1085
+
1077
1086
/// Set the media previews display policy in the timeline.
1078
1087
///
1079
1088
/// This will always use the unstable event until we know which Matrix
1080
1089
/// version will support it.
1081
1090
pub async fn set_media_previews_display_policy ( & self , policy : MediaPreviews ) -> Result < ( ) > {
1082
- let ( mut media_preview_config, _ ) = self . observe_media_preview_config ( ) . await ?;
1091
+ let mut media_preview_config = self . get_media_preview_config_event_content ( ) . await ?;
1083
1092
media_preview_config. media_previews = policy;
1084
1093
1085
1094
// Updating the unstable account data
@@ -1094,7 +1103,7 @@ impl Account {
1094
1103
/// This will always use the unstable event until we know which matrix
1095
1104
/// version will support it.
1096
1105
pub async fn set_invite_avatars_display_policy ( & self , policy : InviteAvatars ) -> Result < ( ) > {
1097
- let ( mut media_preview_config, _ ) = self . observe_media_preview_config ( ) . await ?;
1106
+ let mut media_preview_config = self . get_media_preview_config_event_content ( ) . await ?;
1098
1107
media_preview_config. invite_avatars = policy;
1099
1108
1100
1109
// Updating the unstable account data
0 commit comments