Skip to content

Commit

Permalink
FromType::User => FromType::Custom
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Aug 11, 2023
1 parent 4b7f1ed commit de06a2a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions rmqtt-plugins/rmqtt-web-hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,8 @@ impl JsonFrom for Id {
impl JsonFrom for rmqtt::From {
fn from(&self, json: serde_json::Value) -> serde_json::Value {
let mut json = self.id.from(json);
if !self.is_user() {
if let Some(obj) = json.as_object_mut() {
obj.insert("from_type".into(), serde_json::Value::String(self.typ().to_string()));
}
if let Some(obj) = json.as_object_mut() {
obj.insert("from_type".into(), serde_json::Value::String(self.typ().to_string()));
}
json
}
Expand Down
2 changes: 1 addition & 1 deletion rmqtt/src/broker/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ impl SessionState {

#[inline]
async fn publish(&self, publish: Publish) -> Result<bool> {
let from = From::from_user(self.id.clone());
let from = From::from_custom(self.id.clone());

//hook, message_publish
let publish = self.hook.message_publish(from.clone(), &publish).await.unwrap_or(publish);
Expand Down
12 changes: 6 additions & 6 deletions rmqtt/src/broker/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl Publish {

#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
pub enum FromType {
User,
Custom,
Admin,
System,
LastWill,
Expand All @@ -924,7 +924,7 @@ impl std::fmt::Display for FromType {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let typ = match self {
FromType::User => "user",
FromType::Custom => "custom",
FromType::Admin => "admin",
FromType::System => "system",
FromType::LastWill => "lastwill",
Expand All @@ -941,8 +941,8 @@ pub struct From {

impl From {
#[inline]
pub fn from_user(id: Id) -> From {
From { typ: FromType::User, id }
pub fn from_custom(id: Id) -> From {
From { typ: FromType::Custom, id }
}

#[inline]
Expand Down Expand Up @@ -971,8 +971,8 @@ impl From {
}

#[inline]
pub fn is_user(&self) -> bool {
matches!(self.typ, FromType::User)
pub fn is_custom(&self) -> bool {
matches!(self.typ, FromType::Custom)
}
}

Expand Down

0 comments on commit de06a2a

Please sign in to comment.