View Source Bonfire.Me.Characters (Bonfire v0.9.11-social-beta.6)

Shared helpers for character types (such as User or Category)

Context for Bonfire.Data.Identity.Character mixin, which has these fields:

  • username
  • username_hash: hashed username (used for preserving uniqueness incl. deleted usernames)
  • outbox: Feed of activities by the user
  • inbox: Feed of messages and other activities for the user
  • notifications: Feed of notifications for the user

Summary

Functions

Retrieves a character by username.

Returns the appropriate mention prefix for a character type.

Returns the canonical URL for a character.

Cleans a username by replacing forbidden characters with underscores.

Retrieves multiple characters by IDs.

Checks if a username hash is available.

Deletes a character by username hash.

Updates a character with the given attributes.

Checks if a username is available.

Functions

by_username(username)

Retrieves a character by username.

Examples

> Bonfire.Me.Characters.by_username("username")
%Bonfire.Data.Identity.Character{}

by_username!(username)

by_username_q(username)

changeset(char \\ %Character{}, params, profile \\ :local)

character_mention_prefix(object)

Returns the appropriate mention prefix for a character type.

Examples

iex> Bonfire.Me.Characters.character_mention_prefix(%Bonfire.Data.Identity.User{})
"@"

character_url(character)

Returns the canonical URL for a character.

Examples

iex> Bonfire.Me.Characters.character_url(%Bonfire.Data.Identity.Character{})
"http://example.com/character/username"

clean_username(username)

Cleans a username by replacing forbidden characters with underscores.

Examples

iex> Bonfire.Me.Characters.clean_username("invalid username!")
"invalid_username"

display_username(user, always_include_domain \\ false, is_local? \\ nil, prefix \\ nil)

Displays a username with optional domain and prefix.

Examples

iex> Bonfire.Me.Characters.display_username("username")
"@username"

iex> Bonfire.Me.Characters.display_username("username", true, true, "@")
"@username@domain.com"

get(ids)

Retrieves multiple characters by IDs.

Examples

> Bonfire.Me.Characters.get("id_or_username")
%Bonfire.Data.Identity.Character{}

> Bonfire.Me.Characters.get(["id1", "id2"])
{:ok, [%Bonfire.Data.Identity.Character{}, %Bonfire.Data.Identity.Character{}]}

hash_available?(hash)

Checks if a username hash is available.

Examples

iex> Bonfire.Me.Characters.hash_available?("hash")
true

hash_delete(hash)

Deletes a character by username hash.

Examples

> Bonfire.Me.Characters.hash_delete("hash")

indexing_object_format(obj)

q_by_id(ids)

remote_changeset(changeset, params)

schema_module()

Callback implementation for Bonfire.Common.QueryModule.schema_module/0.

update(character, attrs)

Updates a character with the given attributes.

Examples

> Bonfire.Me.Characters.update(%Bonfire.Data.Identity.Character{}, %{field: "value"})
{:ok, %Bonfire.Data.Identity.Character{}}

username_available?(username)

Checks if a username is available.

Examples

iex> Bonfire.Me.Characters.username_available?("non_existing_username")
true