diff options
Diffstat (limited to 'src/core/ephraim_roster.erl')
-rw-r--r-- | src/core/ephraim_roster.erl | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl index 605d019..6c6a229 100644 --- a/src/core/ephraim_roster.erl +++ b/src/core/ephraim_roster.erl @@ -4,7 +4,7 @@ -export([start_link/2]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). --export([presence/2, roster_iq/2, vcard_iq/3]). +-export([presence/2, roster_iq/2, vcard_iq/3, get_alias/2]). -record(roster_state, { event_manager :: pid(), @@ -176,27 +176,9 @@ handleVCardIQs(VCard, [Item|Rest]) -> VCard2 = handleVCardIQ(VCard, Item), handleVCardIQs(VCard2, Rest). --spec get_alias(#roster_state{}, binary()) -> binary(). +-spec get_alias(pid(), binary()) -> binary(). get_alias(Roster, JID) -> - {Node, Domain, _Resource} = exmpp_jid:to_lower(exmpp_jid:parse(JID)), - BareJID = list_to_binary([Node, <<"@">>, Domain]), - - case dict:find(BareJID, Roster#roster_state.entries) of - {ok, Entry} -> - case Entry#roster_entry.name of - undefined -> - case dict:find('NICKNAME', Entry#roster_entry.vcard) of - {ok, Value} -> - Value; - error -> - Node - end; - Name -> - Name - end; - error -> - Node - end. + gen_server:call(Roster, {get_alias,JID}). presence(Roster, Packet) -> gen_server:cast(Roster, {presence, Packet}). @@ -205,8 +187,27 @@ roster_iq(Roster, Payload) -> vcard_iq(Roster, From, Payload) -> gen_server:cast(Roster, {vcard_iq, From, Payload}). -handle_call(_Msg, _From, State) -> - {noreply, State}. +handle_call({get_alias,JID}, _From, State) -> + {Node, Domain, _Resource} = exmpp_jid:to_lower(exmpp_jid:parse(JID)), + BareJID = list_to_binary([Node, <<"@">>, Domain]), + + Result = case dict:find(BareJID, State#roster_state.entries) of + {ok, Entry} -> + case Entry#roster_entry.name of + undefined -> + case dict:find('NICKNAME', Entry#roster_entry.vcard) of + {ok, Value} -> + Value; + error -> + Node + end; + Name -> + Name + end; + error -> + Node + end, + {reply, Result, State}. handle_cast({presence, Packet}, State) -> %io:format("ephraim_roster: Presence: ~p~n", [Packet]), |