1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
//! User interface
use crate::prelude::*;
use crate::types::files::File;
use crate::types::games::Game;
use crate::types::id::UserId;
use crate::types::mods::Mod;
pub use crate::types::mods::Rating;
pub use crate::types::{Avatar, User};
pub use crate::types::{Event, EventType};
/// Interface for resources owned by the authenticated user or is team member of.
#[derive(Clone)]
pub struct Me {
modio: Modio,
}
impl Me {
pub(crate) fn new(modio: Modio) -> Self {
Self { modio }
}
/// Returns the current user if authenticated.
pub async fn current(self) -> Result<Option<User>> {
if self.modio.inner.credentials.token.is_some() {
let user = self.modio.request(Route::UserAuthenticated).send().await?;
Ok(Some(user))
} else {
Ok(None)
}
}
/// Returns a `Query` interface to retrieve all games the authenticated user added or
/// is team member of. [required: token]
///
/// See [Filters and sorting](filters::games).
pub fn games(&self, filter: Filter) -> Query<Game> {
Query::new(self.modio.clone(), Route::UserGames, filter)
}
/// Returns a `Query` interface to retrieve all mods the authenticated user added or
/// is team member of. [required: token]
///
/// See [Filters and sorting](filters::mods).
pub fn mods(&self, filter: Filter) -> Query<Mod> {
Query::new(self.modio.clone(), Route::UserMods, filter)
}
/// Returns a `Query` interface to retrieve all modfiles the authenticated user uploaded.
/// [required: token]
///
/// See [Filters and sorting](filters::files).
pub fn files(&self, filter: Filter) -> Query<File> {
Query::new(self.modio.clone(), Route::UserFiles, filter)
}
/// Returns a `Query` interface to retrieve the events that have been fired specific to the
/// authenticated user. [required: token]
///
/// See [Filters and sorting](filters::events).
pub fn events(self, filter: Filter) -> Query<Event> {
Query::new(self.modio, Route::UserEvents, filter)
}
/// Returns a `Query` interface to retrieve the mods the authenticated user is subscribed to.
/// [required: token]
///
/// See [Filters and sorting](filters::subscriptions).
pub fn subscriptions(self, filter: Filter) -> Query<Mod> {
Query::new(self.modio, Route::UserSubscriptions, filter)
}
/// Returns a `Query` interface to retrieve the mod ratings submitted by the authenticated user.
/// [required: token]
///
/// See [Filters and sorting](filters::ratings).
pub fn ratings(self, filter: Filter) -> Query<Rating> {
Query::new(self.modio, Route::UserRatings, filter)
}
/// Get all users muted by the authenticated user. [required: token]
pub fn muted_users(self) -> Query<User> {
Query::new(self.modio, Route::UserMuted, Filter::default())
}
/// Mute a user. [required: token]
///
/// This will prevent mod.io from returning mods authored by the muted user.
pub async fn mute_user(self, user_id: UserId) -> Result<()> {
self.modio.request(Route::MuteUser { user_id }).send().await
}
/// Unmute a previously muted user. [required: token]
///
/// This will re-enable mod.io return mods authored by the muted user again.
pub async fn unmute_user(self, user_id: UserId) -> Result<()> {
self.modio
.request(Route::UnmuteUser { user_id })
.send()
.await
}
}
/// Filters for events, subscriptions and ratings.
#[rustfmt::skip]
pub mod filters {
#[doc(inline)]
pub use crate::games::filters as games;
#[doc(inline)]
pub use crate::mods::filters as mods;
#[doc(inline)]
pub use crate::files::filters as files;
/// User event filters and sorting.
///
/// # Filters
/// - `Id`
/// - `GameId`
/// - `ModId`
/// - `UserId`
/// - `DateAdded`
/// - `EventType`
///
/// # Sorting
/// - `Id`
/// - `DateAdded`
///
/// See the [modio docs](https://docs.mod.io/#get-user-events) for more information.
///
/// By default this returns up to `100` items. You can limit the result by using `limit` and
/// `offset`.
///
/// # Example
/// ```
/// use modio::filter::prelude::*;
/// use modio::mods::EventType;
/// use modio::user::filters::events::EventType as Filter;
///
/// let filter = Id::gt(1024).and(Filter::eq(EventType::MODFILE_CHANGED));
/// ```
pub mod events {
#[doc(inline)]
pub use crate::filter::prelude::Id;
#[doc(inline)]
pub use crate::filter::prelude::ModId;
#[doc(inline)]
pub use crate::filter::prelude::DateAdded;
#[doc(inline)]
pub use crate::mods::filters::events::UserId;
#[doc(inline)]
pub use crate::mods::filters::events::EventType;
filter!(GameId, GAME_ID, "game_id", Eq, NotEq, In, Cmp, OrderBy);
}
/// Subscriptions filters and sorting.
///
/// # Filters
/// - `Fulltext`
/// - `Id`
/// - `GameId`
/// - `Status`
/// - `Visible`
/// - `SubmittedBy`
/// - `DateAdded`
/// - `DateUpdated`
/// - `DateLive`
/// - `MaturityOption`
/// - `Name`
/// - `NameId`
/// - `Summary`
/// - `Description`
/// - `Homepage`
/// - `Modfile`
/// - `MetadataBlob`
/// - `MetadataKVP`
/// - `Tags`
///
/// # Sorting
/// - `Id`
/// - `Name`
/// - `Downloads`
/// - `Popular`
/// - `Ratings`
/// - `Subscribers`
///
/// See the [mod.io docs](https://docs.mod.io/#get-user-subscriptions) for more information.
///
/// By default this returns up to `100` items. you can limit the result by using `limit` and
/// `offset`.
///
/// # Example
/// ```
/// use modio::filter::prelude::*;
/// use modio::user::filters::subscriptions::Id;
///
/// let filter = Id::_in(vec![1, 2]).order_by(Id::desc());
/// ```
pub mod subscriptions {
#[doc(inline)]
pub use crate::filter::prelude::Fulltext;
#[doc(inline)]
pub use crate::filter::prelude::Id;
#[doc(inline)]
pub use crate::filter::prelude::Name;
#[doc(inline)]
pub use crate::filter::prelude::NameId;
#[doc(inline)]
pub use crate::mods::filters::GameId;
#[doc(inline)]
pub use crate::mods::filters::Status;
#[doc(inline)]
pub use crate::mods::filters::Visible;
#[doc(inline)]
pub use crate::mods::filters::SubmittedBy;
#[doc(inline)]
pub use crate::mods::filters::DateAdded;
#[doc(inline)]
pub use crate::mods::filters::DateUpdated;
#[doc(inline)]
pub use crate::mods::filters::DateLive;
#[doc(inline)]
pub use crate::mods::filters::MaturityOption;
#[doc(inline)]
pub use crate::mods::filters::Summary;
#[doc(inline)]
pub use crate::mods::filters::Description;
#[doc(inline)]
pub use crate::mods::filters::Homepage;
#[doc(inline)]
pub use crate::mods::filters::Modfile;
#[doc(inline)]
pub use crate::mods::filters::MetadataBlob;
#[doc(inline)]
pub use crate::mods::filters::MetadataKVP;
#[doc(inline)]
pub use crate::mods::filters::Tags;
#[doc(inline)]
pub use crate::mods::filters::Downloads;
#[doc(inline)]
pub use crate::mods::filters::Popular;
#[doc(inline)]
pub use crate::mods::filters::Ratings;
#[doc(inline)]
pub use crate::mods::filters::Subscribers;
}
/// Rating filters and sorting.
///
/// # Filters
/// - `GameId`
/// - `ModId`
/// - `Rating`
/// - `DateAdded`
///
/// # Sorting
/// - `GameId`
/// - `ModId`
/// - `Rating`
/// - `DateAdded`
///
/// See the [mod.io docs](https://docs.mod.io/#get-user-ratings) for more information.
///
/// By default this returns up to `100` items. You can limit the result by using `limit` and
/// `offset`.
///
/// # Example
/// ```
/// use modio::filter::prelude::*;
/// use modio::user::filters::ratings::GameId;
/// use modio::user::filters::ratings::DateAdded;
/// use modio::user::filters::ratings::Rating;
///
/// let filter = GameId::_in(vec![1, 2]).order_by(DateAdded::desc());
///
/// let filter = Rating::positive().order_by(DateAdded::desc());
/// ```
pub mod ratings {
use crate::filter::prelude::*;
#[doc(inline)]
pub use crate::filter::prelude::ModId;
filter!(GameId, GAME_ID, "game_id", Eq, NotEq, In, Cmp, OrderBy);
filter!(Rating, RATING, "rating", Eq, NotEq, In, Cmp, OrderBy);
filter!(DateAdded, DATE_ADDED, "date_added", Eq, NotEq, In, Cmp, OrderBy);
impl Rating {
pub fn positive() -> Filter {
Rating::eq(1)
}
pub fn negative() -> Filter {
Rating::eq(-1)
}
}
}
}