@@ -194,6 +194,11 @@ impl Message {
|
|||||||
with: "message",
|
with: "message",
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
// spawn task_queue ( process embeds )
|
||||||
|
if process_embeds {
|
||||||
|
self.process_embed().await;
|
||||||
|
}
|
||||||
|
|
||||||
// spawn task_queue ( update last_message_id )
|
// spawn task_queue ( update last_message_id )
|
||||||
match channel {
|
match channel {
|
||||||
Channel::DirectMessage { id, .. } =>
|
Channel::DirectMessage { id, .. } =>
|
||||||
@@ -203,40 +208,18 @@ impl Message {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// spawn task_queue ( process embeds )
|
|
||||||
|
|
||||||
// if mentions {
|
// if mentions {
|
||||||
// spawn task_queue ( update channel_unreads )
|
// spawn task_queue ( update channel_unreads )
|
||||||
// }
|
// }
|
||||||
|
/*if let Some(mentions) = &self.mentions {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
// if (channel => DM | Group) | mentions {
|
// if (channel => DM | Group) | mentions {
|
||||||
// spawn task_queue ( web push )
|
// spawn task_queue ( web push )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// ! FIXME: all this code is legitimately crap
|
|
||||||
// ! rewrite when can be asked
|
|
||||||
|
|
||||||
let ss = self.clone();
|
|
||||||
let c_clone = channel.clone();
|
|
||||||
async_std::task::spawn(async move {
|
|
||||||
|
|
||||||
let last_message_id = ss.id.clone();
|
|
||||||
let mut set = doc! { "last_message_id": last_message_id };
|
|
||||||
|
|
||||||
let channels = get_collection("channels");
|
|
||||||
match &c_clone {
|
|
||||||
Channel::DirectMessage { id, .. } => {
|
|
||||||
// ! MARK AS ACTIVE
|
|
||||||
set.insert("active", true);
|
|
||||||
update_channels_last_message(&channels, id, &set).await;
|
|
||||||
},
|
|
||||||
Channel::Group { id, .. } | Channel::TextChannel { id, .. } => {
|
|
||||||
update_channels_last_message(&channels, id, &set).await;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ! FIXME: also temp code
|
// ! FIXME: also temp code
|
||||||
// ! THIS ADDS ANY MENTIONS
|
// ! THIS ADDS ANY MENTIONS
|
||||||
@@ -269,10 +252,6 @@ impl Message {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if process_embeds {
|
|
||||||
self.process_embed();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentions = self.mentions.clone();
|
let mentions = self.mentions.clone();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -356,49 +335,18 @@ impl Message {
|
|||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
.publish(channel);
|
.publish(channel);
|
||||||
self.process_embed();
|
|
||||||
|
|
||||||
|
self.process_embed().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_embed(&self) {
|
pub async fn process_embed(&self) {
|
||||||
if !*USE_JANUARY {
|
if !*USE_JANUARY {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Content::Text(text) = &self.content {
|
if let Content::Text(text) = &self.content {
|
||||||
// ! FIXME: re-write this at some point,
|
crate::task_queue::task_process_embeds::queue(self.channel.clone(), self.id.clone(), text.clone()).await;
|
||||||
// ! or just before we allow user generated embeds
|
|
||||||
let id = self.id.clone();
|
|
||||||
let content = text.clone();
|
|
||||||
let channel = self.channel.clone();
|
|
||||||
async_std::task::spawn(async move {
|
|
||||||
if let Ok(embeds) = Embed::generate(content).await {
|
|
||||||
if let Ok(bson) = to_bson(&embeds) {
|
|
||||||
if let Ok(_) = get_collection("messages")
|
|
||||||
.update_one(
|
|
||||||
doc! {
|
|
||||||
"_id": &id
|
|
||||||
},
|
|
||||||
doc! {
|
|
||||||
"$set": {
|
|
||||||
"embeds": bson
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
ClientboundNotification::MessageUpdate {
|
|
||||||
id,
|
|
||||||
channel: channel.clone(),
|
|
||||||
data: json!({ "embeds": embeds }),
|
|
||||||
}
|
|
||||||
.publish(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
pub mod task_last_message_id;
|
pub mod task_last_message_id;
|
||||||
|
pub mod task_process_embeds;
|
||||||
|
|
||||||
pub async fn start_queues() {
|
pub async fn start_queues() {
|
||||||
async_std::task::spawn(task_last_message_id::run());
|
async_std::task::spawn(task_last_message_id::run());
|
||||||
|
async_std::task::spawn(task_process_embeds::run());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Queue Type: Debounced
|
||||||
use std::{collections::HashMap, time::{Duration, Instant}};
|
use std::{collections::HashMap, time::{Duration, Instant}};
|
||||||
|
|
||||||
use async_channel::{ Sender, Receiver, bounded };
|
use async_channel::{ Sender, Receiver, bounded };
|
||||||
|
|||||||
47
src/task_queue/task_process_embeds.rs
Normal file
47
src/task_queue/task_process_embeds.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Queue Type: Linear
|
||||||
|
use async_channel::{ Sender, Receiver, bounded };
|
||||||
|
use mongodb::bson::{doc, to_bson};
|
||||||
|
|
||||||
|
use crate::{database::*, notifications::events::ClientboundNotification};
|
||||||
|
|
||||||
|
type Message = (String, String, String);
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref CHANNEL: (Sender<Message>, Receiver<Message>) = bounded(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn queue(channel: String, id: String, content: String) {
|
||||||
|
CHANNEL.0.send((channel, id, content)).await.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run() {
|
||||||
|
let messages = get_collection("messages");
|
||||||
|
|
||||||
|
while let Ok((channel, id, content)) = CHANNEL.1.recv().await {
|
||||||
|
if let Ok(embeds) = Embed::generate(content).await {
|
||||||
|
if let Ok(bson) = to_bson(&embeds) {
|
||||||
|
if let Ok(_) = messages
|
||||||
|
.update_one(
|
||||||
|
doc! {
|
||||||
|
"_id": &id
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"embeds": bson
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
ClientboundNotification::MessageUpdate {
|
||||||
|
id,
|
||||||
|
channel: channel.clone(),
|
||||||
|
data: json!({ "embeds": embeds }),
|
||||||
|
}
|
||||||
|
.publish(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user