fix: migration and push edu bugs

This commit is contained in:
Timo Kösters 2021-07-30 18:05:26 +02:00
parent 5df6b8cd5f
commit dc85a8fafd
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 23 additions and 27 deletions

6
Cargo.lock generated
View file

@ -944,7 +944,7 @@ dependencies = [
[[package]] [[package]]
name = "heed" name = "heed"
version = "0.10.6" version = "0.10.6"
source = "git+https://github.com/timokoesters/heed.git?rev=c6b149fd5621999b0d5ef0c28e199015cfc60fa1#c6b149fd5621999b0d5ef0c28e199015cfc60fa1" source = "git+https://github.com/timokoesters/heed.git?rev=f6f825da7fb2c758867e05ad973ef800a6fe1d5d#f6f825da7fb2c758867e05ad973ef800a6fe1d5d"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"byteorder", "byteorder",
@ -962,12 +962,12 @@ dependencies = [
[[package]] [[package]]
name = "heed-traits" name = "heed-traits"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/timokoesters/heed.git?rev=c6b149fd5621999b0d5ef0c28e199015cfc60fa1#c6b149fd5621999b0d5ef0c28e199015cfc60fa1" source = "git+https://github.com/timokoesters/heed.git?rev=f6f825da7fb2c758867e05ad973ef800a6fe1d5d#f6f825da7fb2c758867e05ad973ef800a6fe1d5d"
[[package]] [[package]]
name = "heed-types" name = "heed-types"
version = "0.7.2" version = "0.7.2"
source = "git+https://github.com/timokoesters/heed.git?rev=c6b149fd5621999b0d5ef0c28e199015cfc60fa1#c6b149fd5621999b0d5ef0c28e199015cfc60fa1" source = "git+https://github.com/timokoesters/heed.git?rev=f6f825da7fb2c758867e05ad973ef800a6fe1d5d#f6f825da7fb2c758867e05ad973ef800a6fe1d5d"
dependencies = [ dependencies = [
"bincode", "bincode",
"bytemuck", "bytemuck",

View file

@ -430,8 +430,8 @@ impl Database {
// Upgrade user data store // Upgrade user data store
for (roomuserdataid, _) in db.account_data.roomuserdataid_accountdata.iter() { for (roomuserdataid, _) in db.account_data.roomuserdataid_accountdata.iter() {
let mut parts = roomuserdataid.split(|&b| b == 0xff); let mut parts = roomuserdataid.split(|&b| b == 0xff);
let user_id = parts.next().unwrap();
let room_id = parts.next().unwrap(); let room_id = parts.next().unwrap();
let user_id = parts.next().unwrap();
let event_type = roomuserdataid.rsplit(|&b| b == 0xff).next().unwrap(); let event_type = roomuserdataid.rsplit(|&b| b == 0xff).next().unwrap();
let mut key = room_id.to_vec(); let mut key = room_id.to_vec();

View file

@ -599,8 +599,7 @@ impl Sending {
match event { match event {
SendingEventType::Pdu(pdu_id) => { SendingEventType::Pdu(pdu_id) => {
// TODO: check room version and remove event_id if needed // TODO: check room version and remove event_id if needed
pdu_jsons.push(serde_json::from_str( let raw = PduEvent::convert_to_outgoing_federation_event(
PduEvent::convert_to_outgoing_federation_event(
db.rooms db.rooms
.get_pdu_json_from_id(&pdu_id) .get_pdu_json_from_id(&pdu_id)
.map_err(|e| (OutgoingKind::Normal(server.clone()), e))? .map_err(|e| (OutgoingKind::Normal(server.clone()), e))?
@ -612,16 +611,13 @@ impl Sending {
), ),
) )
})?, })?,
) );
.json() pdu_jsons.push(raw);
.get(),
)
.expect("Raw<..> is always valid"));
} }
SendingEventType::Edu(edu) => { SendingEventType::Edu(edu) => {
edu_jsons.push( if let Ok(raw) = serde_json::from_slice(edu) {
serde_json::from_slice(edu).expect("Raw<..> is always valid"), edu_jsons.push(raw);
); }
} }
} }
} }
@ -689,7 +685,7 @@ impl Sending {
Error::bad_database("Invalid server string in server_currenttransaction") Error::bad_database("Invalid server string in server_currenttransaction")
})?), })?),
if event.starts_with(b"*") { if event.starts_with(b"*") {
SendingEventType::Edu(value.to_vec()) SendingEventType::Edu(value)
} else { } else {
SendingEventType::Pdu(event.to_vec()) SendingEventType::Pdu(event.to_vec())
}, },
@ -707,7 +703,7 @@ impl Sending {
( (
OutgoingKind::Push(user.to_vec(), pushkey.to_vec()), OutgoingKind::Push(user.to_vec(), pushkey.to_vec()),
if event.starts_with(b"*") { if event.starts_with(b"*") {
SendingEventType::Edu(event[1..].to_vec()) SendingEventType::Edu(value)
} else { } else {
SendingEventType::Pdu(event.to_vec()) SendingEventType::Pdu(event.to_vec())
}, },