Commit 9b2c17fb1070
tarball4 files changed+54-3
@@ -538,6 +538,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
538538
let content = serde_json::to_value(&content)539539
.and_then(|mut content| {540540
content[REACTION_SHORTCODE_FIELD] = shortcode.into();541
+ content["shortcode"] = shortcode.into();541542
Raw::new(&content)542543
})543544
.map_err(|err| {@@ -75,7 +75,11 @@ pub(super) const REACTION_SHORTCODE_FIELD: &str = "com.beeper.reaction.shortcode
7575
///7676
/// [MSC4027]: https://github.com/matrix-org/matrix-spec-proposals/pull/40277777
pub(super) fn reaction_shortcode(content: &Raw<AnyMessageLikeEventContent>) -> Option<String> {78
- content.get_field(REACTION_SHORTCODE_FIELD).ok().flatten()78
+ content79
+ .get_field(REACTION_SHORTCODE_FIELD)80
+ .ok()81
+ .flatten()82
+ .or_else(|| content.get_field("shortcode").ok().flatten())7983
}8084
8185
/// When adding an event, useful information related to the source of the event.@@ -147,6 +147,32 @@ async fn test_add_reaction_with_shortcode_sends_it() {
147147
sent_raw_events[0].get_field::<String>("com.beeper.reaction.shortcode").unwrap().as_deref(),148148
Some("blobcat")149149
);150
+ assert_eq!(151
+ sent_raw_events[0].get_field::<String>("shortcode").unwrap().as_deref(),152
+ Some("blobcat")153
+ );154
+}155
+156
+#[test]157
+fn test_reaction_shortcode_accepts_cinny_and_prefers_msc4027() {158
+ for (value, expected) in [159
+ (serde_json::json!({ "shortcode": "blobcat" }), Some("blobcat")),160
+ (161
+ serde_json::json!({162
+ "shortcode": "legacy",163
+ "com.beeper.reaction.shortcode": "preferred"164
+ }),165
+ Some("preferred"),166
+ ),167
+ (serde_json::json!({ "shortcode": 3 }), None),168
+ (serde_json::json!({}), None),169
+ ] {170
+ let content = Raw::new(&value).unwrap().cast_unchecked();171
+ assert_eq!(172
+ crate::timeline::event_handler::reaction_shortcode(&content).as_deref(),173
+ expected174
+ );175
+ }150176
}151177
152178
#[async_test]@@ -3172,7 +3172,8 @@ fn with_reaction_shortcode(
31723172
) -> Result<Raw<AnyMessageLikeEventContent>, serde_json::Error> {31733173
let mut content =31743174
content.deserialize_as_unchecked::<serde_json::Map<String, serde_json::Value>>()?;3175
- content.insert("com.beeper.reaction.shortcode".to_owned(), shortcode.into());3175
+ content.insert("com.beeper.reaction.shortcode".to_owned(), shortcode.clone().into());3176
+ content.insert("shortcode".to_owned(), shortcode.into());31763177
Ok(Raw::new(&content)?.cast_unchecked())31773178
}31783179
@@ -3192,10 +3193,29 @@ mod tests {
31923193
room_id,31933194
};31943195
3195
- use super::canonicalize_dependent_requests;3196
+ use super::{canonicalize_dependent_requests, with_reaction_shortcode};31963197
use crate::{client::WeakClient, test_utils::logged_in_client};31973198
31983199
#[test]3200
+ fn test_reaction_shortcode_fields_preserve_annotation() {3201
+ let content = serde_json::json!({3202
+ "m.relates_to": {3203
+ "rel_type": "m.annotation",3204
+ "event_id": "$event:example.org",3205
+ "key": "mxc://example.org/blobcat"3206
+ }3207
+ });3208
+ let content = ruma::serde::Raw::new(&content).unwrap().cast_unchecked();3209
+3210
+ let result = with_reaction_shortcode(content, "blobcat".to_owned()).unwrap();3211
+ let result = result.deserialize_as_unchecked::<serde_json::Value>().unwrap();3212
+3213
+ assert_eq!(result["m.relates_to"]["key"], "mxc://example.org/blobcat");3214
+ assert_eq!(result["com.beeper.reaction.shortcode"], "blobcat");3215
+ assert_eq!(result["shortcode"], "blobcat");3216
+ }3217
+3218
+ #[test]31993219
fn test_canonicalize_dependent_events_created_at() {32003220
// Test to ensure the created_at field is being serialized and retrieved32013221
// correctly.