|
| 1 | +# <a name="userPreferences">User Preferences</a> |
| 2 | + |
| 3 | +## Reading user preferences |
| 4 | + |
| 5 | +User preferences are stored against a user's profile and can be retrieved with `agent.GetPreferences()`. |
| 6 | + |
| 7 | +```c# |
| 8 | +var userPreferences = await agent.GetPreferences(); |
| 9 | +``` |
| 10 | + |
| 11 | +The `Bluesky.Actor.Preferences` class is both a list of user preferences, but also has properties for the commonly used preferences. These include |
| 12 | + |
| 13 | +* `LabelersPreference` - a list of labelers the user has subscribed to. |
| 14 | +* `ContentLabelPeference` - a list of preferences for content labelling, the DID of the labeler that produces it and the visibility of content that is labeled. |
| 15 | +* `SavedFeedPreference2` - a list of saved feeds. |
| 16 | +* `HiddenPosts` - a list of AT URIs for posts the user has hidden. |
| 17 | +* `AdultContentPreferences` - the users preferences for the display of adult content. |
| 18 | +* `FeedViewPreferences` - how the user wants to view their feeds, include settings for hiding replies, hiding replies by actors they don't follow etc. |
| 19 | +* `MutedWords` - a list of words the user does not want to see, including settings for expiry of the mute, whether if applies to everyone or just actors they don't follow, etc. |
| 20 | +* `ThreadViewPreferences` - how the user would like threads to be displayed in a client. |
| 21 | +* `InteractionPreferences` - the [thread gates](threadGatesAndPostGates.md#threadGates) and [post gates](threadGatesAndPostGates.md#postGates) the user would like applied to new threads or posts they create. |
| 22 | + |
| 23 | +Most of these preferences must be implemented within your client, they are not applied on the Bluesky backend. |
| 24 | + |
| 25 | +For example, the `LabelersPreference` affects the `Labels` attached to content, but you must pass it into API calls that retrieve posts and threads. |
| 26 | + |
| 27 | +```c# |
| 28 | +Preferences preferences = new(); |
| 29 | +var preferencesResult = await agent.GetPreferences(cancellationToken: cancellationToken); |
| 30 | +if (preferencesResult.Succeeded) |
| 31 | +{ |
| 32 | + preferences = preferencesResult.Result; |
| 33 | +} |
| 34 | + |
| 35 | +var timelineResult = await agent.GetTimeline( |
| 36 | + limit: pageSize, |
| 37 | + subscribedLabelers: preferences.SubscribedLabelers); |
| 38 | +``` |
| 39 | + |
| 40 | +The same applies to `InteractionPreferences`, which you must pass into any of the `Post` methods, or apply to a `PostBuilder`. |
| 41 | + |
| 42 | +```c# |
| 43 | +var interactionPreferences = null; |
| 44 | +var userPreferences = await agent.GetPreferences(cancellationToken: cancellationToken); |
| 45 | +if (userPreferences.Succeeded) |
| 46 | +{ |
| 47 | + interactionPreferences = userPreferences.Result.InteractionPreferences; |
| 48 | +} |
| 49 | + |
| 50 | +await agent.Post( |
| 51 | + "Post, using default preferences, if any", |
| 52 | + interactionPreferences: interactionPreferences); |
| 53 | +``` |
| 54 | + |
| 55 | +For things like `MutedWords` you will need to implement the logic to filter out posts that contain muted words, or for `LabelersPreference` you |
| 56 | +need to implement the logic to label or hide according to the user preferences. |
| 57 | + |
| 58 | +## Writing user preferences |
| 59 | + |
| 60 | +You can write user preferences with `agent.PutPreferences()`. This method takes a `Preferences` list and will update the user's preferences. |
| 61 | +There is also an `agent.PutPreference()` should you only want to update a single preference. You do not have to supply the full list of preferences |
| 62 | +returned by `GetPreferences()` only the ones you want to change, for example |
| 63 | + |
| 64 | +```c# |
| 65 | +var updatedPreference = new ThreadViewPreference() |
| 66 | +{ |
| 67 | + PrioritizeFollowedUsers = true |
| 68 | +}; |
| 69 | + |
| 70 | +await agent.PutPreference(updatedPreference, cancellationToken: cancellationToken); |
| 71 | +``` |
0 commit comments