mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0870c8d647 | |||
| d0f00e6f5c |
Generated
+10
-10
@@ -771,7 +771,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_admin",
|
||||
@@ -800,7 +800,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_admin"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_api",
|
||||
@@ -821,7 +821,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_api"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -853,14 +853,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_build_metadata"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"built 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_core"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"arrayvec",
|
||||
@@ -919,7 +919,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_database"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"conduwuit_core",
|
||||
@@ -937,7 +937,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_macros"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"itertools 0.14.0",
|
||||
"proc-macro2",
|
||||
@@ -947,7 +947,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_router"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-client-ip",
|
||||
@@ -981,7 +981,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_service"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -1018,7 +1018,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_web"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"axum",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
||||
rust-version = "1.86.0"
|
||||
version = "0.5.0-rc.5"
|
||||
version = "0.5.0-rc.6"
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "conduwuit"
|
||||
|
||||
+6
-2
@@ -3,7 +3,7 @@
|
||||
"$id": "https://continwuity.org/schema/announcements.schema.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"updates": {
|
||||
"announcements": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
@@ -16,6 +16,10 @@
|
||||
},
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"mention_room": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to mention the room (@room) when posting this announcement"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -26,6 +30,6 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"updates"
|
||||
"announcements"
|
||||
]
|
||||
}
|
||||
@@ -20,7 +20,7 @@ use std::{sync::Arc, time::Duration};
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{Result, Server, debug, info, warn};
|
||||
use database::{Deserialized, Map};
|
||||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
use ruma::events::{Mentions, room::message::RoomMessageEventContent};
|
||||
use serde::Deserialize;
|
||||
use tokio::{
|
||||
sync::Notify,
|
||||
@@ -53,6 +53,8 @@ struct CheckForAnnouncementsResponseEntry {
|
||||
id: u64,
|
||||
date: Option<String>,
|
||||
message: String,
|
||||
#[serde(default, skip_serializing_if = "bool::not")]
|
||||
mention_room: bool,
|
||||
}
|
||||
|
||||
const CHECK_FOR_ANNOUNCEMENTS_URL: &str =
|
||||
@@ -139,19 +141,20 @@ impl Service {
|
||||
} else {
|
||||
info!("[announcements] {:#}", announcement.message);
|
||||
}
|
||||
let mut message = RoomMessageEventContent::text_markdown(format!(
|
||||
"### New announcement{}\n\n{}",
|
||||
announcement
|
||||
.date
|
||||
.as_ref()
|
||||
.map_or_else(String::new, |date| format!(" - `{date}`")),
|
||||
announcement.message
|
||||
));
|
||||
|
||||
self.services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::text_markdown(format!(
|
||||
"### New announcement{}\n\n{}",
|
||||
announcement
|
||||
.date
|
||||
.as_ref()
|
||||
.map_or_else(String::new, |date| format!(" - `{date}`")),
|
||||
announcement.message
|
||||
)))
|
||||
.await
|
||||
.ok();
|
||||
if announcement.mention_room {
|
||||
message = message.add_mentions(Mentions::with_room_mention());
|
||||
}
|
||||
|
||||
self.services.admin.send_message(message).await.ok();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod data;
|
||||
|
||||
use std::{collections::{BTreeMap, HashMap}, sync::Arc};
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use conduwuit::{
|
||||
Result, debug, err,
|
||||
@@ -9,9 +9,12 @@ use conduwuit::{
|
||||
};
|
||||
use futures::{Stream, TryFutureExt, try_join};
|
||||
use ruma::{
|
||||
OwnedEventId, OwnedUserId, RoomId, UserId,
|
||||
events::{
|
||||
receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType, Receipts}, AnySyncEphemeralRoomEvent, SyncEphemeralRoomEvent
|
||||
}, serde::Raw, OwnedEventId, OwnedUserId, RoomId, UserId
|
||||
AnySyncEphemeralRoomEvent, SyncEphemeralRoomEvent,
|
||||
receipt::{ReceiptEvent, ReceiptEventContent, Receipts},
|
||||
},
|
||||
serde::Raw,
|
||||
};
|
||||
|
||||
use self::data::{Data, ReceiptItem};
|
||||
@@ -44,48 +47,19 @@ impl crate::Service for Service {
|
||||
}
|
||||
|
||||
impl Service {
|
||||
/// Updates the public read receipt (`m.read`) based on the incoming event.
|
||||
/// If the event referenced by the new public receipt is newer than the current
|
||||
/// private read marker (`m.read.private`), the private marker is also updated
|
||||
/// to match the public receipt's position.
|
||||
/// Replaces the previous read receipt.
|
||||
pub async fn readreceipt_update(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
event: &ReceiptEvent,
|
||||
) {
|
||||
debug!(target: "readreceipt", %room_id, %user_id, "Updating read receipt in database.");
|
||||
|
||||
// 2. Find the maximum PDU count for the m.read event(s) referenced in the new receipt
|
||||
let mut max_new_public_pdu_count: Option<PduCount> = None;
|
||||
for (event_id, receipts) in event.content.0.iter() {
|
||||
// Check if this event_id has an m.read receipt for the target user
|
||||
if let Some(user_receipts) = receipts.get(&ReceiptType::Read) {
|
||||
if user_receipts.contains_key(user_id) {
|
||||
// Try to get the PDU count (timeline position) for this event_id
|
||||
match self.services.timeline.get_pdu_count(event_id).await {
|
||||
Ok(count) => {
|
||||
// Update the maximum count found so far
|
||||
let current_max = max_new_public_pdu_count.unwrap_or(PduCount::Normal(0));
|
||||
max_new_public_pdu_count = Some(current_max.max(count));
|
||||
debug!(target: "readreceipt", %room_id, %user_id, %event_id, count, "Found PDU count for new public receipt event.");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
target: "readreceipt", %room_id, %user_id, %event_id,
|
||||
"Failed to get PDU count for event ID from new public read receipt: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Flush the sending queue for the room to notify clients
|
||||
if let Err(e) = self.services.sending.flush_room(room_id).await {
|
||||
warn!(target: "readreceipt", %room_id, %user_id, "Failed to flush room after read receipt update: {}", e);
|
||||
}
|
||||
self.db.readreceipt_update(user_id, room_id, event).await;
|
||||
self.services
|
||||
.sending
|
||||
.flush_room(room_id)
|
||||
.await
|
||||
.expect("room flush failed");
|
||||
}
|
||||
|
||||
/// Gets the latest private read receipt from the user in the room
|
||||
|
||||
Reference in New Issue
Block a user