-module(ephraim_conv). -compile([debug_info, export_all]). -record(conv_state, { jid :: binary() }). -spec init(binary()) -> ok. init(JID) -> io:format("Starting a conversation with ~p~n", [JID]), loop(#conv_state{jid=JID}), io:format("Stopping a conversation with ~p~n", [JID]). -spec loop(#conv_state{}) -> ok. loop(State) -> receive stop -> 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 -> io:format("ephraim_conv (~p): ~p~n", [State#conv_state.jid, Msg]), loop(State) end.