Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hedwig-im/hedwig_xmpp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0-rc2
Choose a base ref
...
head repository: hedwig-im/hedwig_xmpp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 12 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 1, 2016

  1. update for hedwig master

    scrogson committed Apr 1, 2016
    Copy the full SHA
    79d737b View commit details
  2. update mix.lock

    scrogson committed Apr 1, 2016
    Copy the full SHA
    6ae5f09 View commit details

Commits on Apr 5, 2016

  1. Copy the full SHA
    45a8c50 View commit details

Commits on Apr 17, 2016

  1. Copy the full SHA
    1e6f441 View commit details
  2. Update README

    scrogson committed Apr 17, 2016
    Copy the full SHA
    f6ea2a0 View commit details
  3. update github link for hex

    scrogson committed Apr 17, 2016
    Copy the full SHA
    d189a51 View commit details

Commits on Apr 22, 2016

  1. Update for hedwig master

    scrogson committed Apr 22, 2016
    Copy the full SHA
    a0c6098 View commit details

Commits on Jul 21, 2016

  1. Update romeo; bump version

    scrogson committed Jul 21, 2016
    Copy the full SHA
    743be50 View commit details

Commits on Oct 10, 2016

  1. prepare for hedwig master

    scrogson committed Oct 10, 2016
    Copy the full SHA
    d936425 View commit details

Commits on Oct 21, 2016

  1. Copy the full SHA
    ede14f4 View commit details

Commits on Nov 20, 2016

  1. 1.0

    scrogson committed Nov 20, 2016
    Copy the full SHA
    45764a7 View commit details
  2. update README

    scrogson committed Nov 20, 2016
    Copy the full SHA
    173c169 View commit details
Showing with 36 additions and 40 deletions.
  1. +3 −8 README.md
  2. +19 −19 lib/hedwig_xmpp.ex
  3. +7 −8 mix.exs
  4. +7 −5 mix.lock
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,8 +38,7 @@ Add `hedwig_xmpp` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:exml, github: "esl/exml"},
{:hedwig_xmpp, "~> 1.0.0-rc0"}]
[{:hedwig_xmpp, "~> 1.0"}]
end
```

@@ -104,9 +103,7 @@ config :alfred, Alfred.Robot,
aka: "/",
responders: [
{Hedwig.Responders.Help, []},
{Hedwig.Responders.Panzy, []},
{Hedwig.Responders.GreatSuccess, []},
{Hedwig.Responders.ShipIt, []}
{Hedwig.Responders.Ping, []}
]
```

@@ -141,9 +138,7 @@ config :alfred, Alfred.Robot,
],
responders: [
{Hedwig.Responders.Help, []},
{Hedwig.Responders.Panzy, []},
{Hedwig.Responders.GreatSuccess, []},
{Hedwig.Responders.ShipIt, []}
{Hedwig.Responders.Ping, []}
]
```

38 changes: 19 additions & 19 deletions lib/hedwig_xmpp.ex
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ defmodule Hedwig.Adapters.XMPP do
use Hedwig.Adapter
use Romeo.XML

@timeout 5000

require Logger

defmodule State do
@@ -88,7 +90,7 @@ defmodule Hedwig.Adapters.XMPP do

def handle_info({:stanza, %Message{} = msg}, %{robot: robot, opts: opts} = state) do
unless from_self?(msg, opts[:name]) do
Hedwig.Robot.handle_message(robot, hedwig_message(msg, state.jid_mapping))
Hedwig.Robot.handle_in(robot, hedwig_message(msg, state))
end
{:noreply, state}
end
@@ -105,26 +107,24 @@ defmodule Hedwig.Adapters.XMPP do
end

def handle_info({:resource_bound, resource}, %{robot: robot, opts: opts} = state) do
Hedwig.Robot.register(robot, opts[:name])
Hedwig.Robot.handle_in(robot, {:resource_bound, resource})
{:noreply, state}
end

def handle_info(:connection_ready, %{conn: conn, robot: robot, opts: opts} = state) do
server = Romeo.JID.server(opts[:jid])

conn
|> get_roster(opts)
|> request_all_rooms(opts)
|> send_presence(opts)
|> join_rooms(opts)

Hedwig.Robot.after_connect(robot)
Hedwig.Robot.handle_connect(robot)

{:noreply, state}
end

def handle_info(msg, state) do
Logger.warn fn -> "Adapter received unhandled message: #{inspect msg}" end
def handle_info(msg, %{robot: robot} = state) do
Hedwig.Robot.handle_in(robot, msg)
{:noreply, state}
end

@@ -159,6 +159,8 @@ defmodule Hedwig.Adapters.XMPP do
receive do
{:stanza, %IQ{id: ^id, type: "result"} = iq} ->
GenServer.cast(self, {:roster_results, iq})
after @timeout ->
:ok
end

conn
@@ -180,6 +182,8 @@ defmodule Hedwig.Adapters.XMPP do
receive do
{:stanza, %IQ{id: ^id, type: "result"} = iq} ->
GenServer.cast(self, {:rooms_results, iq})
after @timeout ->
:ok
end
end

@@ -217,12 +221,12 @@ defmodule Hedwig.Adapters.XMPP do
end
defp from_self?(_, _), do: false

defp hedwig_message(%Message{body: body, type: type} = msg, mapping) do
defp hedwig_message(%Message{body: body, type: type} = msg, %{jid_mapping: mapping, robot: robot}) do
{room, user} = extract_room_and_user(msg, mapping)

%Hedwig.Message{
adapter: {__MODULE__, self},
ref: make_ref(),
robot: robot,
room: room,
text: body,
type: type,
@@ -240,20 +244,16 @@ defmodule Hedwig.Adapters.XMPP do

defp extract_room_and_user(%Message{from: from, type: "groupchat"}, mapping) do
room = Romeo.JID.bare(from)
user = %{
id: Romeo.JID.resource(from),
room: room,
jid: mapping[from.full] || from.full,
user = %Hedwig.User{
id: mapping[from.full] || from.full,
name: Romeo.JID.resource(from)
}

{room, user}
end
defp extract_room_and_user(%Romeo.Stanza.Message{from: from}, mapping) do
user = %{
id: Romeo.JID.user(from),
room: nil,
jid: from.full,
defp extract_room_and_user(%Romeo.Stanza.Message{from: from}, _mapping) do
user = %Hedwig.User{
id: from.full,
name: Romeo.JID.user(from)
}
{nil, user}
@@ -263,6 +263,6 @@ defmodule Hedwig.Adapters.XMPP do
Romeo.JID.bare(room)
end
defp send_to(_type, _room, user) do
Romeo.JID.parse(user.jid)
Romeo.JID.parse(user.id)
end
end
15 changes: 7 additions & 8 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule HedwigXMPP.Mixfile do
use Mix.Project

@version "1.0.0-rc2"
@version "1.0.0"

def project do
[app: :hedwig_xmpp,
@@ -10,27 +10,26 @@ defmodule HedwigXMPP.Mixfile do
elixir: "~> 1.1",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
package: package,
package: package(),
description: "An XMPP adapter for Hedwig",
deps: deps]
deps: deps()]
end

def application do
[applications: [:logger, :hedwig, :romeo]]
end

defp deps do
[{:exml, github: "esl/exml"},
{:hedwig, "~> 1.0.0-rc3"},
{:romeo, "~> 0.4"}]
[{:hedwig, "~> 1.0"},
{:romeo, "~> 0.7"}]
end

defp package do
[files: ["lib", "priv", "mix.exs", "README*", "readme*", "LICENSE*", "license*"],
[files: ["lib", "mix.exs", "README*", "LICENSE*"],
maintainers: ["Sonny Scroggin"],
licenses: ["MIT"],
links: %{
"GitHub" => "https://github.com/hedwig-im/hedwig"
"GitHub" => "https://github.com/hedwig-im/hedwig_xmpp"
}]
end
end
12 changes: 7 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%{"connection": {:hex, :connection, "1.0.2"},
"exml": {:git, "https://github.com/esl/exml.git", "d7b745fa89389b53706a07f33775f1f814c66cb4", []},
"gproc": {:hex, :gproc, "0.5.0"},
"hedwig": {:hex, :hedwig, "1.0.0-rc3"},
"romeo": {:hex, :romeo, "0.4.0"}}
%{"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
"exml": {:git, "https://github.com/paulgray/exml.git", "d7b745fa89389b53706a07f33775f1f814c66cb4", []},
"fast_xml": {:hex, :fast_xml, "1.1.15", "6d23eb7f874e1357cf80a48d75a7bd0c8f6318029dc4b70122e9f54911f57f83", [:rebar3], [{:p1_utils, "1.0.5", [hex: :p1_utils, optional: false]}]},
"gproc": {:hex, :gproc, "0.5.0", "2df2d886f8f8a7b81a4b04aa17972b5965bbc5bf0100ea6d8e8ac6a0e7389afe", [:rebar], []},
"hedwig": {:hex, :hedwig, "1.0.0", "effbb160b9b270cb62ac1b2d6041b4ac731a21b0fc048dd2c35840245fdc0f22", [:mix], []},
"p1_utils": {:hex, :p1_utils, "1.0.5", "3e698354fdc1fea5491d991457b0cb986c0a00a47d224feb841dc3ec82b9f721", [:rebar3], []},
"romeo": {:hex, :romeo, "0.7.0", "17e46830e49eff4d70e59147e808cd3f5f79912bb90a006afe5a8bb4355c29b3", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:fast_xml, "~> 1.1", [hex: :fast_xml, optional: false]}]}}