forked from jmug/stoatchat
Servers: Add TextChannel.
This commit is contained in:
@@ -50,6 +50,18 @@ pub enum Channel {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
last_message: Option<LastMessage>,
|
||||
},
|
||||
TextChannel {
|
||||
#[serde(rename = "_id")]
|
||||
id: String,
|
||||
server: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nonce: Option<String>,
|
||||
|
||||
name: String,
|
||||
description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
icon: Option<File>,
|
||||
}
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
@@ -57,7 +69,8 @@ impl Channel {
|
||||
match self {
|
||||
Channel::SavedMessages { id, .. }
|
||||
| Channel::DirectMessage { id, .. }
|
||||
| Channel::Group { id, .. } => id,
|
||||
| Channel::Group { id, .. }
|
||||
| Channel::TextChannel { id, .. } => id,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +43,10 @@ pub struct Server {
|
||||
|
||||
pub name: String,
|
||||
// pub default_permissions: u32,
|
||||
pub channels: Vec<String>,
|
||||
// pub invites: Vec<Invite>,
|
||||
// pub bans: Vec<Ban>,
|
||||
pub channels: Vec<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub icon: Option<File>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
@@ -81,6 +81,9 @@ impl<'a> PermissionCalculator<'a> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
Channel::TextChannel { .. } => {
|
||||
Ok(ChannelPermission::View + ChannelPermission::SendMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,18 @@ impl ClientboundNotification {
|
||||
.ok();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn publish_to(self, channel: &Channel) {
|
||||
// ! FIXME: update all for channel
|
||||
// ! FIXME: temporary solution for pushing to guilds
|
||||
self.publish(
|
||||
if let Channel::TextChannel { server, .. } = channel {
|
||||
server.clone()
|
||||
} else {
|
||||
channel.id().to_string()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prehandle_hook(notification: &ClientboundNotification) {
|
||||
@@ -161,6 +173,7 @@ pub fn prehandle_hook(notification: &ClientboundNotification) {
|
||||
subscribe_if_exists(recipient.clone(), channel_id.to_string()).ok();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
ClientboundNotification::ServerMemberJoin { id, user } => {
|
||||
|
||||
@@ -108,5 +108,6 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Channel::TextChannel { .. } => unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,24 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
||||
}
|
||||
|
||||
let id = Ulid::new().to_string();
|
||||
let cid = Ulid::new().to_string();
|
||||
|
||||
Channel::TextChannel {
|
||||
id: cid.clone(),
|
||||
server: id.clone(),
|
||||
nonce: Some(info.nonce.clone()),
|
||||
name: "general".to_string(),
|
||||
description: None,
|
||||
icon: None,
|
||||
}.publish().await?;
|
||||
|
||||
let server = Server {
|
||||
id: id.clone(),
|
||||
nonce: Some(info.nonce.clone()),
|
||||
owner: user.id.clone(),
|
||||
|
||||
name: info.name.clone(),
|
||||
channels: vec![],
|
||||
channels: vec![ cid ],
|
||||
|
||||
icon: None,
|
||||
banner: None,
|
||||
|
||||
Reference in New Issue
Block a user