Update mod_default_contacts option parsing to use econf

This commit is contained in:
Badlop 2022-08-12 17:44:59 +02:00
parent 2bf5a362ce
commit f3e03b9729
2 changed files with 14 additions and 13 deletions

View File

@ -26,10 +26,10 @@ modules:
contacts:
-
name: "Bob Virding"
jid: "bob@example.com"
jid: bob@example.com
-
name: "Alice Armstrong"
jid: "alice@example.com"
jid: alice@example.com
```
The configurable `mod_default_contacts` options are:

View File

@ -52,18 +52,19 @@ stop(Host) ->
reload(_Host, _NewOpts, _OldOpts) ->
ok.
-spec mod_opt_type(atom()) -> fun((term()) -> term()).
-spec mod_opt_type(atom()) -> econf:validator().
mod_opt_type(contacts) ->
fun (L) ->
lists:map(fun (Opts) ->
JID1 = proplists:get_value(jid, Opts),
JID2 = iolist_to_binary(JID1),
JID3 = jid:decode(JID2),
Name1 = proplists:get_value(name, Opts, <<>>),
Name2 = iolist_to_binary(Name1),
#roster_item{jid = JID3, name = Name2}
end, L)
end.
econf:list(
econf:and_then(
econf:options(
#{jid => econf:jid(),
name => econf:binary()},
[{required, [jid]}]),
fun(Opts) ->
Jid = proplists:get_value(jid, Opts),
Name = proplists:get_value(name, Opts, <<>>),
#roster_item{jid = Jid, name = Name}
end)).
-spec mod_options(binary()) -> [{atom(), any()}].
mod_options(_Host) ->