add: connect to socket by community

direct messages/groups connect by channel id, everything else should connect by channel with the "is_channel" header set to true
This commit is contained in:
trisua 2025-04-29 16:53:34 -04:00
parent c1c8cdbfcd
commit 0304461389
20 changed files with 241 additions and 160 deletions

View file

@ -151,6 +151,7 @@ impl Default for TurnstileConfig {
}
#[derive(Clone, Serialize, Deserialize, Debug)]
#[derive(Default)]
pub struct ConnectionsConfig {
/// <https://developer.spotify.com/documentation/web-api>
#[serde(default)]
@ -163,15 +164,6 @@ pub struct ConnectionsConfig {
pub last_fm_secret: Option<String>,
}
impl Default for ConnectionsConfig {
fn default() -> Self {
Self {
spotify_client_id: None,
last_fm_key: None,
last_fm_secret: None,
}
}
}
/// Configuration file
#[derive(Clone, Serialize, Deserialize, Debug)]

View file

@ -528,7 +528,7 @@ macro_rules! auto_method {
if !user.permissions.check(FinePermission::$permission) {
return Err(Error::NotAllowed);
} else {
self.create_audit_log_entry(crate::model::moderation::AuditLogEntry::new(
self.create_audit_log_entry($crate::model::moderation::AuditLogEntry::new(
user.id,
format!("invoked `{}` with x value `{x}`", stringify!($name)),
))
@ -607,7 +607,7 @@ macro_rules! auto_method {
if !user.permissions.check(FinePermission::$permission) {
return Err(Error::NotAllowed);
} else {
self.create_audit_log_entry(crate::model::moderation::AuditLogEntry::new(
self.create_audit_log_entry($crate::model::moderation::AuditLogEntry::new(
user.id,
format!("invoked `{}` with x value `{x:?}`", stringify!($name)),
))

View file

@ -49,7 +49,7 @@ impl DataManager {
pub async fn fill_messages(
&self,
messages: Vec<Message>,
ignore_users: &Vec<usize>,
ignore_users: &[usize],
) -> Result<Vec<(Message, User)>> {
let mut out: Vec<(Message, User)> = Vec::new();
@ -158,10 +158,16 @@ impl DataManager {
let mut con = self.2.get_con().await;
if let Err(e) = con.publish::<usize, String, ()>(
data.channel,
if channel.community != 0 {
// broadcast to community ws
channel.community
} else {
// broadcast to channel ws
channel.id
},
serde_json::to_string(&SocketMessage {
method: SocketMethod::Message,
data: serde_json::to_string(&data).unwrap(),
data: serde_json::to_string(&(data.channel.to_string(), data)).unwrap(),
})
.unwrap(),
) {
@ -211,7 +217,13 @@ impl DataManager {
let mut con = self.2.get_con().await;
if let Err(e) = con.publish::<usize, String, ()>(
message.channel,
if channel.community != 0 {
// broadcast to community ws
channel.community
} else {
// broadcast to channel ws
channel.id
},
serde_json::to_string(&SocketMessage {
method: SocketMethod::Delete,
data: serde_json::to_string(&DeleteMessageEvent { id: id.to_string() }).unwrap(),

View file

@ -121,7 +121,7 @@ impl DataManager {
pub async fn fill_posts(
&self,
posts: Vec<Post>,
ignore_users: &Vec<usize>,
ignore_users: &[usize],
) -> Result<Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)>> {
let mut out: Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)> = Vec::new();
@ -160,7 +160,7 @@ impl DataManager {
&self,
posts: Vec<Post>,
user_id: usize,
ignore_users: &Vec<usize>,
ignore_users: &[usize],
) -> Result<
Vec<(
Post,

View file

@ -49,7 +49,7 @@ impl DataManager {
pub async fn fill_questions(
&self,
questions: Vec<Question>,
ignore_users: &Vec<usize>,
ignore_users: &[usize],
) -> Result<Vec<(Question, User)>> {
let mut out: Vec<(Question, User)> = Vec::new();

View file

@ -371,19 +371,12 @@ pub struct ExternalConnectionInfo {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Default)]
pub struct ExternalConnectionData {
pub external_urls: HashMap<String, String>,
pub data: HashMap<String, String>,
}
impl Default for ExternalConnectionData {
fn default() -> Self {
Self {
external_urls: HashMap::new(),
data: HashMap::new(),
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Notification {

View file

@ -93,7 +93,7 @@ impl Message {
created: now,
edited: now,
content,
context: MessageContext::default(),
context: MessageContext,
}
}
}

View file

@ -1,5 +1,11 @@
use serde::{Serialize, Deserialize, de::DeserializeOwned};
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum PacketType {
/// A regular check to ensure the connection is still alive.
Ping,
}
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum SocketMethod {
/// Authentication and channel identification.
@ -8,6 +14,8 @@ pub enum SocketMethod {
Message,
/// A message was deleted in the channel.
Delete,
/// Forward message from server to client. (Redis pubsub to ws)
Forward(PacketType),
}
#[derive(Serialize, Deserialize)]