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,39 +107,30 @@ impl Message {
with: "message", with: "message",
})?; })?;
let mut set = if let Content::Text(text) = &self.content { // ! FIXME: all this code is legitimately crap
doc! { // ! rewrite when can be asked
"last_message": {
"_id": self.id.clone(),
"author": self.author.clone(),
"short": text.chars().take(128).collect::<String>()
}
}
} else {
doc! {}
};
// ! FIXME: temp code let ss = self.clone();
let channels = get_collection("channels"); let c_clone = channel.clone();
match &channel { async_std::task::spawn(async move {
Channel::DirectMessage { id, .. } => { let mut set = if let Content::Text(text) = &ss.content {
set.insert("active", true); doc! {
channels "last_message": {
.update_one( "_id": ss.id.clone(),
doc! { "_id": id }, "author": ss.author.clone(),
doc! { "short": text.chars().take(128).collect::<String>()
"$set": set }
}, }
None, } else {
) doc! {}
.await };
.map_err(|_| Error::DatabaseError {
operation: "update_one", // ! MARK AS ACTIVE
with: "channel", // ! FIXME: temp code
})?; let channels = get_collection("channels");
} match &c_clone {
Channel::Group { id, .. } => { Channel::DirectMessage { id, .. } => {
if let Content::Text(_) = &self.content { set.insert("active", true);
channels channels
.update_one( .update_one(
doc! { "_id": id }, doc! { "_id": id },
@@ -149,32 +140,83 @@ 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::TextChannel { id, .. } => { if let Content::Text(_) = &ss.content {
if let Content::Text(_) = &self.content { channels
channels .update_one(
.update_one( doc! { "_id": id },
doc! { "_id": id }, doc! {
doc! { "$set": set
"$set": { },
"last_message": &self.id None,
} )
}, .await
None, /*.map_err(|_| Error::DatabaseError {
) operation: "update_one",
.await with: "channel",
.map_err(|_| Error::DatabaseError { })?;*/
operation: "update_one", .unwrap();
with: "channel", }
})?;
} }
Channel::TextChannel { id, .. } => {
if let Content::Text(_) = &ss.content {
channels
.update_one(
doc! { "_id": id },
doc! {
"$set": {
"last_message": &ss.id
}
},
None,
)
.await
/*.map_err(|_| Error::DatabaseError {
operation: "update_one",
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,23 +226,22 @@ impl Message {
/* /*
Web Push Test Code Web Push Test Code
! FIXME: temp code
*/ */
let c_clone = channel.clone();
// Find all offline users. async_std::task::spawn(async move {
let mut target_ids = vec![]; // Find all offline users.
match &channel { let mut target_ids = vec![];
Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => { match &c_clone {
for recipient in recipients { Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => {
if !is_online(recipient) { for recipient in recipients {
target_ids.push(recipient.clone()); if !is_online(recipient) {
target_ids.push(recipient.clone());
}
} }
} }
_ => {}
} }
_ => {}
}
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";