-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy path44account_data.pl
104 lines (75 loc) · 2.17 KB
/
44account_data.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
push our @EXPORT, qw(
matrix_get_account_data matrix_get_room_account_data
matrix_add_account_data matrix_add_room_account_data
matrix_add_filler_account_data_synced
);
=head2 matrix_add_account_data
matrix_add_account_data( $user, $type, $content )->get;
Add account data for the user.
=cut
sub matrix_add_account_data
{
my ( $user, $type, $content ) = @_;
do_request_json_for( $user,
method => "PUT",
uri => "/r0/user/:user_id/account_data/$type",
content => $content
);
}
=head2 matrix_add_room_account_data
matrix_add_account_data( $user, $room_id, $type, $content )->get;
Add account data for the user for a room.
=cut
sub matrix_add_room_account_data
{
my ( $user, $room_id, $type, $content ) = @_;
do_request_json_for( $user,
method => "PUT",
uri => "/r0/user/:user_id/rooms/$room_id/account_data/$type",
content => $content
);
}
=head2 matrix_get_account_data
matrix_get_account_data( $user, $type, $content )->get;
Get account data for the user.
=cut
sub matrix_get_account_data
{
my ( $user, $type ) = @_;
do_request_json_for( $user,
method => "GET",
uri => "/r0/user/:user_id/account_data/$type",
);
}
=head2 matrix_get_room_account_data
matrix_get_account_data( $user, $room_id, $type, $content )->get;
Get account data for the user for a room.
=cut
sub matrix_get_room_account_data
{
my ( $user, $room_id, $type, $content ) = @_;
do_request_json_for( $user,
method => "GET",
uri => "/r0/user/:user_id/rooms/$room_id/account_data/$type",
);
}
sub matrix_add_filler_account_data_synced
{
my ( $user ) = @_;
my $random_id = join "", map { chr 64 + rand 63 } 1 .. 20;
my $type = "a.made.up.filler.type";
matrix_do_and_wait_for_sync( $user,
do => sub {
matrix_add_account_data( $user, $type, {
"id" => $random_id,
} );
},
check => sub {
my ( $sync_body ) = @_;
my $global_account_data = $sync_body->{account_data}{events};
return any {
$_->{type} eq $type && $_->{content}{id} eq $random_id
} @{ $global_account_data };
},
);
}