-
Notifications
You must be signed in to change notification settings - Fork 82
/
Notifications.pm
47 lines (30 loc) · 1.15 KB
/
Notifications.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package Convos::Controller::Notifications;
use Mojo::Base 'Mojolicious::Controller', -async_await;
async sub messages {
my $self = shift->openapi->valid_input or return;
my $user = await $self->user->load_p or return $self->reply->errors([], 401);
my %query = map { defined $self->param($_) ? ($_, $self->param($_)) : () } qw(limit match);
my $res = await $user->notifications_p(\%query);
$self->render(openapi => {end => $res->{end}, messages => $res->{messages}});
}
async sub read {
my $self = shift->openapi->valid_input or return;
my $user = await $self->user->load_p or return $self->reply->errors([], 401);
$user->connections->map(sub { shift->conversations->map(notifications => 0) });
$self->render(openapi => {});
}
1;
=encoding utf8
=head1 NAME
Convos::Controller::Notifications - Convos notifications
=head1 DESCRIPTION
L<Convos::Controller::Notifications> is a L<Mojolicious::Controller> with
notifications related actions.
=head1 METHODS
=head2 messages
See L<https://convos.chat/api.html#op-get--notifications>
=head2 read
See L<https://convos.chat/api.html#op-post--notifications-read>
=head1 SEE ALSO
L<Convos>.
=cut