Skip to content

Commit

Permalink
Added functionallity to specify message id in stanza in map form.
Browse files Browse the repository at this point in the history
Updated to_xml function to also use message id
  • Loading branch information
Carel de Waal committed Oct 3, 2017
1 parent 87ae1d1 commit ee9f2ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/romeo/stanza.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ defmodule Romeo.Stanza do
) |> to_xml
end

def to_xml(%Message{to: to, type: type, body: body}) do
message(to_string(to), type, body) |> to_xml
def to_xml(%Message{id: "", to: to, type: type, body: body}) do
message(to_string(to), type, body, generate_id()) |> to_xml
end
def to_xml(%Message{id: id, to: to, type: type, body: body}) do
message(to_string(to), type, body, id) |> to_xml
end

@doc """
Starts an XML stream.
Expand Down Expand Up @@ -273,7 +275,7 @@ defmodule Romeo.Stanza do
def groupchat(to, body, id \\ generate_id()), do: message(to, "groupchat", body, id)

def message(msg) when is_map(msg) do
message(msg["to"], msg["type"], msg["body"])
message(msg["to"], msg["type"], msg["body"], msg["id"] || generate_id())
end
def message(to, type, message, id) do
xmlel(name: "message",
Expand Down

0 comments on commit ee9f2ad

Please sign in to comment.