From 3eb7e7688dea39fa83f41c1f9aba79a962ef1a15 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 25 Jun 2010 04:36:06 +0200 Subject: Create conversation tabs for new conversations --- src/core/ephraim.erl | 10 +++++++--- src/core/ephraim_conn.erl | 4 ++-- src/core/ephraim_conv.erl | 7 ++++--- src/core/ephraim_event.erl | 6 +++++- 4 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl index bd36118..61c3c68 100644 --- a/src/core/ephraim.erl +++ b/src/core/ephraim.erl @@ -32,17 +32,21 @@ init() -> -spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()|undefined}. get_conv(State, JID) -> - Key = exmpp_jid:to_lower(JID), - case Key of - {_,_,undefined} -> + {Node, Domain, Resource} = exmpp_jid:to_lower(exmpp_jid:parse(JID)), + + case Resource of + undefined -> {State, undefined}; _ -> + Key = list_to_binary([Node, <<"@">>, Domain, <<"/">>, Resource]), + case dict:find(Key, State#state.convs) of {ok, Conv} -> {State, Conv}; error -> Conv = spawn(ephraim_conv, init, [Key]), Dict = dict:store(Key, Conv, State#state.convs), + self() ! {ui_update, {new_conversation, Key}}, {State#state{convs=Dict}, Conv} end end. diff --git a/src/core/ephraim_conn.erl b/src/core/ephraim_conn.erl index 28e72b3..bce4d07 100644 --- a/src/core/ephraim_conn.erl +++ b/src/core/ephraim_conn.erl @@ -21,10 +21,10 @@ init() -> session(State) -> io:format("Logging in...~n"), exmpp_session:login(State#conn_state.session), - io:format("Setting presence...~n"), - exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")), io:format("Getting roster...~n"), exmpp_session:send_packet(State#conn_state.session, exmpp_client_roster:get_roster("foo")), + io:format("Setting presence...~n"), + exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")), io:format("Ok.~n"), loop(State). diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl index b502166..3010036 100644 --- a/src/core/ephraim_conv.erl +++ b/src/core/ephraim_conv.erl @@ -2,12 +2,13 @@ -compile([debug_info, export_all]). -record(conv_state, { - jid :: exmpp_jid:jid() + jid :: binary() }). --spec init(exmpp_jid:jid()) -> ok. +-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]). @@ -18,7 +19,7 @@ loop(State) -> ok; {receive_message, Packet} -> - io:format("Received packet from ~p:~n~p~n", [State#conv_state.jid, Packet]), + io:format("Received message from ~p:~n~p~n", [State#conv_state.jid, Packet]), loop(State); Msg -> diff --git a/src/core/ephraim_event.erl b/src/core/ephraim_event.erl index dd86a7b..d32914a 100644 --- a/src/core/ephraim_event.erl +++ b/src/core/ephraim_event.erl @@ -9,10 +9,14 @@ init() -> -spec handleEvent(binary(), #xmlel{}) -> ok. handleEvent(From, Item) -> HasAvatarData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:data', data), + HasAvatarMetaData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:metadata', metadata), if HasAvatarData -> Element = exmpp_xml:get_element(Item, 'urn:xmpp:avatar:data', data), Data = base64:decode(exmpp_xml:get_cdata_from_list(Element#xmlel.children)), - ephraim ! {roster, {avatar, From, Data}}; + ephraim ! {roster, {avatar, From, Data}}, + ok; + HasAvatarMetaData -> + ok; true -> io:format("Received unhandled event from ~p:~n~p~n", [From, Item]) end. -- cgit v1.2.3