feat: implement idempotency tokens

closes #108 and closes #106
This commit is contained in:
Paul
2021-11-01 18:32:45 +00:00
parent 49c7bc0ffe
commit 8d25dd1d65
12 changed files with 146 additions and 109 deletions

View File

@@ -33,8 +33,6 @@ pub enum Channel {
Group {
#[serde(rename = "_id")]
id: String,
#[serde(skip_serializing_if = "Option::is_none")]
nonce: Option<String>,
name: String,
owner: String,
@@ -57,8 +55,6 @@ pub enum Channel {
#[serde(rename = "_id")]
id: String,
server: String,
#[serde(skip_serializing_if = "Option::is_none")]
nonce: Option<String>,
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -81,8 +77,6 @@ pub enum Channel {
#[serde(rename = "_id")]
id: String,
server: String,
#[serde(skip_serializing_if = "Option::is_none")]
nonce: Option<String>,
name: String,
#[serde(skip_serializing_if = "Option::is_none")]

View File

@@ -181,6 +181,20 @@ impl Message {
}
pub async fn publish(self, channel: &Channel, process_embeds: bool) -> Result<()> {
// construct message and publish
// commit message to database
// spawn task_queue ( update last_message_id )
// spawn task_queue ( process embeds )
// if mentions {
// spawn task_queue ( update channel_unreads )
// }
// if (channel => DM | Group) | mentions {
// spawn task_queue ( web push )
// }
get_collection("messages")
.insert_one(to_bson(&self).unwrap().as_document().unwrap().clone(), None)
.await

View File

@@ -85,8 +85,6 @@ pub enum RemoveMember {
pub struct Server {
#[serde(rename = "_id")]
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub nonce: Option<String>,
pub owner: String,
pub name: String,

View File

@@ -342,6 +342,36 @@ pub async fn run_migrations(revision: i32) -> i32 {
}
}
if revision <= 10 {
info!("Running migration [revision 10 / 2021-11-01]: Remove nonce values on channels and servers.");
get_collection("servers")
.update_many(
doc! {},
doc! {
"$unset": {
"nonce": 1,
}
},
None
)
.await
.unwrap();
get_collection("channels")
.update_many(
doc! {},
doc! {
"$unset": {
"nonce": 1,
}
},
None
)
.await
.unwrap();
}
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
// Reminder to update LATEST_REVISION when adding new migrations.