Messaging: Add mentions to unread object.

This commit is contained in:
Paul
2021-06-17 14:42:48 +01:00
parent 4727f997ed
commit b10d4f3559
3 changed files with 109 additions and 68 deletions

View File

@@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
export version=0.5.0-alpha.3 export version=0.5.0-alpha.4
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs echo "pub const VERSION: &str = \"${version}\";" > src/version.rs

View File

@@ -107,11 +107,17 @@ impl Message {
with: "message", with: "message",
})?; })?;
let mut set = if let Content::Text(text) = &self.content { // ! 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 mut set = if let Content::Text(text) = &ss.content {
doc! { doc! {
"last_message": { "last_message": {
"_id": self.id.clone(), "_id": ss.id.clone(),
"author": self.author.clone(), "author": ss.author.clone(),
"short": text.chars().take(128).collect::<String>() "short": text.chars().take(128).collect::<String>()
} }
} }
@@ -119,9 +125,10 @@ impl Message {
doc! {} doc! {}
}; };
// ! MARK AS ACTIVE
// ! FIXME: temp code // ! FIXME: temp code
let channels = get_collection("channels"); let channels = get_collection("channels");
match &channel { match &c_clone {
Channel::DirectMessage { id, .. } => { Channel::DirectMessage { id, .. } => {
set.insert("active", true); set.insert("active", true);
channels channels
@@ -133,13 +140,14 @@ impl Message {
None, None,
) )
.await .await
.map_err(|_| Error::DatabaseError { /*.map_err(|_| Error::DatabaseError {
operation: "update_one", operation: "update_one",
with: "channel", with: "channel",
})?; })?;*/
.unwrap();
} }
Channel::Group { id, .. } => { Channel::Group { id, .. } => {
if let Content::Text(_) = &self.content { if let Content::Text(_) = &ss.content {
channels channels
.update_one( .update_one(
doc! { "_id": id }, doc! { "_id": id },
@@ -149,33 +157,67 @@ impl Message {
None, None,
) )
.await .await
.map_err(|_| Error::DatabaseError { /*.map_err(|_| Error::DatabaseError {
operation: "update_one", operation: "update_one",
with: "channel", with: "channel",
})?; })?;*/
.unwrap();
} }
} }
Channel::TextChannel { id, .. } => { Channel::TextChannel { id, .. } => {
if let Content::Text(_) = &self.content { if let Content::Text(_) = &ss.content {
channels channels
.update_one( .update_one(
doc! { "_id": id }, doc! { "_id": id },
doc! { doc! {
"$set": { "$set": {
"last_message": &self.id "last_message": &ss.id
} }
}, },
None, None,
) )
.await .await
.map_err(|_| Error::DatabaseError { /*.map_err(|_| Error::DatabaseError {
operation: "update_one", operation: "update_one",
with: "channel", with: "channel",
})?; })?;*/
.unwrap();
} }
} }
_ => {} _ => {}
} }
});
// ! FIXME: also temp code
// ! THIS ADDS ANY MENTIONS
if let Some(mentions) = &self.mentions {
let message = self.id.clone();
let channel = self.channel.clone();
let mentions = mentions.clone();
async_std::task::spawn(async move {
get_collection("channel_unreads")
.update_many(
doc! {
"_id.channel": channel,
"_id.user": {
"$in": mentions
}
},
doc! {
"$push": {
"mentions": message
}
},
None
)
.await
/*.map_err(|_| Error::DatabaseError {
operation: "update_many",
with: "channel_unreads",
})?;*/
.unwrap();
});
}
self.process_embed(); self.process_embed();
@@ -184,12 +226,12 @@ impl Message {
/* /*
Web Push Test Code Web Push Test Code
! FIXME: temp code
*/ */
let c_clone = channel.clone();
async_std::task::spawn(async move {
// Find all offline users. // Find all offline users.
let mut target_ids = vec![]; let mut target_ids = vec![];
match &channel { match &c_clone {
Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => { Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => {
for recipient in recipients { for recipient in recipients {
if !is_online(recipient) { if !is_online(recipient) {
@@ -200,7 +242,6 @@ impl Message {
_ => {} _ => {}
} }
async_std::task::spawn(async move {
// Fetch their corresponding sessions. // Fetch their corresponding sessions.
if let Ok(mut cursor) = get_collection("accounts") if let Ok(mut cursor) = get_collection("accounts")
.find( .find(

View File

@@ -1 +1 @@
pub const VERSION: &str = "0.5.0-alpha.3"; pub const VERSION: &str = "0.5.0-alpha.4";