Allow multiple labrinth instances (#3360)

* Move a lot of scheduled tasks to be runnable from the command-line

* Use pubsub to handle sockets connected to multiple Labrinths

* Clippy fix

* Fix build and merge some stuff

* Fix build fmt
:

---------

Signed-off-by: Jai Agrawal <18202329+Geometrically@users.noreply.github.com>
Co-authored-by: Jai A <jaiagr+gpg@pm.me>
Co-authored-by: Jai Agrawal <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Josiah Glosson
2025-03-15 09:28:20 -05:00
committed by GitHub
parent 84a9438a70
commit c998d2566e
21 changed files with 1056 additions and 692 deletions

View File

@@ -5,8 +5,12 @@ use crate::models::pats::Scopes;
use crate::models::users::UserFriend;
use crate::queue::session::AuthQueue;
use crate::queue::socket::ActiveSockets;
use crate::routes::internal::statuses::send_message_to_user;
use crate::routes::internal::statuses::{
broadcast_friends_message, send_message_to_user,
};
use crate::routes::ApiError;
use crate::sync::friends::RedisFriendsMessage;
use crate::sync::status::get_user_status;
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
use ariadne::networking::message::ServerToClientMessage;
use chrono::Utc;
@@ -76,14 +80,16 @@ pub async fn add_friend(
user_id: UserId,
friend_id: UserId,
sockets: &ActiveSockets,
redis: &RedisPool,
) -> Result<(), ApiError> {
if let Some(friend_status) = sockets.get_status(user_id.into())
if let Some(friend_status) =
get_user_status(user_id.into(), sockets, redis).await
{
send_message_to_user(
sockets,
friend_id.into(),
&ServerToClientMessage::StatusUpdate {
status: friend_status.clone(),
broadcast_friends_message(
redis,
RedisFriendsMessage::DirectStatusUpdate {
to_user: friend_id.into(),
status: friend_status,
},
)
.await?;
@@ -92,8 +98,10 @@ pub async fn add_friend(
Ok(())
}
send_friend_status(friend.user_id, friend.friend_id, &db).await?;
send_friend_status(friend.friend_id, friend.user_id, &db).await?;
send_friend_status(friend.user_id, friend.friend_id, &db, &redis)
.await?;
send_friend_status(friend.friend_id, friend.user_id, &db, &redis)
.await?;
} else {
if friend.id == user.id.into() {
return Err(ApiError::InvalidInput(