Messaging: Remove embed when editing message.
This commit is contained in:
@@ -268,7 +268,7 @@ impl Message {
|
|||||||
ClientboundNotification::MessageUpdate {
|
ClientboundNotification::MessageUpdate {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
channel: self.channel.clone(),
|
channel: self.channel.clone(),
|
||||||
data,
|
data
|
||||||
}
|
}
|
||||||
.publish(channel);
|
.publish(channel);
|
||||||
self.process_embed();
|
self.process_embed();
|
||||||
@@ -282,6 +282,8 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Content::Text(text) = &self.content {
|
if let Content::Text(text) = &self.content {
|
||||||
|
// ! FIXME: re-write this at some point,
|
||||||
|
// ! or just before we allow user generated embeds
|
||||||
let id = self.id.clone();
|
let id = self.id.clone();
|
||||||
let content = text.clone();
|
let content = text.clone();
|
||||||
let channel = self.channel.clone();
|
let channel = self.channel.clone();
|
||||||
@@ -305,7 +307,7 @@ impl Message {
|
|||||||
ClientboundNotification::MessageUpdate {
|
ClientboundNotification::MessageUpdate {
|
||||||
id,
|
id,
|
||||||
channel: channel.clone(),
|
channel: channel.clone(),
|
||||||
data: json!({ "embeds": embeds }),
|
data: json!({ "embeds": embeds })
|
||||||
}
|
}
|
||||||
.publish(channel);
|
.publish(channel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub enum ClientboundNotification {
|
|||||||
MessageUpdate {
|
MessageUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
channel: String,
|
channel: String,
|
||||||
data: JsonValue,
|
data: JsonValue
|
||||||
},
|
},
|
||||||
MessageDelete {
|
MessageDelete {
|
||||||
id: String,
|
id: String,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use mongodb::bson::{doc, Bson, DateTime};
|
use mongodb::bson::{Bson, DateTime, Document, doc};
|
||||||
use rocket_contrib::json::Json;
|
use rocket_contrib::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
@@ -33,16 +33,37 @@ pub async fn req(user: User, target: Ref, msg: Ref, edit: Json<Data>) -> Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
let edited = Utc::now();
|
let edited = Utc::now();
|
||||||
|
let mut set = doc! {
|
||||||
|
"content": &edit.content,
|
||||||
|
"edited": Bson::DateTime(edited)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut update = json!({ "content": edit.content, "edited": DateTime(edited) });
|
||||||
|
|
||||||
|
if let Some(embeds) = &message.embeds {
|
||||||
|
let new_embeds: Vec<Document> = vec![];
|
||||||
|
|
||||||
|
for embed in embeds {
|
||||||
|
match embed {
|
||||||
|
Embed::Website(_) |
|
||||||
|
Embed::Image(_) |
|
||||||
|
Embed::None => { }
|
||||||
|
// Otherwise push to new_embeds.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let obj = update.as_object_mut().unwrap();
|
||||||
|
obj.insert("embeds".to_string(), json!(new_embeds).0);
|
||||||
|
set.insert("embeds", new_embeds);
|
||||||
|
}
|
||||||
|
|
||||||
get_collection("messages")
|
get_collection("messages")
|
||||||
.update_one(
|
.update_one(
|
||||||
doc! {
|
doc! {
|
||||||
"_id": &message.id
|
"_id": &message.id
|
||||||
},
|
},
|
||||||
doc! {
|
doc! {
|
||||||
"$set": {
|
"$set": set
|
||||||
"content": &edit.content,
|
|
||||||
"edited": Bson::DateTime(edited)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@@ -53,6 +74,6 @@ pub async fn req(user: User, target: Ref, msg: Ref, edit: Json<Data>) -> Result<
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
message
|
message
|
||||||
.publish_update(json!({ "content": edit.content, "edited": DateTime(edited) }))
|
.publish_update(update)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user