activitystreams_types/activity/
properties.rs

1/*
2 * This file is part of ActivityStreams Types.
3 *
4 * Copyright © 2018 Riley Trautman
5 *
6 * ActivityStreams Types is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ActivityStreams Types is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with ActivityStreams Types.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20//! Namespace for properties of standard Activity types
21//!
22//! To use these properties in your own types, you can flatten them into your struct with serde:
23//!
24//! ```rust
25//! use activitystreams_traits::{Activity, Object};
26//! use activitystreams_types::{
27//!   activity::properties::ActivityProperties,
28//!   object::properties::ObjectProperties,
29//! };
30//! use serde_derive::{Deserialize, Serialize};
31//!
32//! #[derive(Clone, Debug, Serialize, Deserialize)]
33//! #[serde(rename_all = "camelCase")]
34//! pub struct MyActivity {
35//!     #[serde(rename = "type")]
36//!     #[serde(alias = "objectType")]
37//!     #[serde(alias = "verb")]
38//!     pub kind: String,
39//!
40//!     /// Define a require property for the MyActivity type
41//!     pub my_property: String,
42//!
43//!     #[serde(flatten)]
44//!     pub object_properties: ObjectProperties,
45//!
46//!     #[serde(flatten)]
47//!     pub activity_properties: ActivityProperties,
48//! }
49//!
50//! impl Object for MyActivity {}
51//! impl Activity for MyActivity {}
52//! #
53//! # fn main() {}
54//! ```
55
56use activitystreams_derive::Properties;
57use activitystreams_traits::{Link, Object};
58use serde_derive::{Deserialize, Serialize};
59
60/// Activity objects are specializations of the base Object type that provide information about
61/// actions that have either already occurred, are in the process of occurring, or may occur in the
62/// future.
63#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
64#[serde(rename_all = "camelCase")]
65pub struct ActivityProperties {
66    /// Describes the result of the activity.
67    ///
68    /// For instance, if a particular action results in the creation of a new resource, the result
69    /// property can be used to describe that new resource.
70    ///
71    /// - Range: `Object` | `Link`
72    /// - Funcitonal: false
73    #[serde(skip_serializing_if = "Option::is_none")]
74    #[activitystreams(ab(Object, Link), concrete(String))]
75    pub result: Option<serde_json::Value>,
76
77    /// Identifies one or more objects used (or to be used) in the completion of an `Activity`.
78    ///
79    /// - Range: `Object` | `Link`
80    /// - Funcitonal: false
81    #[serde(skip_serializing_if = "Option::is_none")]
82    #[activitystreams(ab(Object, Link), concrete(String))]
83    pub instrument: Option<serde_json::Value>,
84}
85
86/// Struct with `actor` and optional `origin` and `target` properties
87#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
88#[serde(rename_all = "camelCase")]
89pub struct ActorOptOriginAndTarget {
90    /// Describes one or more entities that either performed or are expected to perform the
91    /// activity.
92    ///
93    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
94    /// Link.
95    ///
96    /// - Range: `Object` | `Link`
97    /// - Functional: false
98    #[activitystreams(ab(Object, Link), concrete(String))]
99    pub actor: serde_json::Value,
100
101    /// Describes an indirect object of the activity from which the activity is directed.
102    ///
103    /// The precise meaning of the origin is the object of the English preposition "from". For
104    /// instance, in the activity "John moved an item to List B from List A", the origin of the
105    /// activity is "List A".
106    ///
107    /// - Range: `Object` | `Link`
108    /// - Functional: false
109    #[serde(skip_serializing_if = "Option::is_none")]
110    #[activitystreams(ab(Object, Link), concrete(String))]
111    pub origin: Option<serde_json::Value>,
112
113    /// Describes the indirect object, or target, of the activity.
114    ///
115    /// The precise meaning of the target is largely dependent on the type of action being
116    /// described but will often be the object of the English preposition "to". For instance, in
117    /// the activity "John added a movie to his wishlist", the target of the activity is John's
118    /// wishlist. An activity can have more than one target
119    ///
120    /// - Range: `Object` | `Link`
121    /// - Functional: false
122    #[serde(skip_serializing_if = "Option::is_none")]
123    #[activitystreams(ab(Object, Link), concrete(String))]
124    pub target: Option<serde_json::Value>,
125}
126
127/// Struct with `actor` and `object` properties
128#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
129#[serde(rename_all = "camelCase")]
130pub struct ActorAndObject {
131    /// Describes one or more entities that either performed or are expected to perform the
132    /// activity.
133    ///
134    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
135    /// Link.
136    ///
137    /// - Range: `Object` | `Link`
138    /// - Functional: false
139    #[activitystreams(ab(Object, Link), concrete(String))]
140    pub actor: serde_json::Value,
141
142    /// When used within an Activity, describes the direct object of the activity.
143    ///
144    /// For instance, in the activity "John added a movie to his wishlist", the object of the
145    /// activity is the movie added.
146    ///
147    /// - Range: `Object` | `Link`
148    /// - Functional: false
149    #[activitystreams(ab(Object, Link), concrete(String))]
150    pub object: serde_json::Value,
151}
152
153/// Struct with `actor`, `object`, and `target` properties
154#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
155#[serde(rename_all = "camelCase")]
156pub struct ActorObjectAndTarget {
157    /// Describes one or more entities that either performed or are expected to perform the
158    /// activity.
159    ///
160    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
161    /// Link.
162    ///
163    /// - Range: `Object` | `Link`
164    /// - Functional: false
165    #[activitystreams(ab(Object, Link), concrete(String))]
166    pub actor: serde_json::Value,
167
168    /// When used within an Activity, describes the direct object of the activity.
169    ///
170    /// For instance, in the activity "John added a movie to his wishlist", the object of the
171    /// activity is the movie added.
172    ///
173    /// - Range: `Object` | `Link`
174    /// - Functional: false
175    #[activitystreams(ab(Object, Link), concrete(String))]
176    pub object: serde_json::Value,
177
178    /// Describes the indirect object, or target, of the activity.
179    ///
180    /// The precise meaning of the target is largely dependent on the type of action being
181    /// described but will often be the object of the English preposition "to". For instance, in
182    /// the activity "John added a movie to his wishlist", the target of the activity is John's
183    /// wishlist. An activity can have more than one target
184    ///
185    /// - Range: `Object` | `Link`
186    /// - Functional: false
187    #[activitystreams(ab(Object, Link), concrete(String))]
188    pub target: serde_json::Value,
189}
190
191/// Struct with `actor`, `object`, and optional `target` properties
192#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
193#[serde(rename_all = "camelCase")]
194pub struct ActorAndObjectOptTarget {
195    /// Describes one or more entities that either performed or are expected to perform the
196    /// activity.
197    ///
198    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
199    /// Link.
200    ///
201    /// - Range: `Object` | `Link`
202    /// - Functional: false
203    #[activitystreams(ab(Object, Link), concrete(String))]
204    pub actor: serde_json::Value,
205
206    /// When used within an Activity, describes the direct object of the activity.
207    ///
208    /// For instance, in the activity "John added a movie to his wishlist", the object of the
209    /// activity is the movie added.
210    ///
211    /// - Range: `Object` | `Link`
212    /// - Functional: false
213    #[activitystreams(ab(Object, Link), concrete(String))]
214    pub object: serde_json::Value,
215
216    /// Describes the indirect object, or target, of the activity.
217    ///
218    /// The precise meaning of the target is largely dependent on the type of action being
219    /// described but will often be the object of the English preposition "to". For instance, in
220    /// the activity "John added a movie to his wishlist", the target of the activity is John's
221    /// wishlist. An activity can have more than one target
222    ///
223    /// - Range: `Object` | `Link`
224    /// - Functional: false
225    #[serde(skip_serializing_if = "Option::is_none")]
226    #[activitystreams(ab(Object, Link), concrete(String))]
227    pub target: Option<serde_json::Value>,
228}
229
230/// Struct with `actor`, `object`, and optional `origin` properties
231#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
232#[serde(rename_all = "camelCase")]
233pub struct ActorAndObjectOptOrigin {
234    /// Describes one or more entities that either performed or are expected to perform the
235    /// activity.
236    ///
237    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
238    /// Link.
239    ///
240    /// - Range: `Object` | `Link`
241    /// - Functional: false
242    #[activitystreams(ab(Object, Link), concrete(String))]
243    pub actor: serde_json::Value,
244
245    /// When used within an Activity, describes the direct object of the activity.
246    ///
247    /// For instance, in the activity "John added a movie to his wishlist", the object of the
248    /// activity is the movie added.
249    ///
250    /// - Range: `Object` | `Link`
251    /// - Functional: false
252    #[activitystreams(ab(Object, Link), concrete(String))]
253    pub object: serde_json::Value,
254
255    /// Describes an indirect object of the activity from which the activity is directed.
256    ///
257    /// The precise meaning of the origin is the object of the English preposition "from". For
258    /// instance, in the activity "John moved an item to List B from List A", the origin of the
259    /// activity is "List A".
260    ///
261    /// - Range: `Object` | `Link`
262    /// - Functional: false
263    #[serde(skip_serializing_if = "Option::is_none")]
264    #[activitystreams(ab(Object, Link), concrete(String))]
265    pub origin: Option<serde_json::Value>,
266}
267
268/// Struct with `actor`, `object`, and optional `origin` and `target` properties
269#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
270#[serde(rename_all = "camelCase")]
271pub struct ActorAndObjectOptOthers {
272    /// Describes one or more entities that either performed or are expected to perform the
273    /// activity.
274    ///
275    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
276    /// Link.
277    ///
278    /// - Range: `Object` | `Link`
279    /// - Functional: false
280    #[activitystreams(ab(Object, Link), concrete(String))]
281    pub actor: serde_json::Value,
282
283    /// When used within an Activity, describes the direct object of the activity.
284    ///
285    /// For instance, in the activity "John added a movie to his wishlist", the object of the
286    /// activity is the movie added.
287    ///
288    /// - Range: `Object` | `Link`
289    /// - Functional: false
290    #[activitystreams(ab(Object, Link), concrete(String))]
291    pub object: serde_json::Value,
292
293    /// Describes an indirect object of the activity from which the activity is directed.
294    ///
295    /// The precise meaning of the origin is the object of the English preposition "from". For
296    /// instance, in the activity "John moved an item to List B from List A", the origin of the
297    /// activity is "List A".
298    ///
299    /// - Range: `Object` | `Link`
300    /// - Functional: false
301    #[serde(skip_serializing_if = "Option::is_none")]
302    #[activitystreams(ab(Object, Link), concrete(String))]
303    pub origin: Option<serde_json::Value>,
304
305    /// Describes the indirect object, or target, of the activity.
306    ///
307    /// The precise meaning of the target is largely dependent on the type of action being
308    /// described but will often be the object of the English preposition "to". For instance, in
309    /// the activity "John added a movie to his wishlist", the target of the activity is John's
310    /// wishlist. An activity can have more than one target
311    ///
312    /// - Range: `Object` | `Link`
313    /// - Functional: false
314    #[serde(skip_serializing_if = "Option::is_none")]
315    #[activitystreams(ab(Object, Link), concrete(String))]
316    pub target: Option<serde_json::Value>,
317}
318
319/// Struct with `actor` and `origin` properties
320#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
321#[serde(rename_all = "camelCase")]
322pub struct ActorAndOrigin {
323    /// Describes one or more entities that either performed or are expected to perform the
324    /// activity.
325    ///
326    /// Any single activity can have multiple actors. The actor MAY be specified using an indirect
327    /// Link.
328    ///
329    /// - Range: `Object` | `Link`
330    /// - Functional: false
331    #[activitystreams(ab(Object, Link), concrete(String))]
332    pub actor: serde_json::Value,
333
334    /// Describes an indirect object of the activity from which the activity is directed.
335    ///
336    /// The precise meaning of the origin is the object of the English preposition "from". For
337    /// instance, in the activity "John moved an item to List B from List A", the origin of the
338    /// activity is "List A".
339    ///
340    /// - Range: `Object` | `Link`
341    /// - Functional: false
342    #[activitystreams(ab(Object, Link), concrete(String))]
343    pub origin: serde_json::Value,
344}
345
346/// Properties for the Accept activity
347pub type AcceptProperties = ActorAndObject;
348
349/// Properties for the Add activity
350pub type AddProperties = ActorAndObject;
351
352/// Properties for the Move activity
353pub type MoveProperties = ActorAndObjectOptOthers;
354
355/// Properties for the Announce activity
356pub type AnnounceProperties = ActorAndObjectOptTarget;
357
358/// Properties for the Arrive activity
359pub type ArriveProperties = ActorAndOrigin;
360
361/// Properties for the Block activity
362pub type BlockProperties = ActorAndObject;
363
364/// Properties for the Create activity
365pub type CreateProperties = ActorAndObject;
366
367/// Properties for the Delete activity
368pub type DeleteProperties = ActorAndObjectOptOrigin;
369
370/// Properties for the Dislike activity
371pub type DislikeProperties = ActorAndObject;
372
373/// Properties for the Flag activity
374pub type FlagProperties = ActorAndObject;
375
376/// Properties for the Follow activity
377pub type FollowProperties = ActorAndObject;
378
379/// Properties for the Ignore activity
380pub type IgnoreProperties = ActorAndObject;
381
382/// Properties for the Invite activity
383pub type InviteProperties = ActorObjectAndTarget;
384
385/// Properties for the Join activity
386pub type JoinProperties = ActorAndObject;
387
388/// Properties for the Leave activity
389pub type LeaveProperties = ActorAndObject;
390
391/// Properties for the Like activity
392pub type LikeProperties = ActorAndObject;
393
394/// Properties for the Listen activity
395pub type ListenProperties = ActorAndObject;
396
397/// Properties for the Offer activity
398pub type OfferProperties = ActorAndObjectOptTarget;
399
400/// Properties for the Question activity
401#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
402#[serde(rename_all = "camelCase")]
403pub struct QuestionProperties {
404    /// Identifies an exclusive option for a Question.
405    ///
406    /// Use of `one_of` implies that the Question can have only a single answer. To indicate that a
407    /// `Question` can have multiple answers, use `any_of`.
408    ///
409    /// - Range: `Object` | `Link`
410    /// - Functional: false
411    #[serde(skip_serializing_if = "Option::is_none")]
412    #[activitystreams(ab(Object, Link), concrete(String))]
413    pub one_of: Option<serde_json::Value>,
414
415    /// Identifies an inclusive option for a Question.
416    ///
417    /// Use of `any_of` implies that the Question can have multiple answers. To indicate that a
418    /// `Question` can have only one answer, use `one_of`.
419    ///
420    /// - Range: `Object` | `Link`
421    /// - Functional: false
422    #[serde(skip_serializing_if = "Option::is_none")]
423    #[activitystreams(ab(Object, Link), concrete(String))]
424    pub any_of: Option<serde_json::Value>,
425}
426
427/// Properties for the Read activity
428pub type ReadProperties = ActorAndObject;
429
430/// Properties for the Reject activity
431pub type RejectProperties = ActorAndObject;
432
433/// Properties for the Remove activity
434pub type RemoveProperties = ActorAndObjectOptOthers;
435
436/// Properties for the TentativeAccept activity
437pub type TentativeAcceptProperties = ActorAndObject;
438
439/// Properties for the TentativeReject activity
440pub type TentativeRejectProperties = ActorAndObject;
441
442/// Properties for the Travel activity
443pub type TravelProperties = ActorOptOriginAndTarget;
444
445/// Properties for the Undo activity
446pub type UndoProperties = ActorAndObject;
447
448/// Properties for the Update activity
449pub type UpdateProperties = ActorAndObject;
450
451/// Properties for the View activity
452pub type ViewProperties = ActorAndObject;