Skip to content

Commit

Permalink
Improve example Elixir modules
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed Nov 25, 2024
1 parent f9cecca commit 6790ab0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
19 changes: 0 additions & 19 deletions lib/ejabberd/module.ex

This file was deleted.

17 changes: 11 additions & 6 deletions lib/ejabberd_auth_example.ex
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
defmodule ModAuthExample do
defmodule Ejabberd.Auth.Example do

@moduledoc """
Example ejabberd auth method written in Elixir.
This is a dummy auth module to demonstrate the usage of Elixir to
create Ejabberd Auth modules.
This is an example to demonstrate the usage of Elixir to
create ejabberd auth methods.
Example configuration:
auth_method: 'Ejabberd.Auth.Example'
"""
import Ejabberd.Logger

@behaviour :ejabberd_auth
import Ejabberd.Logger

@impl true
def start(host) do
info("Using mod_auth_example to authenticate #{host} users")
info("Starting Ejabberd.Auth.Example to authenticate '#{host}' users")
nil
end

@impl true
def stop(host) do
info("Stop using mod_auth_example to authenticate #{host} users")
info("Stopping Ejabberd.Auth.Example to authenticate '#{host}' users")
nil
end

Expand Down
21 changes: 17 additions & 4 deletions lib/mod_example.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
defmodule ModPresenceDemo do
use Ejabberd.Module
defmodule Ejabberd.Module.Example do

@moduledoc """
Example ejabberd module written in Elixir.
This is an example to demonstrate the usage of Elixir to
create ejabberd modules.
Example configuration:
modules:
'Ejabberd.Module.Example': {}
"""

@behaviour :gen_mod
import Ejabberd.Logger

def start(host, _opts) do
info("Starting ejabberd module Presence Demo")
info("Starting Ejabberd.Module.Example for host '#{host}'")
Ejabberd.Hooks.add(:set_presence_hook, host, __MODULE__, :on_presence, 50)
:ok
end

def stop(host) do
info("Stopping ejabberd module Presence Demo")
info("Stopping Ejabberd.Module.Example for host '#{host}'")
Ejabberd.Hooks.delete(:set_presence_hook, host, __MODULE__, :on_presence, 50)
:ok
end
Expand Down

0 comments on commit 6790ab0

Please sign in to comment.