Skip to content

Commit

Permalink
feat: Add support for stars events (#241)
Browse files Browse the repository at this point in the history
Add support for `star_added` and `star_removed` Slack events.
It has now been renamed "saved for later" in the Slack UI.
  • Loading branch information
dax authored Feb 28, 2024
1 parent 4bd1bfc commit 43423cd
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/models/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ mod channel;
pub use channel::*;
mod reaction;
pub use reaction::*;
mod star;
pub use star::*;

mod bot;
pub use bot::*;
Expand Down
66 changes: 66 additions & 0 deletions src/models/common/star.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::*;

use rsb_derive::Builder;
use rvstruct::ValueStruct;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "lowercase")]
#[allow(clippy::large_enum_variant)]
pub enum SlackStarsItem {
Message(SlackStarsItemMessage),
File(SlackStarsItemFile),
#[serde(rename = "file_comment")]
FileComment(SlackStarsItemFileComment),
Channel(SlackStarsItemChannel),
Im(SlackStarsItemIm),
Group(SlackStarsItemGroup),
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemMessage {
message: SlackHistoryMessage,
channel: SlackChannelId,
date_create: SlackDateTime,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemFile {
file: SlackFile,
channel: SlackChannelId,
date_create: SlackDateTime,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemFileComment {
file: SlackFile,
comment: String,
channel: SlackChannelId,
date_create: SlackDateTime,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemChannel {
channel: SlackChannelId,
date_create: SlackDateTime,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemIm {
channel: SlackChannelId,
date_create: SlackDateTime,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarsItemGroup {
group: SlackChannelId,
date_create: SlackDateTime,
}
18 changes: 18 additions & 0 deletions src/models/events/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum SlackEventCallbackBody {
FilePublic(SlackFilePublicEvent),
ReactionAdded(SlackReactionAddedEvent),
ReactionRemoved(SlackReactionRemovedEvent),
StarAdded(SlackStarAddedEvent),
StarRemoved(SlackStarRemovedEvent),
UserChange(SlackUserChangeEvent),
UserStatusChanged(SlackUserStatusChangedEvent),
}
Expand Down Expand Up @@ -356,6 +358,22 @@ pub struct SlackReactionRemovedEvent {
pub event_ts: SlackTs,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarAddedEvent {
pub user: SlackUserId,
pub item: SlackStarsItem,
pub event_ts: SlackTs,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackStarRemovedEvent {
pub user: SlackUserId,
pub item: SlackStarsItem,
pub event_ts: SlackTs,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackUserChangeEvent {
Expand Down

0 comments on commit 43423cd

Please sign in to comment.