use std::string;
use sui::clock;
use sui::coin;
use sui::event;
use sui::sui;
use sage_admin::admin;
use sage_admin::admin_access;
use sage_admin::apps;
use sage_admin::fees;
use sage_analytics::analytics_actions;
use sage_post::post;
use sage_post::post_actions;
use sage_post::post_fees;
use sage_reward::reward_actions;
use sage_reward::reward_registry;
use sage_shared::membership;
use sage_trust::trust;
use sage_trust::trust_access;
use sage_user::user_fees;
use sage_user::user_invite;
use sage_user::user_owned;
use sage_user::user_registry;
use sage_user::user_shared;
use sage_user::user_witness;
use sage_utils::string_helpers;
Explore this module further in the Mover Registry: @sage/user

Events

ChannelFavoritesUpdate

Emitted when a User favorites or unfavorites a Channel.
public struct ChannelFavoritesUpdate has copy, drop

InviteCreated

Emitted when a new Invite is created.
public struct InviteCreated has copy, drop

PostFavoritesUpdate

Emitted when a User favorites or unfavorites a Post.
public struct PostFavoritesUpdate has copy, drop

UserCreated

Emitted when a new User is created.
public struct UserCreated has copy, drop

UserFavoritesUpdate

Emitted when a User favorites or unfavorites a User.
public struct UserFavoritesUpdate has copy, drop

UserFollowsUpdate

Emitted when a User follows or unfollows another User.
public struct UserFollowsUpdate has copy, drop

UserFriendUpdate

Emitted when a User confirms friendship or unfriends another User.
public struct UserFriendUpdate has copy, drop

UserFriendRequestUpdate

Emitted when a User requests friendship with another User.
public struct UserFriendRequestUpdate has copy, drop

UserPostCreated

Emitted when a new Post is created for a User.
public struct UserPostCreated has copy, drop

UserUpdated

Emitted when a User is updated.
public struct UserUpdated has copy, drop

Constants

Maximum number of characters for User description.
const DESCRIPTION_MAX_LENGTH: u64 = 370;
Minimum number of characters for User name.
const USERNAME_MIN_LENGTH: u64 = 3;
Maximum number of characters for User name.
const USERNAME_MAX_LENGTH: u64 = 20;
User actions that are tracked by Analytics that result in $TRUST rewards.
const METRIC_COMMENT_GIVEN: vector<u8> = b"comment-given";
const METRIC_COMMENT_RECEIVED: vector<u8> = b"comment-received";
const METRIC_FAVORITED_POST: vector<u8> = b"favorited-post";
const METRIC_FOLLOWED_USER: vector<u8> = b"followed-user";
const METRIC_LIKED_POST: vector<u8> = b"liked-post";
const METRIC_POST_FAVORITED: vector<u8> = b"post-favorited";
const METRIC_POST_LIKED: vector<u8> = b"post-liked";
const METRIC_USER_FOLLOWED: vector<u8> = b"user-followed";
const METRIC_USER_FRIENDS: vector<u8> = b"user-friends";
const METRIC_USER_TEXT_POST: vector<u8> = b"user-text-posts";
Error code for invalid User description.
const EInvalidUserDescription: u64 = 370;
Error code for invalid User name.
const EInvalidUsername: u64 = 371;
Error code for attempt to create a User without a (required) Invite.
const EInviteRequired: u64 = 372;
Error code for attempting to friend or follow the User’s own User.
const ENoSelfJoin: u64 = 373;
Error code for attempting to update metadata for another’s User.
const ENotSelf: u64 = 374;
Error code for supplying a User who is not the author of a Post.
const ESuppliedAuthorMismatch: u64 = 375;
Error code for attempting to change the name for the User. Only the casing may be changed (e.g. “user” to “USER”)
const EUserNameMismatch: u64 = 376;

Functions

add_favorite_channel

Allows a User to add a favorite Channel within an App. Aborts with ETypeMismatch if ChannelType is not a Channel.
public fun add_favorite_channel<ChannelType: key> (app: &App, clock: &Clock, channel: &ChannelType, channel_config: &ChannelConfig, owned_user: &mut UserOwned, ctx: &mut TxContext)

add_favorite_post

Allows a User to add a favorite Post within an App. Aborts with ESuppliedAuthorMismatch if the supplied SharedUser is not the author of the Post.
public fun add_favorite_post(app: &App, clock: &Clock, owned_user: &mut UserOwned, post: &Post, reward_weights_registry: &RewardWeightsRegistry, user: &mut UserShared, user_witness_config: &UserWitnessConfig, ctx: &mut TxContext)

add_favorite_user

Allows a User to add a favorite User within an App.
public fun add_favorite_user(app: &App, clock: &Clock, owned_user: &mut UserOwned, user: &UserShared, ctx: &mut TxContext)

assert_user_description

Aborts with EInvalidUserDescription if the description is invalid.
public fun assert_user_description(description: &String)

assert_user_name

Aborts with EInvalidUsername if the name is invalid.
public fun assert_user_name(name: &String)

claim_reward

If User has an available claim on the App and for the specified epoch, then mints $TRUST and transfers it to the User’s wallet. Aborts with ENotSelf if the SharedUser does not belong to the wallet address.
public fun claim_reward(app: &App, mint_config: &MintConfig, reward_witness_config: &RewardWitnessConfig, treasury: &mut ProtectedTreasury, owned_user: &mut UserOwned, shared_user: &mut UserShared, user_witness_config: &UserWitnessConfig, epoch: u64, ctx: &mut TxContext)

