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:
parent
c1c8cdbfcd
commit
0304461389
20 changed files with 241 additions and 160 deletions
|
@ -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)]
|
||||
|
|
|
@ -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)),
|
||||
))
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -93,7 +93,7 @@ impl Message {
|
|||
created: now,
|
||||
edited: now,
|
||||
content,
|
||||
context: MessageContext::default(),
|
||||
context: MessageContext,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue