Skip to content

Commit

Permalink
fix error and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptex-github authored May 27, 2024
1 parent d0dcc8c commit 315068b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,14 @@ impl UserSession {
let relationships = db.fetch_relationships(self.user_id).await?;
let dm_channels = db.fetch_all_dm_channels_for_user(self.user_id).await?;
let unacked = db.fetch_unacked(self.user_id, &guilds).await?;

Ok(OutboundMessage::Ready {
session_id: self.id.clone(),
user,
guilds,
dm_channels,
presences,
relationships,
unacked,
inbox: vec![],
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ async fn main() {
.expect("Failed to create global event exchange");

events::setup(con);
presence::reset_all().await.expect("failed to reset presence");
presence::reset_all()
.await
.expect("failed to reset presence");

let listener = TcpListener::bind("0.0.0.0:8076")
.await
Expand Down
7 changes: 2 additions & 5 deletions src/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ pub async fn update_presence(user_id: u64, status: PresenceStatus) -> Result<()>
let key = format!("presence-{user_id}");

if status == PresenceStatus::Offline {
get_con()
.await?
.del(key)
.await?;
} else {
get_con().await?.del(key).await?;
} else {
get_con()
.await?
.set(key, bincode::encode_to_vec(status, CONFIG)?)
Expand Down
44 changes: 29 additions & 15 deletions src/recv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use essence::{ws::OutboundMessage, models::Channel as EssenceChannel};
use essence::{models::Channel as EssenceChannel, ws::OutboundMessage};
use flume::Sender;
use futures_util::TryStreamExt;
use lapin::{
Expand All @@ -19,17 +19,21 @@ enum HandleState {
Break,
}

async fn unsubscribe(channel: &Channel, session_id: impl AsRef<str>, exchange: impl AsRef<str>) -> Result<HandleState> {
async fn unsubscribe(
channel: &Channel,
session_id: impl AsRef<str>,
exchange: impl AsRef<str>,
) -> Result<HandleState> {
channel
.queue_unbind(
session_id.as_ref(),
exchange.as_ref(),
"all",
FieldTable::default(),
)
.await
.map(|_| HandleState::Continue)
.map_err(|e| e.into())
.queue_unbind(
session_id.as_ref(),
exchange.as_ref(),
"all",
FieldTable::default(),
)
.await
.map(|_| HandleState::Continue)
.map_err(|e| e.into())
}

async fn handle(
Expand Down Expand Up @@ -59,16 +63,26 @@ async fn handle(
.await
.map(|_| HandleState::Continue)
}
OutboundMessage::GuildRemove { guild_id, .. } => unsubscribe(&channel, &session_id, guild_id.to_string()).await,
OutboundMessage::GuildRemove { guild_id, .. } => {
unsubscribe(&channel, &session_id, guild_id.to_string()).await
}
OutboundMessage::ChannelCreate { channel: chan } => {
if let EssenceChannel::Dm(chan) = chan {
upstream::subscribe(&channel, chan.id.to_string(), &session_id, ExchangeKind::Fanout).await
.map(|_| HandleState::Continue)
upstream::subscribe(
&channel,
chan.id.to_string(),
&session_id,
ExchangeKind::Fanout,
)
.await
.map(|_| HandleState::Continue)
} else {
Ok(HandleState::Continue)
}
}
OutboundMessage::ChannelDelete { channel_id } => unsubscribe(&channel, &session_id, channel_id.to_string()).await,
OutboundMessage::ChannelDelete { channel_id } => {
unsubscribe(&channel, &session_id, channel_id.to_string()).await
}
OutboundMessage::MessageCreate { message, .. } => {
if hidden_channels.contains(&message.channel_id) {
Ok(HandleState::Break)
Expand Down
4 changes: 2 additions & 2 deletions src/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use essence::{
models::Guild,
};
use flume::Sender;
use futures_util::future::{JoinAll};
use futures_util::future::JoinAll;
use lapin::{
options::{BasicConsumeOptions, ExchangeDeclareOptions, QueueBindOptions, QueueDeclareOptions},
types::FieldTable,
Expand All @@ -17,7 +17,7 @@ use tokio_tungstenite::tungstenite::Message;

use crate::{
config::{HiddenChannels, MessageFormat},
error::{Result},
error::Result,
recv,
};

Expand Down

0 comments on commit 315068b

Please sign in to comment.