events: Add RoomMessageEventContentWithoutRelation::add_mentions
This commit is contained in:
parent
440a563355
commit
e7ed90ad0f
@ -10,6 +10,7 @@ Improvements:
|
|||||||
`RoomMessageEventContent`:
|
`RoomMessageEventContent`:
|
||||||
- `make_reply_to`
|
- `make_reply_to`
|
||||||
- `make_reply_to_raw`
|
- `make_reply_to_raw`
|
||||||
|
- `add_mentions`
|
||||||
|
|
||||||
# 0.27.0
|
# 0.27.0
|
||||||
|
|
||||||
|
@ -272,6 +272,11 @@ impl Mentions {
|
|||||||
pub fn with_room_mention() -> Self {
|
pub fn with_room_mention() -> Self {
|
||||||
Self { room: true, ..Default::default() }
|
Self { room: true, ..Default::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add(&mut self, mentions: Self) {
|
||||||
|
self.user_ids.extend(mentions.user_ids);
|
||||||
|
self.room |= mentions.room;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
|
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
|
||||||
|
@ -348,13 +348,7 @@ impl RoomMessageEventContent {
|
|||||||
///
|
///
|
||||||
/// [mentions]: https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions
|
/// [mentions]: https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions
|
||||||
pub fn add_mentions(mut self, mentions: Mentions) -> Self {
|
pub fn add_mentions(mut self, mentions: Mentions) -> Self {
|
||||||
if let Some(m) = &mut self.mentions {
|
self.mentions.get_or_insert_with(Mentions::new).add(mentions);
|
||||||
m.user_ids.extend(mentions.user_ids);
|
|
||||||
m.room |= mentions.room;
|
|
||||||
} else {
|
|
||||||
self.mentions = Some(mentions);
|
|
||||||
}
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +213,18 @@ impl RoomMessageEventContentWithoutRelation {
|
|||||||
self.make_reply_tweaks(original_event_id, original_thread_id, sender_for_mentions)
|
self.make_reply_tweaks(original_event_id, original_thread_id, sender_for_mentions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add the given [mentions] to this event.
|
||||||
|
///
|
||||||
|
/// If no [`Mentions`] was set on this events, this sets it. Otherwise, this updates the current
|
||||||
|
/// mentions by extending the previous `user_ids` with the new ones, and applies a logical OR to
|
||||||
|
/// the values of `room`.
|
||||||
|
///
|
||||||
|
/// [mentions]: https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions
|
||||||
|
pub fn add_mentions(mut self, mentions: Mentions) -> Self {
|
||||||
|
self.mentions.get_or_insert_with(Mentions::new).add(mentions);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn make_reply_tweaks(
|
fn make_reply_tweaks(
|
||||||
mut self,
|
mut self,
|
||||||
original_event_id: OwnedEventId,
|
original_event_id: OwnedEventId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user