reply to messages
This commit is contained in:
parent
ebb94341c8
commit
b30884c7ac
2 changed files with 29 additions and 22 deletions
|
@ -9,6 +9,7 @@ use clap::{Parser, Subcommand};
|
|||
use regex::Regex;
|
||||
use ruma::{
|
||||
events::{
|
||||
relation::InReplyTo,
|
||||
room::{
|
||||
canonical_alias::RoomCanonicalAliasEventContent,
|
||||
create::RoomCreateEventContent,
|
||||
|
@ -16,7 +17,7 @@ use ruma::{
|
|||
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
message::RoomMessageEventContent,
|
||||
message::{Relation::Reply, RoomMessageEventContent},
|
||||
name::RoomNameEventContent,
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
topic::RoomTopicEventContent,
|
||||
|
@ -285,7 +286,7 @@ enum ServerCommand {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum AdminRoomEvent {
|
||||
ProcessMessage(String),
|
||||
ProcessMessage(String, Arc<EventId>),
|
||||
SendMessage(RoomMessageEventContent),
|
||||
}
|
||||
|
||||
|
@ -333,9 +334,11 @@ impl Service {
|
|||
loop {
|
||||
tokio::select! {
|
||||
Some(event) = receiver.recv() => {
|
||||
let message_content = match event {
|
||||
AdminRoomEvent::SendMessage(content) => content,
|
||||
AdminRoomEvent::ProcessMessage(room_message) => self.process_admin_message(room_message).await
|
||||
let (mut message_content, reply) = match event {
|
||||
AdminRoomEvent::SendMessage(content) => (content, None),
|
||||
AdminRoomEvent::ProcessMessage(room_message, reply_id) => {
|
||||
(self.process_admin_message(room_message).await, Some(reply_id))
|
||||
}
|
||||
};
|
||||
|
||||
let mutex_state = Arc::clone(
|
||||
|
@ -349,6 +352,10 @@ impl Service {
|
|||
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
if let Some(reply) = reply {
|
||||
message_content.relates_to = Some(Reply { in_reply_to: InReplyTo { event_id: reply.into() } })
|
||||
}
|
||||
|
||||
services().rooms.timeline.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: TimelineEventType::RoomMessage,
|
||||
|
@ -371,9 +378,9 @@ impl Service {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn process_message(&self, room_message: String) {
|
||||
pub fn process_message(&self, room_message: String, event_id: Arc<EventId>) {
|
||||
self.sender
|
||||
.send(AdminRoomEvent::ProcessMessage(room_message))
|
||||
.send(AdminRoomEvent::ProcessMessage(room_message, event_id))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -483,7 +483,7 @@ impl Service {
|
|||
&& services().globals.emergency_password().is_none();
|
||||
|
||||
if to_conduit && !from_conduit && admin_room.as_ref() == Some(&pdu.room_id) {
|
||||
services().admin.process_message(body);
|
||||
services().admin.process_message(body, pdu.event_id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue