mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
Messaging: Remove embed when editing message.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user