steam_client/services/
notifications.rs1use crate::{error::SteamError, SteamClient};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[repr(u32)]
11pub enum NotificationType {
12 TradeOffers = 1,
14 CommunityMessages = 3,
16}
17
18impl NotificationType {
19 pub fn name(&self) -> &'static str {
21 match self {
22 NotificationType::TradeOffers => "tradeOffers",
23 NotificationType::CommunityMessages => "communityMessages",
24 }
25 }
26}
27
28#[derive(Debug, Clone)]
30pub struct Notification {
31 pub id: String,
33 pub notification_type: u32,
35 pub targets: Vec<u32>,
37 pub body: Option<serde_json::Value>,
39 pub read: bool,
41 pub timestamp: Option<u64>,
43 pub hidden: bool,
45 pub expiry: Option<u64>,
47 pub viewed: Option<u64>,
49}
50
51impl SteamClient {
52 pub async fn mark_notifications_read(&mut self, notification_ids: Vec<String>) -> Result<(), SteamError> {
64 if !self.is_logged_in() {
65 return Err(SteamError::NotLoggedOn);
66 }
67
68 let ids: Vec<u64> = notification_ids.iter().filter_map(|s| s.parse().ok()).collect();
69
70 let request = steam_protos::CSteamNotificationMarkNotificationsReadNotification { timestamp: None, notification_type: None, notification_ids: ids, mark_all_read: None };
71
72 self.send_service_method("SteamNotification.MarkNotificationsRead#1", &request).await?;
74
75 Ok(())
76 }
77
78 pub async fn mark_all_notifications_read(&mut self) -> Result<(), SteamError> {
86 if !self.is_logged_in() {
87 return Err(SteamError::NotLoggedOn);
88 }
89
90 let request = steam_protos::CSteamNotificationMarkNotificationsReadNotification { timestamp: None, notification_type: None, notification_ids: vec![], mark_all_read: Some(true) };
91
92 self.send_service_method("SteamNotification.MarkNotificationsRead#1", &request).await?;
94
95 Ok(())
96 }
97
98 pub async fn request_notifications(&mut self) -> Result<(), SteamError> {
111 if !self.is_logged_in() {
112 return Err(SteamError::NotLoggedOn);
113 }
114
115 let item_request = steam_protos::CMsgClientRequestItemAnnouncements {};
117 self.send_message(steam_enums::EMsg::ClientRequestItemAnnouncements, &item_request).await?;
118
119 let comment_request = steam_protos::CMsgClientRequestCommentNotifications {};
121 self.send_message(steam_enums::EMsg::ClientRequestCommentNotifications, &comment_request).await?;
122
123 let offline_request = steam_protos::CMsgClientRequestOfflineMessageCount {};
125 self.send_message(steam_enums::EMsg::ClientChatRequestOfflineMessageCount, &offline_request).await?;
126
127 Ok(())
128 }
129}