mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-08 20:16:54 +00:00
Compare commits
9 Commits
v0.11.5
...
fix/hosepi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
805f2c4528 | ||
|
|
5a6155fdb6 | ||
|
|
c5844b6281 | ||
|
|
24d0d2b726 | ||
|
|
f777e2863c | ||
|
|
a80ad1cbe5 | ||
|
|
0b522ebddc | ||
|
|
6bd045eb79 | ||
|
|
0698e115e8 |
147
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
147
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
name: Bug Report
|
||||
description: Report a bug in Stoat — please fill out every required field to help us triage quickly.
|
||||
title: "[Bug]: "
|
||||
labels:
|
||||
- bug
|
||||
- unconfirmed
|
||||
|
||||
body:
|
||||
# ── Thank you section ────────────────────────────────────────────────────────
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**Thank you for taking the time to report a bug for Stoat!**
|
||||
|
||||
Please follow the instructions below and provide as much detail as possible to help us understand and reproduce the issue.
|
||||
|
||||
# ── Pre-flight checks ────────────────────────────────────────────────────────
|
||||
- type: checkboxes
|
||||
id: preflight
|
||||
attributes:
|
||||
label: Pre-flight checklist
|
||||
description: Please confirm all of the following before submitting.
|
||||
options:
|
||||
- label: I am on the latest available version of Stoat.
|
||||
required: true
|
||||
- label: I searched existing issues and did not find a duplicate.
|
||||
required: true
|
||||
- label: This is a bug report, not a support question or feature request.
|
||||
required: true
|
||||
|
||||
# ── Bug description ──────────────────────────────────────────────────────────
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Bug description
|
||||
description: >
|
||||
What happened? What did you expect to happen instead?
|
||||
Keep this brief — detailed steps go in the next field.
|
||||
placeholder: "Example: When I open a DM thread, new messages from the other person do not appear unless I reload the page."
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Steps to reproduce ───────────────────────────────────────────────────────
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: >
|
||||
Provide a numbered list of every step needed to trigger the bug.
|
||||
The clearer this is, the faster we can fix it.
|
||||
placeholder: |
|
||||
1. Log in to Stoat on the web client.
|
||||
2. Open a direct message conversation.
|
||||
3. Ask the other person to send a message.
|
||||
4. Observe that the message does not appear without reloading.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Expected behavior ────────────────────────────────────────────────────────
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: What should have happened?
|
||||
placeholder: "New messages should appear in real time without a page reload."
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Client / platform ────────────────────────────────────────────────────────
|
||||
- type: dropdown
|
||||
id: platform
|
||||
attributes:
|
||||
label: Client / platform
|
||||
description: Which Stoat client are you using?
|
||||
options:
|
||||
- Web (browser)
|
||||
- Stoat for Desktop
|
||||
- Android
|
||||
- iOS
|
||||
- Self-hosted server
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Client version ───────────────────────────────────────────────────────────
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Client version
|
||||
description: >
|
||||
Find this in **Settings**. For the web client, include the build
|
||||
number shown in the footer or About page.
|
||||
placeholder: "e.g. Stoat for Desktop 1.3.0 or 0.2.1 (2025-10-10)"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── OS / browser details ─────────────────────────────────────────────────────
|
||||
- type: input
|
||||
id: os
|
||||
attributes:
|
||||
label: OS / browser details
|
||||
description: Your operating system and, for web bugs, your browser and its version.
|
||||
placeholder: "e.g. Windows 11, Chrome 121 or macOS 14.3, Stoat for Desktop 1.3.0 or Android 14"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Reproducibility ──────────────────────────────────────────────────────────
|
||||
- type: dropdown
|
||||
id: reproducibility
|
||||
attributes:
|
||||
label: Reproducibility
|
||||
description: How consistently does this bug occur?
|
||||
options:
|
||||
- Always
|
||||
- Usually
|
||||
- Rarely
|
||||
- Only once
|
||||
- Unknown
|
||||
validations:
|
||||
required: true
|
||||
|
||||
# ── Screenshots or video ─────────────────────────────────────────────────────
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: Screenshots or video
|
||||
description: Paste images or drag-and-drop a screen recording here. GitHub accepts common image and video formats.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
# ── Additional context ───────────────────────────────────────────────────────
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: >
|
||||
Anything else that might help: workarounds you found, links to related issues,
|
||||
self-hosted configuration details (Redis, MongoDB, LiveKit, SMTP), network environment, etc.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
# ── Closing note ─────────────────────────────────────────────────────────────
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
---
|
||||
A maintainer will review your report. Please watch for follow-up questions — issues
|
||||
that go unanswered are harder to resolve and may be closed after 30 days of inactivity.
|
||||
2
.github/workflows/release-webhook.yml
vendored
2
.github/workflows/release-webhook.yml
vendored
@@ -20,4 +20,4 @@ jobs:
|
||||
RELEASE_URL="https://github.com/${REPOSITORY}/releases/tag/${TAG_NAME}"
|
||||
curl -X POST "$WEBHOOK_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"content\": \"$RELEASE_URL\"}"
|
||||
-d "{\"content\": \"$RELEASE_URL\"}"
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -6838,8 +6838,10 @@ dependencies = [
|
||||
name = "revolt-bonfire"
|
||||
version = "0.11.5"
|
||||
dependencies = [
|
||||
"amqprs",
|
||||
"async-channel 2.5.0",
|
||||
"async-std",
|
||||
"async-trait",
|
||||
"async-tungstenite",
|
||||
"authifier",
|
||||
"bincode",
|
||||
|
||||
@@ -36,6 +36,7 @@ async-std = { version = "1.8.0", features = [
|
||||
"tokio02",
|
||||
"attributes",
|
||||
] }
|
||||
async-trait = "0.1.89"
|
||||
|
||||
# core
|
||||
authifier = { version = "1.0.16" }
|
||||
@@ -48,3 +49,6 @@ revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||
|
||||
# redis
|
||||
fred = { version = "8.0.1", features = ["subscriber-client"] }
|
||||
|
||||
# Redis
|
||||
amqprs = { version = "1.7.0" }
|
||||
@@ -1,6 +1,18 @@
|
||||
use std::env;
|
||||
|
||||
use amqprs::{
|
||||
channel::{
|
||||
BasicConsumeArguments, Channel, ExchangeDeclareArguments, QueueBindArguments,
|
||||
QueueDeclareArguments,
|
||||
},
|
||||
connection::{Connection, OpenConnectionArguments},
|
||||
consumer::AsyncConsumer,
|
||||
BasicProperties, Deliver,
|
||||
};
|
||||
use async_std::net::TcpListener;
|
||||
use async_trait::async_trait;
|
||||
use redis_kiss::AsyncCommands;
|
||||
use revolt_database::util::rabbit::set_rabbitmq_connection;
|
||||
use revolt_presence::clear_region;
|
||||
|
||||
#[macro_use]
|
||||
@@ -31,6 +43,55 @@ async fn main() {
|
||||
let try_socket = TcpListener::bind(bind).await;
|
||||
let listener = try_socket.expect("Failed to bind");
|
||||
|
||||
let config = revolt_config::config().await;
|
||||
|
||||
let rmq_conn = Connection::open(&OpenConnectionArguments::new(
|
||||
&config.rabbit.host,
|
||||
config.rabbit.port,
|
||||
&config.rabbit.username,
|
||||
&config.rabbit.password,
|
||||
))
|
||||
.await
|
||||
.expect("Failed to connect to RabbitMQ");
|
||||
|
||||
set_rabbitmq_connection(rmq_conn.clone());
|
||||
|
||||
if std::env::var("ENABLE_RABBITMQ_INGRESS").as_deref().is_ok_and(|v| v == "1") {
|
||||
let channel = rmq_conn
|
||||
.open_channel(None)
|
||||
.await
|
||||
.expect("Failed to open RabbitMQ channel.");
|
||||
|
||||
channel
|
||||
.exchange_declare(
|
||||
ExchangeDeclareArguments::new("events", "fanout")
|
||||
.durable(true)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to declare exchange");
|
||||
|
||||
channel
|
||||
.queue_declare(QueueDeclareArguments::new("events").durable(true).finish())
|
||||
.await
|
||||
.expect("Failed to declare queue");
|
||||
|
||||
channel
|
||||
.queue_bind(QueueBindArguments::new("events", "events", "events"))
|
||||
.await
|
||||
.expect("Failed to bind queue");
|
||||
|
||||
channel
|
||||
.basic_consume(
|
||||
RabbitToRedisConsumer,
|
||||
BasicConsumeArguments::new("events", "")
|
||||
.manual_ack(false)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to consume channel");
|
||||
}
|
||||
|
||||
// Start accepting new connections and spawn a client for each connection.
|
||||
while let Ok((stream, addr)) = listener.accept().await {
|
||||
async_std::task::spawn(async move {
|
||||
@@ -40,3 +101,32 @@ async fn main() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct RabbitToRedisConsumer;
|
||||
|
||||
#[async_trait]
|
||||
impl AsyncConsumer for RabbitToRedisConsumer {
|
||||
async fn consume(
|
||||
&mut self,
|
||||
_channel: &Channel,
|
||||
_deliver: Deliver,
|
||||
basic_properties: BasicProperties,
|
||||
content: Vec<u8>,
|
||||
) {
|
||||
let mut redis_conn = redis_kiss::get_connection()
|
||||
.await
|
||||
.expect("Failed to connect to Redis.");
|
||||
|
||||
let pubsub_channel = basic_properties
|
||||
.headers()
|
||||
.expect("No headers")
|
||||
.get(&"c".try_into().unwrap())
|
||||
.expect("No channel header")
|
||||
.to_string();
|
||||
|
||||
redis_conn
|
||||
.publish(pubsub_channel, content)
|
||||
.await
|
||||
.expect("failed to publish")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,30 +464,30 @@ async fn worker(
|
||||
|
||||
match payload {
|
||||
// disabled events
|
||||
// ClientMessage::BeginTyping { channel } => {
|
||||
// if !subscribed.read().await.contains(&channel) {
|
||||
// continue;
|
||||
// }
|
||||
ClientMessage::BeginTyping { channel } => {
|
||||
if !subscribed.read().await.contains(&channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// EventV1::ChannelStartTyping {
|
||||
// id: channel.clone(),
|
||||
// user: user_id.clone(),
|
||||
// }
|
||||
// .p(channel.clone())
|
||||
// .await;
|
||||
// }
|
||||
// ClientMessage::EndTyping { channel } => {
|
||||
// if !subscribed.read().await.contains(&channel) {
|
||||
// continue;
|
||||
// }
|
||||
EventV1::ChannelStartTyping {
|
||||
id: channel.clone(),
|
||||
user: user_id.clone(),
|
||||
}
|
||||
.p(channel.clone())
|
||||
.await;
|
||||
}
|
||||
ClientMessage::EndTyping { channel } => {
|
||||
if !subscribed.read().await.contains(&channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// EventV1::ChannelStopTyping {
|
||||
// id: channel.clone(),
|
||||
// user: user_id.clone(),
|
||||
// }
|
||||
// .p(channel.clone())
|
||||
// .await;
|
||||
// }
|
||||
EventV1::ChannelStopTyping {
|
||||
id: channel.clone(),
|
||||
user: user_id.clone(),
|
||||
}
|
||||
.p(channel.clone())
|
||||
.await;
|
||||
}
|
||||
ClientMessage::Subscribe { server_id } => {
|
||||
let mut servers = active_servers.lock().await;
|
||||
let has_item = servers.contains_key(&server_id);
|
||||
|
||||
@@ -244,7 +244,7 @@ voice_quality = 16000
|
||||
# Whether the user can use video streams in voice calls
|
||||
video = true
|
||||
|
||||
# Mamimum resolution (width, height) of video streams in voice calls
|
||||
# Maximum resolution (width, height) of video streams in voice calls
|
||||
video_resolution = [1080, 720]
|
||||
|
||||
# Minimum and maximum aspect ratio of video streams in voice calls
|
||||
@@ -283,8 +283,8 @@ voice_quality = 16000
|
||||
# Whether the user can use video streams in voice calls
|
||||
video = true
|
||||
|
||||
# Mamimum resolution (width, height) of video streams in voice calls
|
||||
video_resolution = [1080, 720]
|
||||
# Maximum resolution (width, height) of video streams in voice calls
|
||||
video_resolution = [1280, 720]
|
||||
|
||||
# Minimum and maximum aspect ratio of video streams in voice calls
|
||||
video_aspect_ratio = [0.3, 2.5]
|
||||
@@ -312,4 +312,4 @@ files = ""
|
||||
proxy = ""
|
||||
pushd = ""
|
||||
crond = ""
|
||||
gifbox = ""
|
||||
gifbox = ""
|
||||
|
||||
@@ -449,7 +449,7 @@ pub async fn config() -> Settings {
|
||||
let mut config = read().await.try_deserialize::<Settings>().unwrap();
|
||||
|
||||
// inject REDIS_URI for redis-kiss library
|
||||
if std::env::var("REDIS_URL").is_err() {
|
||||
if std::env::var("REDIS_URI").is_err() {
|
||||
std::env::set_var("REDIS_URI", config.database.redis.clone());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ use revolt_presence::filter_online;
|
||||
|
||||
use serde_json::to_string;
|
||||
|
||||
// TODO: move away from storing Connection and Channel to using thread local singletons - #659
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AMQP {
|
||||
#[allow(unused)]
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
use amqprs::{
|
||||
channel::{BasicPublishArguments},
|
||||
BasicProperties, FieldTable,
|
||||
};
|
||||
use authifier::AuthifierEvent;
|
||||
use revolt_result::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use revolt_models::v0::{
|
||||
AppendMessage, Channel, ChannelUnread, ChannelVoiceState, Emoji, FieldsChannel, FieldsMember, FieldsMessage, FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message, PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser, PartialUserVoiceState, PartialWebhook, PolicyChange, RemovalIntention, Report, Server, User, UserSettings, UserVoiceState, Webhook
|
||||
AppendMessage, Channel, ChannelUnread, ChannelVoiceState, Emoji, FieldsChannel, FieldsMember,
|
||||
FieldsMessage, FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey,
|
||||
Message, PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer,
|
||||
PartialUser, PartialUserVoiceState, PartialWebhook, PolicyChange, RemovalIntention, Report,
|
||||
Server, User, UserSettings, UserVoiceState, Webhook,
|
||||
};
|
||||
|
||||
use crate::Database;
|
||||
use crate::{util::rabbit::get_channel, Database};
|
||||
|
||||
/// Ping Packet
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -304,14 +312,23 @@ pub enum EventV1 {
|
||||
impl EventV1 {
|
||||
/// Publish helper wrapper
|
||||
pub async fn p(self, channel: String) {
|
||||
#[cfg(not(debug_assertions))]
|
||||
redis_kiss::p(channel, self).await;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
info!("Publishing event to {channel}: {self:?}");
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
redis_kiss::publish(channel, self).await.unwrap();
|
||||
let rmq = get_channel().await;
|
||||
|
||||
let mut headers = FieldTable::new();
|
||||
headers.insert("c".try_into().unwrap(), channel.clone().into());
|
||||
let mut properties = BasicProperties::default();
|
||||
properties.with_headers(headers);
|
||||
|
||||
rmq.basic_publish(
|
||||
properties,
|
||||
serde_json::to_string(&self).unwrap().into_bytes(),
|
||||
BasicPublishArguments::new("events", "events"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Publish user event
|
||||
|
||||
@@ -5,5 +5,6 @@ pub mod idempotency;
|
||||
pub mod permissions;
|
||||
pub mod reference;
|
||||
pub mod test_fixtures;
|
||||
pub mod rabbit;
|
||||
|
||||
pub use funcs::*;
|
||||
|
||||
48
crates/core/database/src/util/rabbit.rs
Normal file
48
crates/core/database/src/util/rabbit.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use amqprs::{channel::Channel, connection::Connection};
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::{
|
||||
collections::HashMap, future::ready, sync::{LazyLock, RwLock}, thread::{ThreadId, current}
|
||||
};
|
||||
|
||||
static RABBIT_CONNECTION: OnceCell<Connection> = OnceCell::new();
|
||||
static RABBIT_CHANNELS: LazyLock<RwLock<HashMap<ThreadId, Channel>>> =
|
||||
LazyLock::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
pub async fn get_channel_with_init<F: AsyncFnOnce(Channel) -> Channel>(init: F) -> Channel {
|
||||
let conn = RABBIT_CONNECTION
|
||||
.get()
|
||||
.expect("Rabbit connection is not initialised.");
|
||||
|
||||
let thread_id = current().id();
|
||||
|
||||
let channel = RABBIT_CHANNELS
|
||||
.read()
|
||||
.expect("Channels poisioned")
|
||||
.get(&thread_id)
|
||||
.cloned();
|
||||
|
||||
if let Some(channel) = channel {
|
||||
channel
|
||||
} else {
|
||||
let mut channel =
|
||||
conn.open_channel(None)
|
||||
.await
|
||||
.expect("Failed to open rabbitmq channel");
|
||||
|
||||
channel = init(channel).await;
|
||||
|
||||
RABBIT_CHANNELS
|
||||
.write()
|
||||
.expect("Channels poisioned")
|
||||
.insert(thread_id, channel.clone());
|
||||
channel
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_channel() -> Channel {
|
||||
get_channel_with_init(ready).await
|
||||
}
|
||||
|
||||
pub fn set_rabbitmq_connection(connection: Connection) -> bool {
|
||||
RABBIT_CONNECTION.set(connection).is_ok()
|
||||
}
|
||||
@@ -16,7 +16,9 @@ mod voice_client;
|
||||
pub use voice_client::VoiceClient;
|
||||
|
||||
async fn get_connection() -> Result<Conn> {
|
||||
_get_connection().await.map_err(|_| create_error!(InternalError))
|
||||
_get_connection()
|
||||
.await
|
||||
.map_err(|_| create_error!(InternalError))
|
||||
}
|
||||
|
||||
pub async fn raise_if_in_voice(user: &User, channel_id: &str) -> Result<()> {
|
||||
@@ -59,6 +61,14 @@ pub async fn get_channel_node(channel: &str) -> Result<Option<String>> {
|
||||
.to_internal_error()
|
||||
}
|
||||
|
||||
pub async fn delete_channel_node(channel: &str) -> Result<()> {
|
||||
get_connection()
|
||||
.await?
|
||||
.del(format!("node:{channel}"))
|
||||
.await
|
||||
.to_internal_error()
|
||||
}
|
||||
|
||||
pub async fn get_user_voice_channels(user_id: &str) -> Result<Vec<String>> {
|
||||
get_connection()
|
||||
.await?
|
||||
@@ -226,6 +236,7 @@ pub async fn delete_channel_voice_state(
|
||||
|
||||
let mut pipeline = Pipeline::new();
|
||||
pipeline.del(format!("vc_members:{channel_id}"));
|
||||
pipeline.del(format!("node:{channel_id}"));
|
||||
|
||||
for user_id in user_ids {
|
||||
let unique_key = format!("{user_id}:{parent_id}");
|
||||
@@ -567,15 +578,24 @@ pub async fn get_call_notification_recipients(
|
||||
.to_internal_error()
|
||||
}
|
||||
|
||||
pub async fn remove_user_from_voice_channels(db: &Database, voice_client: &VoiceClient, user_id: &str) -> Result<()> {
|
||||
pub async fn remove_user_from_voice_channels(
|
||||
db: &Database,
|
||||
voice_client: &VoiceClient,
|
||||
user_id: &str,
|
||||
) -> Result<()> {
|
||||
for channel_id in get_user_voice_channels(user_id).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, &channel_id, user_id).await?;
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn remove_user_from_voice_channel(db: &Database, voice_client: &VoiceClient, channel_id: &str, user_id: &str) -> Result<()> {
|
||||
pub async fn remove_user_from_voice_channel(
|
||||
db: &Database,
|
||||
voice_client: &VoiceClient,
|
||||
channel_id: &str,
|
||||
user_id: &str,
|
||||
) -> Result<()> {
|
||||
if let Some(node) = get_channel_node(channel_id).await? {
|
||||
let _ = voice_client.remove_user(&node, user_id, channel_id).await;
|
||||
}
|
||||
@@ -587,7 +607,11 @@ pub async fn remove_user_from_voice_channel(db: &Database, voice_client: &VoiceC
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_voice_channel(voice_client: &VoiceClient, channel_id: &str, server_id: Option<&str>) -> Result<()> {
|
||||
pub async fn delete_voice_channel(
|
||||
voice_client: &VoiceClient,
|
||||
channel_id: &str,
|
||||
server_id: Option<&str>,
|
||||
) -> Result<()> {
|
||||
if let Some(users) = get_voice_channel_members(channel_id).await? {
|
||||
let node = get_channel_node(channel_id).await?.unwrap();
|
||||
|
||||
@@ -597,4 +621,4 @@ pub async fn delete_voice_channel(voice_client: &VoiceClient, channel_id: &str,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ impl DmCallConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -101,7 +101,7 @@ impl FRAcceptedConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -101,7 +101,7 @@ impl FRReceivedConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -107,7 +107,7 @@ impl GenericConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -104,7 +104,7 @@ impl MassMessageConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -107,7 +107,7 @@ impl MessageConsumer {
|
||||
config.pushd.vapid.queue.as_str(),
|
||||
)
|
||||
.finish();
|
||||
sendable.extras.insert("p265dh".to_string(), sub.p256dh);
|
||||
sendable.extras.insert("p256dh".to_string(), sub.p256dh);
|
||||
sendable
|
||||
.extras
|
||||
.insert("endpoint".to_string(), sub.endpoint.clone());
|
||||
|
||||
@@ -5,9 +5,8 @@ use revolt_database::{
|
||||
iso8601_timestamp::{Duration, Timestamp},
|
||||
util::reference::Reference,
|
||||
voice::{
|
||||
create_voice_state, delete_voice_state,
|
||||
get_user_moved_from_voice, get_user_moved_to_voice,
|
||||
update_voice_state_tracks, VoiceClient,
|
||||
create_voice_state, delete_channel_node, delete_voice_state, get_user_moved_from_voice,
|
||||
get_user_moved_to_voice, get_voice_channel_members, update_voice_state_tracks, VoiceClient,
|
||||
},
|
||||
Database, AMQP,
|
||||
};
|
||||
@@ -160,6 +159,8 @@ pub async fn ingress(
|
||||
// let members = get_voice_channel_members(channel_id).await?;
|
||||
|
||||
// if members.is_none_or(|m| m.is_empty()) {
|
||||
// delete_channel_node(channel_id).await?;
|
||||
//
|
||||
// // The channel is empty so send out an "end" message for ringing
|
||||
// if let Err(e) = amqp
|
||||
// .dm_call_updated(user_id, channel_id, None, true, None)
|
||||
|
||||
@@ -9,8 +9,7 @@ pub mod routes;
|
||||
pub mod util;
|
||||
|
||||
use revolt_config::config;
|
||||
use revolt_database::events::client::EventV1;
|
||||
use revolt_database::AMQP;
|
||||
use revolt_database::{AMQP, util::rabbit::{get_channel, get_channel_with_init, set_rabbitmq_connection}};
|
||||
use revolt_ratelimits::rocket as ratelimiter;
|
||||
use rocket::{Build, Rocket};
|
||||
use rocket_cors::{AllowedOrigins, CorsOptions};
|
||||
@@ -19,11 +18,9 @@ use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use amqprs::{
|
||||
channel::ExchangeDeclareArguments,
|
||||
channel::{Channel, ExchangeDeclareArguments},
|
||||
connection::{Connection, OpenConnectionArguments},
|
||||
};
|
||||
use async_std::channel::unbounded;
|
||||
use authifier::AuthifierEvent;
|
||||
use rocket::data::ToByteUnit;
|
||||
use revolt_database::voice::VoiceClient;
|
||||
|
||||
@@ -39,28 +36,9 @@ pub async fn web() -> Rocket<Build> {
|
||||
log::info!("database_here {db:?}");
|
||||
db.migrate_database().await.unwrap();
|
||||
|
||||
// Setup Authifier event channel
|
||||
let (_, receiver) = unbounded();
|
||||
|
||||
// Setup Authifier
|
||||
let authifier = db.clone().to_authifier().await;
|
||||
|
||||
// Launch a listener for Authifier events
|
||||
async_std::task::spawn(async move {
|
||||
while let Ok(event) = receiver.recv().await {
|
||||
match &event {
|
||||
AuthifierEvent::CreateSession { .. } | AuthifierEvent::CreateAccount { .. } => {
|
||||
EventV1::Auth(event).global().await
|
||||
}
|
||||
AuthifierEvent::DeleteSession { user_id, .. }
|
||||
| AuthifierEvent::DeleteAllSessions { user_id, .. } => {
|
||||
let id = user_id.to_string();
|
||||
EventV1::Auth(event).private(id).await
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Configure CORS
|
||||
let cors = CorsOptions {
|
||||
allowed_origins: AllowedOrigins::All,
|
||||
@@ -121,19 +99,19 @@ pub async fn web() -> Rocket<Build> {
|
||||
.await
|
||||
.expect("Failed to connect to RabbitMQ");
|
||||
|
||||
let channel = connection
|
||||
.open_channel(None)
|
||||
.await
|
||||
.expect("Failed to open RabbitMQ channel");
|
||||
set_rabbitmq_connection(connection.clone());
|
||||
let channel = get_channel_with_init(|channel: Channel| async {
|
||||
channel
|
||||
.exchange_declare(
|
||||
ExchangeDeclareArguments::new(&config.pushd.exchange, "direct")
|
||||
.durable(true)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to declare exchange");
|
||||
|
||||
channel
|
||||
.exchange_declare(
|
||||
ExchangeDeclareArguments::new(&config.pushd.exchange, "direct")
|
||||
.durable(true)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to declare exchange");
|
||||
channel
|
||||
}).await;
|
||||
|
||||
let amqp = AMQP::new(connection, channel);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use revolt_database::{
|
||||
util::{permissions::perms, reference::Reference},
|
||||
voice::{
|
||||
delete_voice_state, get_channel_node, get_user_voice_channels, get_voice_channel_members,
|
||||
raise_if_in_voice, set_call_notification_recipients, VoiceClient,
|
||||
raise_if_in_voice, set_call_notification_recipients, set_channel_node, VoiceClient,
|
||||
},
|
||||
Database, User,
|
||||
};
|
||||
@@ -60,6 +60,7 @@ pub async fn call(
|
||||
}
|
||||
|
||||
let existing_node = get_channel_node(channel.id()).await?;
|
||||
let has_existing_node = existing_node.is_some(); // we move existing_node in the next statement so this is the quickest way to know if we need to set it.
|
||||
|
||||
let node = existing_node
|
||||
.or(node)
|
||||
@@ -86,9 +87,11 @@ pub async fn call(
|
||||
|
||||
let channel = Reference::from_unchecked(&channel_id)
|
||||
.as_channel(db)
|
||||
.await?;
|
||||
.await;
|
||||
|
||||
delete_voice_state(&channel_id, channel.server(), &user.id).await?;
|
||||
if channel.is_ok() {
|
||||
delete_voice_state(&channel_id, channel.unwrap().server(), &user.id).await?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
raise_if_in_voice(&user, channel.id()).await?;
|
||||
@@ -100,6 +103,10 @@ pub async fn call(
|
||||
|
||||
let room = voice_client.create_room(&node, &channel).await?;
|
||||
|
||||
if !has_existing_node {
|
||||
set_channel_node(channel.id(), &node).await?;
|
||||
}
|
||||
|
||||
log::debug!("Created room {}", room.name);
|
||||
|
||||
if let Some(recipients) = recipients {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use revolt_config::config;
|
||||
use revolt_result::Result;
|
||||
use rocket::serde::json::Json;
|
||||
@@ -54,6 +55,80 @@ pub struct RevoltFeatures {
|
||||
pub january: Feature,
|
||||
/// Voice server configuration
|
||||
pub livekit: VoiceFeature,
|
||||
/// Limits
|
||||
pub limits: LimitsConfig,
|
||||
}
|
||||
|
||||
/// # Limits For Users
|
||||
#[derive(Serialize, JsonSchema, Debug)]
|
||||
pub struct LimitsConfig {
|
||||
/// Global Limits
|
||||
pub global: GlobalLimits,
|
||||
/// New User Limits
|
||||
pub new_user: UserLimits,
|
||||
/// Default User Limits
|
||||
pub default: UserLimits,
|
||||
}
|
||||
|
||||
/// # Global limits
|
||||
#[derive(Serialize, JsonSchema, Debug)]
|
||||
pub struct GlobalLimits {
|
||||
/// max group size
|
||||
group_size: i64,
|
||||
/// max message embeds
|
||||
message_embeds: i64,
|
||||
/// max replies
|
||||
message_replies: i64,
|
||||
/// max reactions per message
|
||||
message_reactions: i64,
|
||||
/// max server emoji
|
||||
server_emoji: i64,
|
||||
/// max server roles
|
||||
server_roles: i64,
|
||||
/// max server channels
|
||||
server_channels: i64,
|
||||
body_limit_size: i64,
|
||||
}
|
||||
|
||||
/// # User Limits
|
||||
#[derive(Serialize, JsonSchema, Debug)]
|
||||
pub struct UserLimits {
|
||||
/// Max Outgoing Friend Requests
|
||||
pub outgoing_friend_requests: i64,
|
||||
/// Max Owned Bots
|
||||
pub bots: i64,
|
||||
/// Max message content length
|
||||
pub message_length: i64,
|
||||
/// max message attachments
|
||||
pub message_attachments: i64,
|
||||
/// max servers
|
||||
pub servers: i64,
|
||||
/// max audio quality
|
||||
pub voice_quality: i64,
|
||||
/// video streaming enabled
|
||||
pub video: bool,
|
||||
/// max video resolution (vertical, horizontal)
|
||||
pub video_resolution: [i64; 2],
|
||||
/// min/max aspect ratios
|
||||
pub video_aspect_ratio: [f64; 2],
|
||||
pub file_upload_size_limits: HashMap<String, usize>,
|
||||
}
|
||||
|
||||
impl UserLimits {
|
||||
fn from_feature_limits(fl: revolt_config::FeaturesLimits) -> UserLimits {
|
||||
UserLimits {
|
||||
outgoing_friend_requests: fl.outgoing_friend_requests as i64,
|
||||
bots: fl.bots as i64,
|
||||
message_length: fl.message_length as i64,
|
||||
message_attachments: fl.message_attachments as i64,
|
||||
servers: fl.servers as i64,
|
||||
voice_quality: fl.voice_quality as i64,
|
||||
video: fl.video,
|
||||
video_resolution: [fl.video_resolution[0] as i64, fl.video_resolution[1] as i64],
|
||||
video_aspect_ratio: [fl.video_aspect_ratio[0] as f64, fl.video_aspect_ratio[1] as f64],
|
||||
file_upload_size_limits: fl.file_upload_size_limit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// # Build Information
|
||||
@@ -134,6 +209,20 @@ pub async fn root() -> Result<Json<RevoltConfig>> {
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
limits: LimitsConfig {
|
||||
global: GlobalLimits {
|
||||
group_size: config.features.limits.global.group_size as i64,
|
||||
message_embeds: config.features.limits.global.message_embeds as i64,
|
||||
message_replies: config.features.limits.global.message_replies as i64,
|
||||
message_reactions: config.features.limits.global.message_reactions as i64,
|
||||
server_emoji: config.features.limits.global.server_emoji as i64,
|
||||
server_roles: config.features.limits.global.server_roles as i64,
|
||||
server_channels: config.features.limits.global.server_channels as i64,
|
||||
body_limit_size: config.features.limits.global.body_limit_size as i64,
|
||||
},
|
||||
new_user: UserLimits::from_feature_limits(config.features.limits.new_user),
|
||||
default: UserLimits::from_feature_limits(config.features.limits.default),
|
||||
}
|
||||
},
|
||||
ws: config.hosts.events,
|
||||
app: config.hosts.app,
|
||||
|
||||
@@ -6,7 +6,9 @@ use futures::StreamExt;
|
||||
use rand::Rng;
|
||||
use redis_kiss::redis::aio::PubSub;
|
||||
use revolt_database::{
|
||||
events::client::EventV1, Channel, Database, Member, Message, PartialRole, Server, User, AMQP,
|
||||
events::client::EventV1,
|
||||
util::rabbit::{get_channel, set_rabbitmq_connection},
|
||||
Channel, Database, Member, Message, PartialRole, Server, User, AMQP,
|
||||
};
|
||||
use revolt_database::{util::idempotency::IdempotencyKey, Role};
|
||||
use revolt_models::v0;
|
||||
@@ -59,10 +61,16 @@ impl TestHarness {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let channel = connection.open_channel(None).await.unwrap();
|
||||
|
||||
set_rabbitmq_connection(connection.clone());
|
||||
let channel = get_channel().await;
|
||||
|
||||
let amqp = AMQP::new(connection, channel);
|
||||
|
||||
async_std::task::spawn(async {
|
||||
|
||||
});
|
||||
|
||||
TestHarness {
|
||||
client,
|
||||
authifier,
|
||||
|
||||
Reference in New Issue
Block a user