| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- diff --git a/src/api/workshop.rs b/src/api/workshop.rs
- index c8482ca..3046cbe 100644
- --- a/src/api/workshop.rs
- +++ b/src/api/workshop.rs
- @@ -7,7 +7,7 @@ pub mod workshop {
- use napi::threadsafe_function::ThreadsafeFunction;
- use napi::threadsafe_function::ThreadsafeFunctionCallMode;
- use std::path::Path;
- - use steamworks::{ClientManager, FileType, PublishedFileId, UpdateHandle};
- + use steamworks::{AppId, ClientManager, FileType, PublishedFileId, UpdateHandle};
- use tokio::sync::oneshot;
-
- #[napi(object)]
- @@ -108,6 +108,13 @@ pub mod workshop {
- pub total: BigInt,
- }
-
- + #[napi(object)]
- + pub struct UserItemVote {
- + pub voted_up: bool,
- + pub voted_down: bool,
- + pub vote_skipped: bool,
- + }
- +
- #[derive(Debug)]
- #[napi]
- pub enum UpdateStatus {
- @@ -320,6 +327,90 @@ pub mod workshop {
- }
- }
-
- + /// Sets the current user's vote (up or down) on a workshop item.
- + ///
- + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#SetUserItemVote}
- + #[napi]
- + pub async fn vote_item(item_id: BigInt, vote_up: bool) -> Result<(), Error> {
- + let client = crate::client::get_client();
- + let (tx, rx) = oneshot::channel();
- +
- + client
- + .ugc()
- + .vote_up_item(PublishedFileId(item_id.get_u64().1), vote_up, |result| {
- + tx.send(result).unwrap();
- + });
- +
- + let result = rx.await.unwrap();
- + match result {
- + Ok(()) => Ok(()),
- + Err(e) => Err(Error::from_reason(e.to_string())),
- + }
- + }
- +
- + /// Adds a workshop item to the current user's favorites list.
- + ///
- + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#AddItemToFavorites}
- + #[napi]
- + pub async fn add_favorite(app_id: u32, item_id: BigInt) -> Result<(), Error> {
- + let client = crate::client::get_client();
- + let (tx, rx) = oneshot::channel();
- +
- + client.ugc().add_item_to_favorites(
- + AppId(app_id),
- + PublishedFileId(item_id.get_u64().1),
- + |result| {
- + tx.send(result).unwrap();
- + },
- + );
- +
- + rx.await.unwrap().map_err(|e| Error::from_reason(e.to_string()))
- + }
- +
- + /// Removes a workshop item from the current user's favorites list.
- + ///
- + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#RemoveItemFromFavorites}
- + #[napi]
- + pub async fn remove_favorite(app_id: u32, item_id: BigInt) -> Result<(), Error> {
- + let client = crate::client::get_client();
- + let (tx, rx) = oneshot::channel();
- +
- + client.ugc().remove_item_from_favorites(
- + AppId(app_id),
- + PublishedFileId(item_id.get_u64().1),
- + |result| {
- + tx.send(result).unwrap();
- + },
- + );
- +
- + rx.await.unwrap().map_err(|e| Error::from_reason(e.to_string()))
- + }
- +
- + /// Gets the current user's existing vote (if any) on a workshop item.
- + ///
- + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetUserItemVote}
- + #[napi]
- + pub async fn get_user_vote(item_id: BigInt) -> Result<UserItemVote, Error> {
- + let client = crate::client::get_client();
- + let (tx, rx) = oneshot::channel();
- +
- + client
- + .ugc()
- + .user_item_vote(PublishedFileId(item_id.get_u64().1), |result| {
- + tx.send(result).unwrap();
- + });
- +
- + let result = rx.await.unwrap();
- + match result {
- + Ok(v) => Ok(UserItemVote {
- + voted_up: v.voted_up,
- + voted_down: v.voted_down,
- + vote_skipped: v.vote_skipped,
- + }),
- + Err(e) => Err(Error::from_reason(e.to_string())),
- + }
- + }
- +
- /// Gets the current state of a workshop item on this client. States can be combined.
- ///
- /// @returns a number with the current item state, e.g. 9
|