Problem including mod_roster in custom roster written in Elixir

Hi

I'm yet another developer new to ejabberd, erlang and elixir. I have successfully built, installed and verified functionality of a simple module written in Elixir that simply prints a log message while starting and stopping (start and stop functions).

Now I want to write a custom roster.

I started by looking at mod_roster_riak.erl. There is no start function in that file. If I understand it correctly that function is "inherited" from mod_roster with this line:

-include("mod_roster.hrl")

In my Elixir roster module I renamed "start" to "init", installed and tested it. I got an error that the "start" function was undefined.

So I tried to include mod_roster in various ways:

defmodule ModRosterMy do
    @behaviour :mod_roster
    require :mod_roster
    ...
end

I also tried with use :mod_roster and import :mod_roster but nothing works. The code above builds correctly, but still fails at runtime because "start" is undefined.

Any hints?

Disclaimer: I only know how

Disclaimer: I only know how the standard ejabberd works, I didn't dig into Elixir. So my help is only for the non-Elixir code and config. Take what you can use from it.

This line just tells the compiler to include a header file, where some constants and other structures are defined:
-include("mod_roster.hrl")

mod_roster is the main module, it contains the main function definitions. For some roster features that require read or write in a database, its functions delegate that into the different database modules, like in:

read_roster_version(LUser, LServer) ->
    Mod = gen_mod:db_mod(LServer, ?MODULE),
    Mod:read_roster_version(LUser, LServer).

This will get which database module is configured for LServer, and then calls that module's read_roster_version function.

To develop a new database storage, copy mod_roster_riak.erl to mod_roster_test.erl, fix the first line
-module(mod_roster_riak).
Then, for each of the exported functions (that mod_roster will call when required), put your desired code.
Finally, configure mod_roster to use test as its database:

  mod_roster:
    db_type: test
Syndicate content