Skip to content
Snippets Groups Projects
Commit bad90245 authored by insert's avatar insert
Browse files

Messaging: Remove embed when editing message.

parent 6d67b3f7
No related merge requests found
......@@ -268,7 +268,7 @@ impl Message {
ClientboundNotification::MessageUpdate {
id: self.id.clone(),
channel: self.channel.clone(),
data,
data
}
.publish(channel);
self.process_embed();
......@@ -282,6 +282,8 @@ impl Message {
}
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 content = text.clone();
let channel = self.channel.clone();
......@@ -305,7 +307,7 @@ impl Message {
ClientboundNotification::MessageUpdate {
id,
channel: channel.clone(),
data: json!({ "embeds": embeds }),
data: json!({ "embeds": embeds })
}
.publish(channel);
}
......
......@@ -70,7 +70,7 @@ pub enum ClientboundNotification {
MessageUpdate {
id: String,
channel: String,
data: JsonValue,
data: JsonValue
},
MessageDelete {
id: String,
......
......@@ -2,7 +2,7 @@ use crate::database::*;
use crate::util::result::{Error, Result};
use chrono::Utc;
use mongodb::bson::{doc, Bson, DateTime};
use mongodb::bson::{Bson, DateTime, Document, doc};
use rocket_contrib::json::Json;
use serde::{Deserialize, Serialize};
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 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")
.update_one(
doc! {
"_id": &message.id
},
doc! {
"$set": {
"content": &edit.content,
"edited": Bson::DateTime(edited)
}
"$set": set
},
None,
)
......@@ -53,6 +74,6 @@ pub async fn req(user: User, target: Ref, msg: Ref, edit: Json<Data>) -> Result<
})?;
message
.publish_update(json!({ "content": edit.content, "edited": DateTime(edited) }))
.publish_update(update)
.await
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment