diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ephraim.erl | 18 | ||||
-rw-r--r-- | src/core/ephraim_conn.erl | 4 | ||||
-rw-r--r-- | src/core/ephraim_conv.erl | 11 |
3 files changed, 33 insertions, 0 deletions
diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl index 61c3c68..c0ab7ae 100644 --- a/src/core/ephraim.erl +++ b/src/core/ephraim.erl @@ -97,6 +97,24 @@ loop(State) -> end, loop(State2); + {send_message, To, Type, Message} -> + {State2, Conv} = get_conv(State, To), + case Conv of + undefined -> + io:format("ephraim: send_message: ~p~n", [Message]); + _ -> + Conv ! {send_message, Type, Message} + end, + loop(State2); + + {start_conversation, To} -> + {State2, _Conv} = get_conv(State, To), + loop(State2); + + {send_packet, Packet} -> + State#state.conn ! {send_packet, Packet}, + loop(State); + {receive_event, From, Packet} -> State#state.event ! {receive_event, From, Packet}, loop(State); diff --git a/src/core/ephraim_conn.erl b/src/core/ephraim_conn.erl index bce4d07..7a6ddae 100644 --- a/src/core/ephraim_conn.erl +++ b/src/core/ephraim_conn.erl @@ -53,6 +53,10 @@ loop(State) -> ephraim ! {receive_iq, IQ}, loop(State); + {send_packet, Packet} -> + exmpp_session:send_packet(State#conn_state.session, Packet), + loop(State); + Msg -> io:format("ephraim_conn: ~p~n", [Msg]), loop(State) diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl index 3010036..ac4c26d 100644 --- a/src/core/ephraim_conv.erl +++ b/src/core/ephraim_conv.erl @@ -19,7 +19,18 @@ loop(State) -> ok; {receive_message, Packet} -> + Type = exmpp_message:get_type(Packet), + Body = exmpp_message:get_body(Packet), io:format("Received message from ~p:~n~p~n", [State#conv_state.jid, Packet]), + ephraim ! {ui_update, {receive_message, State#conv_state.jid, Type, Body}}, + loop(State); + + {send_message, Type, Message} -> + Packet = exmpp_message:normal(Message), + Packet2 = exmpp_message:set_type(Packet, Type), + Packet3 = exmpp_xml:set_attribute(Packet2, to, State#conv_state.jid), + ephraim ! {send_packet, Packet3}, + ephraim ! {ui_update, {sent_message, State#conv_state.jid, Type, Message}}, loop(State); Msg -> |