comment

Create a comment on a Post. Aborts with ESuppliedAuthorMismatch if the supplied SharedUser is not the author of the parent Post.
public fun comment<CoinType> (app: &App, clock: &Clock, owned_user: &mut UserOwned, parent_post: &mut Post, post_fees: &PostFees, reward_weights_registry: &RewardWeightsRegistry, shared_user: &mut UserShared, user_witness_config: &UserWitnessConfig, data: String, description: String, title: String, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext): (address, address, u64)

create

Create a new User. Aborts with EInvalidUserDescription or EInvalidUsername if the description or name is invalid, EInviteRequired if an Invite is required and not supplied, EInviteDoesNotExist if invite info was supplied but does not exist in the registry, EInviteInvalid if invite info was supplied but is not valid, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun create<CoinType> (clock: &Clock, invite_config: &InviteConfig, user_registry: &mut UserRegistry, user_invite_registry: &mut UserInviteRegistry, user_fees: &UserFees, invite_code_option: Option<String>, invite_key_option: Option<String>, avatar: String, banner: String, description: String, name: String, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext): (address, address)

create_invite

Create an invite for another wallet address. Aborts with EInviteNotAllowed if invites are required, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun create_invite<CoinType> (invite_config: &InviteConfig, user_fees: &UserFees, user_invite_registry: &mut UserInviteRegistry, _: &UserOwned, invite_code: String, invite_hash: vector<u8>, invite_key: String, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

follow

User follows another User within an App. Aborts with ENoSelfJoin if attempting to follow one’s self, EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun follow<CoinType> (app: &App, clock: &Clock, owned_user: &mut UserOwned, reward_weights_registry: &RewardWeightsRegistry, shared_user: &mut UserShared, user_fees: &UserFees, user_witness_config: &UserWitnessConfig, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

friend_user

Creates a friend request between two Users if one does not exist, or creates a friendship if the other User had already requested to be friends. Aborts with ENotSelf if attempting to friend one’s self, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun friend_user<CoinType> (app: &App, clock: &Clock, reward_weights_registry: &RewardWeightsRegistry, user_fees: &UserFees, user_friend: &mut UserShared, user_shared: &mut UserShared, user_witness_config: &UserWitnessConfig, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

like_post

User likes a Post. Aborts with ESuppliedAuthorMismatch if the SharedUser is not the author of the Post, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun like_post<CoinType> (app: &App, clock: &Clock, owned_user: &mut UserOwned, post: &mut Post, post_fees: &PostFees, reward_weights_registry: &RewardWeightsRegistry, royalties: &Royalties, shared_user: &mut UserShared, user_witness_config: &UserWitnessConfig, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

post

Creates a Post on the User and returns the Post address and timestamp that it was made. Aborts with EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun post<CoinType> (app: &App, clock: &Clock, owned_user: &mut UserOwned, reward_weights_registry: &RewardWeightsRegistry, shared_user: &mut UserShared, user_fees: &UserFees, user_witness_config: &UserWitnessConfig, data: String, description: String, title: String, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext): (address, u64)

remove_favorite_channel

Removes a Channel from being a favorite within an App.
public fun remove_favorite_channel<ChannelType: key> (app: &App, clock: &Clock, channel: &ChannelType, owned_user: &mut UserOwned, ctx: &mut TxContext)

remove_favorite_post

Removes a Post from being a favorite within an App.
public fun remove_favorite_post(app: &App, clock: &Clock, owned_user: &mut UserOwned, post: &Post, ctx: &mut TxContext)

remove_favorite_user

Removes a User from being a favorite within an App.
public fun remove_favorite_user(app: &App, clock: &Clock, owned_user: &mut UserOwned, user: &UserShared, ctx: &mut TxContext)

remove_friend_request

Removes a friend request to the User if they do not wish to connect to the requester. Aborts with ENotSelf if the SharedUser does not belong to the wallet address or if the request is not affiliated with the provided SharedUser.
public fun remove_friend_request(app: &App, clock: &Clock, shared_user: &mut UserShared, removed_request: address, ctx: &mut TxContext)

unfollow

Unfollow a User. Aborts with EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun unfollow<CoinType> (app: &App, clock: &Clock, shared_user: &mut UserShared, user_fees: &UserFees, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

unfriend_user

Removes friendship between Users. Aborts with ENotSelf if the wallet does not own the OwnedUser or SharedUser, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun unfriend_user<CoinType> (app: &App, clock: &Clock, user_fees: &UserFees, user_friend: &mut UserShared, user_shared: &mut UserShared, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)

update

Updates metadata on the OwnedUser. Aborts with EUserNameMismatch if attempting to change the name, or EIncorrectCoinType, EIncorrectCustomPayment, or EIncorrectSuiPayment if the payment was incorrect.
public fun update<CoinType> (clock: &Clock, user_registry: &UserRegistry, user_fees: &UserFees, owned_user: &mut UserOwned, avatar: String, banner: String, description: String, name: String, custom_payment: Coin<CoinType>, sui_payment: Coin<SUI>, ctx: &mut TxContext)