mirror of
https://forgejo.ellis.link/continuwuation/continuwuity/
synced 2026-09-25 21:03:41 +00:00
Ruma upgrade
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::{utils, Error, Result};
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
events::{AnyEphemeralRoomEvent, EventType},
|
||||
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
||||
serde::Raw,
|
||||
RoomId, UserId,
|
||||
};
|
||||
@@ -22,7 +22,7 @@ pub fn update<T: Serialize>(
|
||||
&self,
|
||||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
event_type: EventType,
|
||||
event_type: RoomAccountDataEventType,
|
||||
data: &T,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
@@ -38,10 +38,10 @@ pub fn update<T: Serialize>(
|
||||
let mut roomuserdataid = prefix.clone();
|
||||
roomuserdataid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
roomuserdataid.push(0xff);
|
||||
roomuserdataid.extend_from_slice(event_type.as_bytes());
|
||||
roomuserdataid.extend_from_slice(event_type.to_string().as_bytes());
|
||||
|
||||
let mut key = prefix;
|
||||
key.extend_from_slice(event_type.as_bytes());
|
||||
key.extend_from_slice(event_type.to_string().as_bytes());
|
||||
|
||||
let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling
|
||||
if json.get("type").is_none() || json.get("content").is_none() {
|
||||
@@ -75,7 +75,7 @@ pub fn get<T: DeserializeOwned>(
|
||||
&self,
|
||||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
kind: EventType,
|
||||
kind: RoomAccountDataEventType,
|
||||
) -> Result<Option<T>> {
|
||||
let mut key = room_id
|
||||
.map(|r| r.to_string())
|
||||
@@ -85,7 +85,7 @@ pub fn get<T: DeserializeOwned>(
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(kind.as_ref().as_bytes());
|
||||
key.extend_from_slice(kind.to_string().as_bytes());
|
||||
|
||||
self.roomusertype_roomuserdataid
|
||||
.get(&key)?
|
||||
@@ -109,7 +109,7 @@ pub fn changes_since(
|
||||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
since: u64,
|
||||
) -> Result<HashMap<EventType, Raw<AnyEphemeralRoomEvent>>> {
|
||||
) -> Result<HashMap<RoomAccountDataEventType, Raw<AnyEphemeralRoomEvent>>> {
|
||||
let mut userdata = HashMap::new();
|
||||
|
||||
let mut prefix = room_id
|
||||
@@ -131,7 +131,7 @@ pub fn changes_since(
|
||||
.take_while(move |(k, _)| k.starts_with(&prefix))
|
||||
.map(|(k, v)| {
|
||||
Ok::<_, Error>((
|
||||
EventType::try_from(
|
||||
RoomAccountDataEventType::try_from(
|
||||
utils::string_from_bytes(k.rsplit(|&b| b == 0xff).next().ok_or_else(
|
||||
|| Error::bad_database("RoomUserData ID in db is invalid."),
|
||||
)?)
|
||||
|
||||
+16
-16
@@ -28,9 +28,9 @@
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
topic::RoomTopicEventContent,
|
||||
},
|
||||
EventType,
|
||||
RoomEventType,
|
||||
},
|
||||
identifiers::{EventId, RoomAliasId, RoomId, RoomName, RoomVersionId, ServerName, UserId},
|
||||
EventId, RoomAliasId, RoomId, RoomName, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use tokio::sync::{mpsc, MutexGuard, RwLock, RwLockReadGuard};
|
||||
@@ -81,7 +81,7 @@ pub fn start_handler(
|
||||
.rooms
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
event_type: RoomEventType::RoomMessage,
|
||||
content: to_raw_value(&message)
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
@@ -553,7 +553,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
// 1. The room create event
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomCreate,
|
||||
event_type: RoomEventType::RoomCreate,
|
||||
content: to_raw_value(&content).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
@@ -568,7 +568,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
// 2. Make conduit bot join
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
event_type: RoomEventType::RoomMember,
|
||||
content: to_raw_value(&RoomMemberEventContent {
|
||||
membership: MembershipState::Join,
|
||||
displayname: None,
|
||||
@@ -596,7 +596,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomPowerLevels,
|
||||
event_type: RoomEventType::RoomPowerLevels,
|
||||
content: to_raw_value(&RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
@@ -615,7 +615,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
// 4.1 Join Rules
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomJoinRules,
|
||||
event_type: RoomEventType::RoomJoinRules,
|
||||
content: to_raw_value(&RoomJoinRulesEventContent::new(JoinRule::Invite))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
@@ -631,7 +631,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
// 4.2 History Visibility
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomHistoryVisibility,
|
||||
event_type: RoomEventType::RoomHistoryVisibility,
|
||||
content: to_raw_value(&RoomHistoryVisibilityEventContent::new(
|
||||
HistoryVisibility::Shared,
|
||||
))
|
||||
@@ -649,7 +649,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
// 4.3 Guest Access
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomGuestAccess,
|
||||
event_type: RoomEventType::RoomGuestAccess,
|
||||
content: to_raw_value(&RoomGuestAccessEventContent::new(GuestAccess::Forbidden))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
@@ -667,7 +667,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
.expect("Room name is valid");
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomName,
|
||||
event_type: RoomEventType::RoomName,
|
||||
content: to_raw_value(&RoomNameEventContent::new(Some(room_name)))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
@@ -682,7 +682,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomTopic,
|
||||
event_type: RoomEventType::RoomTopic,
|
||||
content: to_raw_value(&RoomTopicEventContent {
|
||||
topic: format!("Manage {}", db.globals.server_name()),
|
||||
})
|
||||
@@ -704,7 +704,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomCanonicalAlias,
|
||||
event_type: RoomEventType::RoomCanonicalAlias,
|
||||
content: to_raw_value(&RoomCanonicalAliasEventContent {
|
||||
alias: Some(alias.clone()),
|
||||
alt_aliases: Vec::new(),
|
||||
@@ -758,7 +758,7 @@ pub(crate) async fn make_user_admin(
|
||||
// Invite and join the real user
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
event_type: RoomEventType::RoomMember,
|
||||
content: to_raw_value(&RoomMemberEventContent {
|
||||
membership: MembershipState::Invite,
|
||||
displayname: None,
|
||||
@@ -781,7 +781,7 @@ pub(crate) async fn make_user_admin(
|
||||
)?;
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
event_type: RoomEventType::RoomMember,
|
||||
content: to_raw_value(&RoomMemberEventContent {
|
||||
membership: MembershipState::Join,
|
||||
displayname: Some(displayname),
|
||||
@@ -810,7 +810,7 @@ pub(crate) async fn make_user_admin(
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomPowerLevels,
|
||||
event_type: RoomEventType::RoomPowerLevels,
|
||||
content: to_raw_value(&RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
@@ -829,7 +829,7 @@ pub(crate) async fn make_user_admin(
|
||||
// Send welcome message
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
event_type: RoomEventType::RoomMessage,
|
||||
content: to_raw_value(&RoomMessageEventContent::text_html(
|
||||
format!("## Thank you for trying out Conduit!\n\nConduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.\n\nHelpful links:\n> Website: https://conduit.rs\n> Git and Documentation: https://gitlab.com/famedly/conduit\n> Report issues: https://gitlab.com/famedly/conduit/-/issues\n\nFor a list of available commands, send the following message in this room: `@conduit:{}: --help`\n\nHere are some rooms you can join (by typing the command):\n\nConduit room (Ask questions and get notified on updates):\n`/join #conduit:fachschaften.org`\n\nConduit lounge (Off-topic, only Conduit users are allowed to join)\n`/join #conduit-lounge:conduit.rs`", db.globals.server_name()).to_owned(),
|
||||
format!("<h2>Thank you for trying out Conduit!</h2>\n<p>Conduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.</p>\n<p>Helpful links:</p>\n<blockquote>\n<p>Website: https://conduit.rs<br>Git and Documentation: https://gitlab.com/famedly/conduit<br>Report issues: https://gitlab.com/famedly/conduit/-/issues</p>\n</blockquote>\n<p>For a list of available commands, send the following message in this room: <code>@conduit:{}: --help</code></p>\n<p>Here are some rooms you can join (by typing the command):</p>\n<p>Conduit room (Ask questions and get notified on updates):<br><code>/join #conduit:fachschaften.org</code></p>\n<p>Conduit lounge (Off-topic, only Conduit users are allowed to join)<br><code>/join #conduit-lounge:conduit.rs</code></p>\n", db.globals.server_name()).to_owned(),
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
events::{
|
||||
room::{name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent},
|
||||
AnySyncRoomEvent, EventType,
|
||||
AnySyncRoomEvent, EventType, RoomEventType, StateEventType,
|
||||
},
|
||||
push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak},
|
||||
serde::Raw,
|
||||
@@ -181,7 +181,7 @@ pub async fn send_push_notice(
|
||||
|
||||
let power_levels: RoomPowerLevelsEventContent = db
|
||||
.rooms
|
||||
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
|
||||
.room_state_get(&pdu.room_id, &StateEventType::RoomPowerLevels, "")?
|
||||
.map(|ev| {
|
||||
serde_json::from_str(ev.content.get())
|
||||
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
|
||||
@@ -293,7 +293,7 @@ async fn send_notice(
|
||||
// TODO: missed calls
|
||||
notifi.counts = NotificationCounts::new(unread, uint!(0));
|
||||
|
||||
if event.kind == EventType::RoomEncrypted
|
||||
if event.kind == RoomEventType::RoomEncrypted
|
||||
|| tweaks
|
||||
.iter()
|
||||
.any(|t| matches!(t, Tweak::Highlight(true) | Tweak::Sound(_)))
|
||||
@@ -314,7 +314,7 @@ async fn send_notice(
|
||||
let content = serde_json::value::to_raw_value(&event.content).ok();
|
||||
notifi.content = content.as_deref();
|
||||
|
||||
if event.kind == EventType::RoomMember {
|
||||
if event.kind == RoomEventType::RoomMember {
|
||||
notifi.user_is_target = event.state_key.as_deref() == Some(event.sender.as_str());
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ async fn send_notice(
|
||||
|
||||
let room_name = if let Some(room_name_pdu) =
|
||||
db.rooms
|
||||
.room_state_get(&event.room_id, &EventType::RoomName, "")?
|
||||
.room_state_get(&event.room_id, &StateEventType::RoomName, "")?
|
||||
{
|
||||
serde_json::from_str::<RoomNameEventContent>(room_name_pdu.content.get())
|
||||
.map_err(|_| Error::bad_database("Invalid room name event in database."))?
|
||||
|
||||
+73
-53
@@ -21,7 +21,8 @@
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
},
|
||||
tag::TagEvent,
|
||||
AnyStrippedStateEvent, AnySyncStateEvent, EventType,
|
||||
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||
RoomAccountDataEventType, RoomEventType, StateEventType,
|
||||
},
|
||||
push::{Action, Ruleset, Tweak},
|
||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
@@ -111,8 +112,8 @@ pub struct Rooms {
|
||||
pub(super) shorteventid_cache: Mutex<LruCache<u64, Arc<EventId>>>,
|
||||
pub(super) auth_chain_cache: Mutex<LruCache<Vec<u64>, Arc<HashSet<u64>>>>,
|
||||
pub(super) eventidshort_cache: Mutex<LruCache<Box<EventId>, u64>>,
|
||||
pub(super) statekeyshort_cache: Mutex<LruCache<(EventType, String), u64>>,
|
||||
pub(super) shortstatekey_cache: Mutex<LruCache<u64, (EventType, String)>>,
|
||||
pub(super) statekeyshort_cache: Mutex<LruCache<(StateEventType, String), u64>>,
|
||||
pub(super) shortstatekey_cache: Mutex<LruCache<u64, (StateEventType, String)>>,
|
||||
pub(super) our_real_users_cache: RwLock<HashMap<Box<RoomId>, Arc<HashSet<Box<UserId>>>>>,
|
||||
pub(super) appservice_in_room_cache: RwLock<HashMap<Box<RoomId>, HashMap<String, bool>>>,
|
||||
pub(super) lazy_load_waiting:
|
||||
@@ -151,7 +152,7 @@ pub fn state_full_ids(&self, shortstatehash: u64) -> Result<BTreeMap<u64, Arc<Ev
|
||||
pub fn state_full(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
) -> Result<HashMap<(EventType, String), Arc<PduEvent>>> {
|
||||
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
|
||||
let full_state = self
|
||||
.load_shortstatehash_info(shortstatehash)?
|
||||
.pop()
|
||||
@@ -166,7 +167,7 @@ pub fn state_full(
|
||||
.map(|pdu| {
|
||||
Ok::<_, Error>((
|
||||
(
|
||||
pdu.kind.clone(),
|
||||
pdu.kind.to_string().into(),
|
||||
pdu.state_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| Error::bad_database("State event has no state key."))?
|
||||
@@ -184,7 +185,7 @@ pub fn state_full(
|
||||
pub fn state_get_id(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<Arc<EventId>>> {
|
||||
let shortstatekey = match self.get_shortstatekey(event_type, state_key)? {
|
||||
@@ -211,7 +212,7 @@ pub fn state_get_id(
|
||||
pub fn state_get(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<Arc<PduEvent>>> {
|
||||
self.state_get_id(shortstatehash, event_type, state_key)?
|
||||
@@ -254,7 +255,7 @@ pub fn current_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
pub fn get_auth_events(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
kind: &EventType,
|
||||
kind: &RoomEventType,
|
||||
sender: &UserId,
|
||||
state_key: Option<&str>,
|
||||
content: &serde_json::value::RawValue,
|
||||
@@ -272,7 +273,7 @@ pub fn get_auth_events(
|
||||
let mut sauthevents = auth_events
|
||||
.into_iter()
|
||||
.filter_map(|(event_type, state_key)| {
|
||||
self.get_shortstatekey(&event_type, &state_key)
|
||||
self.get_shortstatekey(&event_type.to_string().into(), &state_key)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|s| (s, (event_type, state_key)))
|
||||
@@ -764,7 +765,7 @@ pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_shortstatekey(
|
||||
&self,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<u64>> {
|
||||
if let Some(short) = self
|
||||
@@ -776,7 +777,7 @@ pub fn get_shortstatekey(
|
||||
return Ok(Some(*short));
|
||||
}
|
||||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
let mut statekey = event_type.to_string().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
@@ -820,7 +821,7 @@ pub fn get_or_create_shortroomid(
|
||||
#[tracing::instrument(skip(self, globals))]
|
||||
pub fn get_or_create_shortstatekey(
|
||||
&self,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<u64> {
|
||||
@@ -833,7 +834,7 @@ pub fn get_or_create_shortstatekey(
|
||||
return Ok(*short);
|
||||
}
|
||||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
let mut statekey = event_type.to_string().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
@@ -888,7 +889,7 @@ pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>>
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(EventType, String)> {
|
||||
pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> {
|
||||
if let Some(id) = self
|
||||
.shortstatekey_cache
|
||||
.lock()
|
||||
@@ -910,7 +911,7 @@ pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(EventType,
|
||||
.ok_or_else(|| Error::bad_database("Invalid statekey in shortstatekey_statekey."))?;
|
||||
|
||||
let event_type =
|
||||
EventType::try_from(utils::string_from_bytes(eventtype_bytes).map_err(|_| {
|
||||
StateEventType::try_from(utils::string_from_bytes(eventtype_bytes).map_err(|_| {
|
||||
Error::bad_database("Event type in shortstatekey_statekey is invalid unicode.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("Event type in shortstatekey_statekey is invalid."))?;
|
||||
@@ -934,7 +935,7 @@ pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(EventType,
|
||||
pub fn room_state_full(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<HashMap<(EventType, String), Arc<PduEvent>>> {
|
||||
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
|
||||
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
|
||||
self.state_full(current_shortstatehash)
|
||||
} else {
|
||||
@@ -947,7 +948,7 @@ pub fn room_state_full(
|
||||
pub fn room_state_get_id(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<Arc<EventId>>> {
|
||||
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
|
||||
@@ -962,7 +963,7 @@ pub fn room_state_get_id(
|
||||
pub fn room_state_get(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &EventType,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<Arc<PduEvent>>> {
|
||||
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
|
||||
@@ -1281,7 +1282,7 @@ pub fn append_pdu<'a>(
|
||||
{
|
||||
if let Some(shortstatehash) = self.pdu_shortstatehash(&pdu.event_id).unwrap() {
|
||||
if let Some(prev_state) = self
|
||||
.state_get(shortstatehash, &pdu.kind, state_key)
|
||||
.state_get(shortstatehash, &pdu.kind.to_string().into(), state_key)
|
||||
.unwrap()
|
||||
{
|
||||
unsigned.insert(
|
||||
@@ -1346,7 +1347,7 @@ pub fn append_pdu<'a>(
|
||||
// See if the event matches any known pushers
|
||||
let power_levels: RoomPowerLevelsEventContent = db
|
||||
.rooms
|
||||
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
|
||||
.room_state_get(&pdu.room_id, &StateEventType::RoomPowerLevels, "")?
|
||||
.map(|ev| {
|
||||
serde_json::from_str(ev.content.get())
|
||||
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
|
||||
@@ -1367,7 +1368,11 @@ pub fn append_pdu<'a>(
|
||||
|
||||
let rules_for_user = db
|
||||
.account_data
|
||||
.get(None, user, EventType::PushRules)?
|
||||
.get(
|
||||
None,
|
||||
user,
|
||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||
)?
|
||||
.map(|ev: PushRulesEvent| ev.content.global)
|
||||
.unwrap_or_else(|| Ruleset::server_default(user));
|
||||
|
||||
@@ -1416,12 +1421,12 @@ pub fn append_pdu<'a>(
|
||||
.increment_batch(&mut highlights.into_iter())?;
|
||||
|
||||
match pdu.kind {
|
||||
EventType::RoomRedaction => {
|
||||
RoomEventType::RoomRedaction => {
|
||||
if let Some(redact_id) = &pdu.redacts {
|
||||
self.redact_pdu(redact_id, pdu)?;
|
||||
}
|
||||
}
|
||||
EventType::RoomMember => {
|
||||
RoomEventType::RoomMember => {
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
#[derive(Deserialize)]
|
||||
struct ExtractMembership {
|
||||
@@ -1456,7 +1461,7 @@ struct ExtractMembership {
|
||||
)?;
|
||||
}
|
||||
}
|
||||
EventType::RoomMessage => {
|
||||
RoomEventType::RoomMessage => {
|
||||
#[derive(Deserialize)]
|
||||
struct ExtractBody<'a> {
|
||||
#[serde(borrow)]
|
||||
@@ -1663,8 +1668,11 @@ pub fn append_to_state(
|
||||
let states_parents = previous_shortstatehash
|
||||
.map_or_else(|| Ok(Vec::new()), |p| self.load_shortstatehash_info(p))?;
|
||||
|
||||
let shortstatekey =
|
||||
self.get_or_create_shortstatekey(&new_pdu.kind, state_key, globals)?;
|
||||
let shortstatekey = self.get_or_create_shortstatekey(
|
||||
&new_pdu.kind.to_string().into(),
|
||||
state_key,
|
||||
globals,
|
||||
)?;
|
||||
|
||||
let new = self.compress_state_event(shortstatekey, &new_pdu.event_id, globals)?;
|
||||
|
||||
@@ -1713,28 +1721,36 @@ pub fn calculate_invite_state(
|
||||
) -> Result<Vec<Raw<AnyStrippedStateEvent>>> {
|
||||
let mut state = Vec::new();
|
||||
// Add recommended events
|
||||
if let Some(e) = self.room_state_get(&invite_event.room_id, &EventType::RoomCreate, "")? {
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) =
|
||||
self.room_state_get(&invite_event.room_id, &EventType::RoomJoinRules, "")?
|
||||
self.room_state_get(&invite_event.room_id, &StateEventType::RoomCreate, "")?
|
||||
{
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) =
|
||||
self.room_state_get(&invite_event.room_id, &EventType::RoomCanonicalAlias, "")?
|
||||
self.room_state_get(&invite_event.room_id, &StateEventType::RoomJoinRules, "")?
|
||||
{
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) = self.room_state_get(&invite_event.room_id, &EventType::RoomAvatar, "")? {
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) = self.room_state_get(&invite_event.room_id, &EventType::RoomName, "")? {
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) = self.room_state_get(
|
||||
&invite_event.room_id,
|
||||
&EventType::RoomMember,
|
||||
&StateEventType::RoomCanonicalAlias,
|
||||
"",
|
||||
)? {
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) =
|
||||
self.room_state_get(&invite_event.room_id, &StateEventType::RoomAvatar, "")?
|
||||
{
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) =
|
||||
self.room_state_get(&invite_event.room_id, &StateEventType::RoomName, "")?
|
||||
{
|
||||
state.push(e.to_stripped_state_event());
|
||||
}
|
||||
if let Some(e) = self.room_state_get(
|
||||
&invite_event.room_id,
|
||||
&StateEventType::RoomMember,
|
||||
invite_event.sender.as_str(),
|
||||
)? {
|
||||
state.push(e.to_stripped_state_event());
|
||||
@@ -1807,7 +1823,7 @@ pub fn build_and_append_pdu(
|
||||
.take(20)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let create_event = self.room_state_get(room_id, &EventType::RoomCreate, "")?;
|
||||
let create_event = self.room_state_get(room_id, &StateEventType::RoomCreate, "")?;
|
||||
|
||||
let create_event_content: Option<RoomCreateEventContent> = create_event
|
||||
.as_ref()
|
||||
@@ -1845,7 +1861,9 @@ pub fn build_and_append_pdu(
|
||||
|
||||
let mut unsigned = unsigned.unwrap_or_default();
|
||||
if let Some(state_key) = &state_key {
|
||||
if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? {
|
||||
if let Some(prev_pdu) =
|
||||
self.room_state_get(room_id, &event_type.to_string().into(), state_key)?
|
||||
{
|
||||
unsigned.insert(
|
||||
"prev_content".to_owned(),
|
||||
serde_json::from_str(prev_pdu.content.get()).expect("string is valid json"),
|
||||
@@ -1888,7 +1906,6 @@ pub fn build_and_append_pdu(
|
||||
let auth_check = state_res::auth_check(
|
||||
&room_version,
|
||||
&pdu,
|
||||
create_prev_event,
|
||||
None::<PduEvent>, // TODO: third_party_invite
|
||||
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
|
||||
)
|
||||
@@ -2031,7 +2048,7 @@ pub fn build_and_append_pdu(
|
||||
|
||||
let matching_users = |users: &Regex| {
|
||||
users.is_match(pdu.sender.as_str())
|
||||
|| pdu.kind == EventType::RoomMember
|
||||
|| pdu.kind == RoomEventType::RoomMember
|
||||
&& pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
@@ -2231,7 +2248,7 @@ pub fn update_membership(
|
||||
|
||||
// Check if the room has a predecessor
|
||||
if let Some(predecessor) = self
|
||||
.room_state_get(room_id, &EventType::RoomCreate, "")?
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")?
|
||||
.and_then(|create| serde_json::from_str(create.content.get()).ok())
|
||||
.and_then(|content: RoomCreateEventContent| content.predecessor)
|
||||
{
|
||||
@@ -2264,13 +2281,13 @@ pub fn update_membership(
|
||||
if let Some(tag_event) = db.account_data.get::<TagEvent>(
|
||||
Some(&predecessor.room_id),
|
||||
user_id,
|
||||
EventType::Tag,
|
||||
RoomAccountDataEventType::Tag,
|
||||
)? {
|
||||
db.account_data
|
||||
.update(
|
||||
Some(room_id),
|
||||
user_id,
|
||||
EventType::Tag,
|
||||
RoomAccountDataEventType::Tag,
|
||||
&tag_event,
|
||||
&db.globals,
|
||||
)
|
||||
@@ -2278,10 +2295,11 @@ pub fn update_membership(
|
||||
};
|
||||
|
||||
// Copy direct chat flag
|
||||
if let Some(mut direct_event) =
|
||||
db.account_data
|
||||
.get::<DirectEvent>(None, user_id, EventType::Direct)?
|
||||
{
|
||||
if let Some(mut direct_event) = db.account_data.get::<DirectEvent>(
|
||||
None,
|
||||
user_id,
|
||||
GlobalAccountDataEventType::Direct.to_string().into(),
|
||||
)? {
|
||||
let mut room_ids_updated = false;
|
||||
|
||||
for room_ids in direct_event.content.0.values_mut() {
|
||||
@@ -2295,7 +2313,7 @@ pub fn update_membership(
|
||||
db.account_data.update(
|
||||
None,
|
||||
user_id,
|
||||
EventType::Direct,
|
||||
GlobalAccountDataEventType::Direct.to_string().into(),
|
||||
&direct_event,
|
||||
&db.globals,
|
||||
)?;
|
||||
@@ -2322,7 +2340,9 @@ pub fn update_membership(
|
||||
.get::<IgnoredUserListEvent>(
|
||||
None, // Ignored users are in global account data
|
||||
user_id, // Receiver
|
||||
EventType::IgnoredUserList,
|
||||
GlobalAccountDataEventType::IgnoredUserList
|
||||
.to_string()
|
||||
.into(),
|
||||
)?
|
||||
.map_or(false, |ignored| {
|
||||
ignored
|
||||
@@ -2578,7 +2598,7 @@ pub async fn leave_room(
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
let mut event: RoomMemberEventContent = serde_json::from_str(
|
||||
self.room_state_get(room_id, &EventType::RoomMember, user_id.as_str())?
|
||||
self.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::BadState,
|
||||
"Cannot leave a room you are not a member of.",
|
||||
@@ -2592,7 +2612,7 @@ pub async fn leave_room(
|
||||
|
||||
self.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
event_type: RoomEventType::RoomMember,
|
||||
content: to_raw_value(&event).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some(user_id.to_string()),
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
OutgoingRequest,
|
||||
},
|
||||
device_id,
|
||||
events::{push_rules::PushRulesEvent, AnySyncEphemeralRoomEvent, EventType},
|
||||
events::{
|
||||
push_rules::PushRulesEvent, AnySyncEphemeralRoomEvent, EventType,
|
||||
GlobalAccountDataEventType,
|
||||
},
|
||||
push,
|
||||
receipt::ReceiptType,
|
||||
uint, MilliSecondsSinceUnixEpoch, ServerName, UInt, UserId,
|
||||
@@ -635,7 +638,11 @@ async fn handle_events(
|
||||
|
||||
let rules_for_user = db
|
||||
.account_data
|
||||
.get(None, &userid, EventType::PushRules)
|
||||
.get(
|
||||
None,
|
||||
&userid,
|
||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||
)
|
||||
.unwrap_or_default()
|
||||
.map(|ev: PushRulesEvent| ev.content.global)
|
||||
.unwrap_or_else(|| push::Ruleset::server_default(&userid));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::Result;
|
||||
use ruma::{identifiers::TransactionId, DeviceId, UserId};
|
||||
use ruma::{DeviceId, TransactionId, UserId};
|
||||
|
||||
use super::abstraction::Tree;
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
use ruma::{
|
||||
api::client::{device::Device, error::ErrorKind, filter::IncomingFilterDefinition},
|
||||
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
|
||||
events::{AnyToDeviceEvent, EventType},
|
||||
identifiers::MxcUri,
|
||||
events::{AnyToDeviceEvent, StateEventType},
|
||||
serde::Raw,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, RoomAliasId, UInt,
|
||||
UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, MxcUri, RoomAliasId,
|
||||
UInt, UserId,
|
||||
};
|
||||
use std::{collections::BTreeMap, mem, sync::Arc};
|
||||
use tracing::warn;
|
||||
@@ -754,7 +753,7 @@ pub fn mark_device_key_update(
|
||||
for room_id in rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
||||
// Don't send key updates to unencrypted rooms
|
||||
if rooms
|
||||
.room_state_get(&room_id, &EventType::RoomEncryption, "")?
|
||||
.room_state_get(&room_id, &StateEventType::RoomEncryption, "")?
|
||||
.is_none()
|
||||
{
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user