fix: put reason of redaction in the redacted event
This commit is contained in:
		
							parent
							
								
									7ba9263cc6
								
							
						
					
					
						commit
						38663228f5
					
				
					 2 changed files with 6 additions and 20 deletions
				
			
		|  | @ -11,7 +11,6 @@ use ruma::{ | ||||||
|         room::{ |         room::{ | ||||||
|             join_rules, member, |             join_rules, member, | ||||||
|             power_levels::{self, PowerLevelsEventContent}, |             power_levels::{self, PowerLevelsEventContent}, | ||||||
|             redaction, |  | ||||||
|         }, |         }, | ||||||
|         EventType, |         EventType, | ||||||
|     }, |     }, | ||||||
|  | @ -566,7 +565,7 @@ impl Rooms { | ||||||
|         self.eventid_pduid |         self.eventid_pduid | ||||||
|             .insert(pdu.event_id.to_string(), pdu_id.clone())?; |             .insert(pdu.event_id.to_string(), pdu_id.clone())?; | ||||||
| 
 | 
 | ||||||
|         if let Some(state_key) = pdu.state_key { |         if let Some(state_key) = &pdu.state_key { | ||||||
|             let mut key = room_id.to_string().as_bytes().to_vec(); |             let mut key = room_id.to_string().as_bytes().to_vec(); | ||||||
|             key.push(0xff); |             key.push(0xff); | ||||||
|             key.extend_from_slice(pdu.kind.to_string().as_bytes()); |             key.extend_from_slice(pdu.kind.to_string().as_bytes()); | ||||||
|  | @ -578,20 +577,7 @@ impl Rooms { | ||||||
|         match event_type { |         match event_type { | ||||||
|             EventType::RoomRedaction => { |             EventType::RoomRedaction => { | ||||||
|                 if let Some(redact_id) = &redacts { |                 if let Some(redact_id) = &redacts { | ||||||
|                     // TODO: Reason
 |                     self.redact_pdu(&redact_id, &pdu)?; | ||||||
|                     let _reason = |  | ||||||
|                         serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content) |  | ||||||
|                             .expect("Raw::from_value always works.") |  | ||||||
|                             .deserialize() |  | ||||||
|                             .map_err(|_| { |  | ||||||
|                                 Error::BadRequest( |  | ||||||
|                                     ErrorKind::InvalidParam, |  | ||||||
|                                     "Invalid redaction event content.", |  | ||||||
|                                 ) |  | ||||||
|                             })? |  | ||||||
|                             .reason; |  | ||||||
| 
 |  | ||||||
|                     self.redact_pdu(&redact_id)?; |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             EventType::RoomMember => { |             EventType::RoomMember => { | ||||||
|  | @ -758,12 +744,12 @@ impl Rooms { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Replace a PDU with the redacted form.
 |     /// Replace a PDU with the redacted form.
 | ||||||
|     pub fn redact_pdu(&self, event_id: &EventId) -> Result<()> { |     pub fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { | ||||||
|         if let Some(pdu_id) = self.get_pdu_id(event_id)? { |         if let Some(pdu_id) = self.get_pdu_id(event_id)? { | ||||||
|             let mut pdu = self |             let mut pdu = self | ||||||
|                 .get_pdu_from_id(&pdu_id)? |                 .get_pdu_from_id(&pdu_id)? | ||||||
|                 .ok_or_else(|| Error::bad_database("PDU ID points to invalid PDU."))?; |                 .ok_or_else(|| Error::bad_database("PDU ID points to invalid PDU."))?; | ||||||
|             pdu.redact()?; |             pdu.redact(&reason)?; | ||||||
|             self.replace_pdu(&pdu_id, &pdu)?; |             self.replace_pdu(&pdu_id, &pdu)?; | ||||||
|             Ok(()) |             Ok(()) | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ pub struct PduEvent { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl PduEvent { | impl PduEvent { | ||||||
|     pub fn redact(&mut self) -> Result<()> { |     pub fn redact(&mut self, reason: &PduEvent) -> Result<()> { | ||||||
|         self.unsigned.clear(); |         self.unsigned.clear(); | ||||||
| 
 | 
 | ||||||
|         let allowed: &[&str] = match self.kind { |         let allowed: &[&str] = match self.kind { | ||||||
|  | @ -71,7 +71,7 @@ impl PduEvent { | ||||||
| 
 | 
 | ||||||
|         self.unsigned.insert( |         self.unsigned.insert( | ||||||
|             "redacted_because".to_owned(), |             "redacted_because".to_owned(), | ||||||
|             json!({"content": {}, "type": "m.room.redaction"}), |             serde_json::to_string(reason).expect("PduEvent::to_string always works").into() | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         self.content = new_content.into(); |         self.content = new_content.into(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue