Convos::Core::Backend - Convos storage backend

  1. DESCRIPTION
  2. ATTRIBUTES
  3. METHODS
    1. connections_p
    2. delete_messages_p
    3. delete_object_p
    4. emit_p
    5. files_p
    6. load_object_p
    7. messages_p
    8. new
    9. notifications_p
    10. save_object_p
    11. users_p
  4. SEE ALSO

DESCRIPTION

Convos::Core::Backend is a base class for storage backends. See Convos::Core::Backend::File for code that actually perist data.

ATTRIBUTES

Convos::Core::Backend inherits all attributes from Mojo::EventEmitter and implements the following new ones.

METHODS

Convos::Core::Backend inherits all methods from Mojo::EventEmitter and implements the following new ones.

connections_p

$p = $backend->connections($user)->then(sub { my $connections = shift });

Used to find a list of connection names for a given $user.

delete_messages_p

$p = $backend->delete_object_p($obj)->then(sub { my $obj = shift });

This method will delete all messages for a given conversation.

delete_object_p

$p = $backend->delete_object_p($obj)->then(sub { my $obj = shift });

This method is called to remove a given object from persistent storage.

emit_p

$p = $backend->emit_p($name => @args);

Will call each event handler registered in reverse, and return the first promise returned by a callback. A rejected promise will be returned if no event is registered or no callbacks returns a promise.

$backend->on(cool_beans => sub { return Mojo::Promise->resolve if rand > 0.5 });
$backend->emit_p('cool_beans')->then(sub { ... });

files_p

$p = $backend->files_p($user, {after => '...', limit => 60})->then(sub { my $c = shift });

Gets a list of uploaded files for a Convos::Core::User. after optional, but can be set to a given file id to provide pagination. $c is a Mojo::Collection containing file information.

load_object_p

$p = $backend->load_object_p($obj)->then(sub { my $obj = shift });

This method will load $data for $obj.

messages_p

$p = $backend->messages_p(\%query)->then(sub { my $res = shift; });

Used to search for messages stored in backend. The callback will be called with the messages found.

Possible %query:

{
  after  => $datetime, # find messages after a given ISO 8601 timestamp
  before => $datetime, # find messages before a given ISO 8601 timestamp
  level  => $str,      # debug, info (default), warn, error
  limit  => $int,      # max number of messages to retrieve
  match  => $regexp,   # filter messages by a regexp
}

$res will contain:

{
  end      => true,
  messages => [...],
}

new

Will also call _setup() after the object is created.

notifications_p

$p = $backend->notifications_p($user, \%query)->then(sub { my $res = shift; });

This method will return notifications, in the same structure as "messages".

save_object_p

$backend->save_object_p($obj)->then(sub { my $obj = shift });

This method is called to save a given object to persistent storage.

users_p

$backend = $backend->users_p->then(sub { my $users = shift });

Used to find a list of user emails.

SEE ALSO

Convos::Core