summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-07-17 23:49:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-07-17 23:49:06 +0200
commit69aaef2680ff5c96b34ad983b665a80c06c20224 (patch)
tree08ae44133e45f3f49d8f2324f23feb9c6f028246 /src
parent0aac619ba4dccd81018bddaa4690213b14cfe2b6 (diff)
downloadephraim-69aaef2680ff5c96b34ad983b665a80c06c20224.tar
ephraim-69aaef2680ff5c96b34ad983b665a80c06c20224.zip
Use nickname from VCard if no nickname is set
Diffstat (limited to 'src')
-rw-r--r--src/core/ephraim.erl12
-rw-r--r--src/core/ephraim_conv.erl4
-rw-r--r--src/core/ephraim_roster.erl32
3 files changed, 44 insertions, 4 deletions
diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl
index d558eda..c8783f0 100644
--- a/src/core/ephraim.erl
+++ b/src/core/ephraim.erl
@@ -59,6 +59,14 @@ get_conv(State, JID) ->
end
end.
+-spec get_alias(binary()) -> binary().
+get_alias(JID) ->
+ ephraim ! {self(),get_alias,JID},
+ receive
+ {alias,JID,Alias} ->
+ Alias
+ end.
+
-spec loop(#state{}) -> ok.
loop(State) ->
receive
@@ -139,6 +147,10 @@ loop(State) ->
end,
loop(State);
+ {Pid, get_alias, JID} ->
+ State#state.roster ! {Pid,get_alias,JID},
+ loop(State);
+
Msg ->
io:format("ephraim: ~p~n", [Msg]),
loop(State)
diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl
index 199787a..3342bc9 100644
--- a/src/core/ephraim_conv.erl
+++ b/src/core/ephraim_conv.erl
@@ -25,7 +25,7 @@ loop(State) ->
Body = exmpp_message:get_body(Packet),
if
Body =/= undefined ->
- ephraim ! {ui_update, {chat_message, State#conv_state.jid, Type, State#conv_state.jid, Body}};
+ ephraim ! {ui_update, {chat_message, State#conv_state.jid, Type, ephraim:get_alias(State#conv_state.jid), Body}};
true ->
io:format("Received strange message from ~p:~n~p~n", [State#conv_state.jid, Packet])
end,
@@ -36,7 +36,7 @@ loop(State) ->
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, {chat_message, State#conv_state.jid, Type, State#conv_state.my_jid, Message}},
+ ephraim ! {ui_update, {chat_message, State#conv_state.jid, Type, ephraim:get_alias(State#conv_state.my_jid), Message}},
loop(State);
Msg ->
diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl
index b596837..b0fa7cf 100644
--- a/src/core/ephraim_roster.erl
+++ b/src/core/ephraim_roster.erl
@@ -66,7 +66,6 @@ updateRosterEntry(Roster, JID, Name, Subscription, Groups) ->
#roster_entry{}
end,
NewEntry = OldEntry#roster_entry{subscription=Subscription,name=Name,groups=Groups},
-
Entries = dict:store(JID, NewEntry, Roster#roster.entries),
uiUpdate(JID, NewEntry),
@@ -130,6 +129,9 @@ handleRosterIQ(Roster, Item) ->
Groups = getGroups(Item#xmlel.children),
Subscription = binary_to_atom(exmpp_xml:get_attribute(Item, subscription, undefined), utf8),
+ ephraim ! {send_packet, exmpp_stanza:set_recipient(exmpp_iq:get('jabber:client', #xmlel{ns='vcard-temp',name='vCard'}), JID)},
+ io:format("ephraim_roster: ~p~n", [exmpp_stanza:set_recipient(exmpp_iq:get('jabber:client', #xmlel{ns='vcard-temp',name='vCard'}), JID)]),
+
updateRosterEntry(Roster, JID, Name, Subscription, Groups).
-spec handleRosterIQs(#roster{}, [#xmlel{}]) -> #roster{}.
@@ -157,6 +159,28 @@ handleVCardIQs(VCard, [Item|Rest]) ->
VCard2 = handleVCardIQ(VCard, Item),
handleVCardIQs(VCard2, Rest).
+-spec get_alias(#roster{}, 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.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.
+
-spec loop(#roster{}) -> ok.
loop(Roster) ->
receive
@@ -183,10 +207,14 @@ loop(Roster) ->
loop(Roster2);
{vcard_iq, From, Payload} ->
- Dict = handleVCardIQs(dict:new(), Payload#xmlel.children),
+ Dict = handleVCardIQs(dict:new(), Payload#xmlel.children),
Roster2 = updateVCard(Roster, From, Dict),
loop(Roster2);
+ {Pid, get_alias, JID} ->
+ Pid ! {alias,JID,get_alias(Roster, JID)},
+ loop(Roster);
+
Msg ->
io:format("ephraim_roster: ~p~n", [Msg]),
loop(Roster)