Add PduId wrapper struct

Death to Vec<u8>
This commit is contained in:
Lambda 2024-08-26 16:47:50 +00:00
parent 341f4213d0
commit 26322d5a95
15 changed files with 110 additions and 71 deletions

View file

@ -37,6 +37,7 @@ use tokio::{
};
use tracing::{debug, error, warn, Span};
use super::rooms::timeline::PduId;
use crate::{
api::{appservice_server, server_server},
services,
@ -83,7 +84,7 @@ impl Destination {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) enum SendingEventType {
// pduid
Pdu(Vec<u8>),
Pdu(PduId),
// pdu json
Edu(Vec<u8>),
}
@ -565,7 +566,7 @@ impl Service {
#[tracing::instrument(skip(self, pdu_id, user, pushkey))]
pub(crate) fn send_push_pdu(
&self,
pdu_id: &[u8],
pdu_id: &PduId,
user: &UserId,
pushkey: String,
) -> Result<()> {
@ -589,7 +590,7 @@ impl Service {
pub(crate) fn send_pdu<I: Iterator<Item = OwnedServerName>>(
&self,
servers: I,
pdu_id: &[u8],
pdu_id: &PduId,
) -> Result<()> {
let requests = servers
.into_iter()
@ -644,7 +645,7 @@ impl Service {
pub(crate) fn send_pdu_appservice(
&self,
appservice_id: String,
pdu_id: Vec<u8>,
pdu_id: PduId,
) -> Result<()> {
let destination = Destination::Appservice(appservice_id);
let event_type = SendingEventType::Pdu(pdu_id);
@ -758,8 +759,8 @@ async fn handle_appservice_event(
&events
.iter()
.map(|e| match e {
SendingEventType::Edu(b)
| SendingEventType::Pdu(b) => &**b,
SendingEventType::Edu(b) => &**b,
SendingEventType::Pdu(b) => b.as_bytes(),
})
.collect::<Vec<_>>(),
))
@ -905,8 +906,8 @@ async fn handle_federation_event(
&events
.iter()
.map(|e| match e {
SendingEventType::Edu(b)
| SendingEventType::Pdu(b) => &**b,
SendingEventType::Edu(b) => &**b,
SendingEventType::Pdu(b) => b.as_bytes(),
})
.collect::<Vec<_>>(),
))