feat(core): include user and member on Message events

This commit is contained in:
Paul Makles
2024-06-25 21:01:45 +01:00
parent ac20b6bc99
commit 1d5dae4751
11 changed files with 117 additions and 34 deletions

View File

@@ -377,6 +377,8 @@ impl Channel {
username: &user.username,
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
},
None,
None,
self,
false,
)
@@ -688,6 +690,8 @@ impl Channel {
username: name,
avatar: None,
},
None,
None,
self,
false,
)
@@ -723,6 +727,8 @@ impl Channel {
username: &user.username,
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
},
None,
None,
self,
false,
)

View File

@@ -213,6 +213,8 @@ impl Message {
channel: Channel,
data: DataMessageSend,
author: MessageAuthor<'_>,
user: Option<v0::User>,
member: Option<v0::Member>,
limits: FeaturesLimits,
mut idempotency: IdempotencyKey,
generate_embeds: bool,
@@ -362,7 +364,9 @@ impl Message {
message.nonce = Some(idempotency.into_key());
// Send the message
message.send(db, author, &channel, generate_embeds).await?;
message
.send(db, author, user, member, &channel, generate_embeds)
.await?;
Ok(message)
}
@@ -371,13 +375,15 @@ impl Message {
pub async fn send_without_notifications(
&mut self,
db: &Database,
user: Option<v0::User>,
member: Option<v0::Member>,
is_dm: bool,
generate_embeds: bool,
) -> Result<()> {
db.insert_message(self).await?;
// Fan out events
EventV1::Message(self.clone().into())
EventV1::Message(self.clone().into_model(user, member))
.p(self.channel.to_string())
.await;
@@ -418,11 +424,15 @@ impl Message {
&mut self,
db: &Database,
author: MessageAuthor<'_>,
user: Option<v0::User>,
member: Option<v0::Member>,
channel: &Channel,
generate_embeds: bool,
) -> Result<()> {
self.send_without_notifications(
db,
user,
member,
matches!(channel, Channel::DirectMessage { .. }),
generate_embeds,
)
@@ -438,7 +448,12 @@ impl Message {
_ => vec![],
}
},
PushNotification::from(self.clone().into(), Some(author), &channel.id()).await,
PushNotification::from(
self.clone().into_model(None, None),
Some(author),
&channel.id(),
)
.await,
)
.await;
@@ -500,7 +515,7 @@ impl Message {
.fetch_messages(query)
.await?
.into_iter()
.map(Into::into)
.map(|msg| msg.into_model(None, None))
.collect();
if let Some(true) = include_users {

View File

@@ -150,7 +150,7 @@ impl Member {
id: user.id.clone(),
}
.into_message(id.to_string())
.send_without_notifications(db, false, false)
.send_without_notifications(db, None, None, false, false)
.await
.ok();
}
@@ -250,7 +250,7 @@ impl Member {
}
.into_message(id.to_string())
// TODO: support notifications here in the future?
.send_without_notifications(db, false, false)
.send_without_notifications(db, None, None, false, false)
.await
.ok();
}