diff options
author | Alexey Shchepin <alexey@process-one.net> | 2016-02-26 15:45:28 +0300 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2016-03-02 00:12:49 +0300 |
commit | e21f25f5b9229cfa2c97a2c0aec340ff71cfe26c (patch) | |
tree | 3b4a942e77d57371577cb216b8ed9b112c83950f /src/mod_roster.erl | |
parent | Update more SQL queries (diff) |
Update more SQL queries
Diffstat (limited to 'src/mod_roster.erl')
-rw-r--r-- | src/mod_roster.erl | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/mod_roster.erl b/src/mod_roster.erl index 1e5e3b70..79655af8 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -694,12 +694,9 @@ roster_subscribe_t(LUser, LServer, LJID, Item) -> roster_subscribe_t(_LUser, _LServer, _LJID, Item, mnesia) -> mnesia:write(Item); -roster_subscribe_t(LUser, LServer, LJID, Item, odbc) -> - ItemVals = record_to_string(Item), - Username = ejabberd_odbc:escape(LUser), - SJID = ejabberd_odbc:escape(jid:to_string(LJID)), - odbc_queries:roster_subscribe(LServer, Username, SJID, - ItemVals); +roster_subscribe_t(_LUser, _LServer, _LJID, Item, odbc) -> + ItemVals = record_to_row(Item), + odbc_queries:roster_subscribe(ItemVals); roster_subscribe_t(LUser, LServer, _LJID, Item, riak) -> ejabberd_riak:put(Item, roster_schema(), [{'2i', [{<<"us">>, {LUser, LServer}}]}]). @@ -1034,11 +1031,10 @@ update_roster_t(_LUser, _LServer, _LJID, Item, mnesia) -> mnesia:write(Item); update_roster_t(LUser, LServer, LJID, Item, odbc) -> - Username = ejabberd_odbc:escape(LUser), - SJID = ejabberd_odbc:escape(jid:to_string(LJID)), - ItemVals = record_to_string(Item), - ItemGroups = groups_to_string(Item), - odbc_queries:update_roster(LServer, Username, SJID, ItemVals, + SJID = jid:to_string(LJID), + ItemVals = record_to_row(Item), + ItemGroups = Item#roster.groups, + odbc_queries:update_roster(LServer, LUser, SJID, ItemVals, ItemGroups); update_roster_t(LUser, LServer, _LJID, Item, riak) -> ejabberd_riak:put(Item, roster_schema(), @@ -1051,9 +1047,8 @@ del_roster_t(LUser, LServer, LJID) -> del_roster_t(LUser, LServer, LJID, mnesia) -> mnesia:delete({roster, {LUser, LServer, LJID}}); del_roster_t(LUser, LServer, LJID, odbc) -> - Username = ejabberd_odbc:escape(LUser), - SJID = ejabberd_odbc:escape(jid:to_string(LJID)), - odbc_queries:del_roster(LServer, Username, SJID); + SJID = jid:to_string(LJID), + odbc_queries:del_roster(LServer, LUser, SJID); del_roster_t(LUser, LServer, LJID, riak) -> ejabberd_riak:delete(roster, {LUser, LServer, LJID}). @@ -1319,6 +1314,27 @@ record_to_string(#roster{us = {User, _Server}, [Username, SJID, Nick, SSubscription, SAsk, SAskMessage, <<"N">>, <<"">>, <<"item">>]. +record_to_row( + #roster{us = {LUser, _LServer}, + jid = JID, name = Name, subscription = Subscription, + ask = Ask, askmessage = AskMessage}) -> + SJID = jid:to_string(jid:tolower(JID)), + SSubscription = case Subscription of + both -> <<"B">>; + to -> <<"T">>; + from -> <<"F">>; + none -> <<"N">> + end, + SAsk = case Ask of + subscribe -> <<"S">>; + unsubscribe -> <<"U">>; + both -> <<"B">>; + out -> <<"O">>; + in -> <<"I">>; + none -> <<"N">> + end, + {LUser, SJID, Name, SSubscription, SAsk, AskMessage}. + groups_to_string(#roster{us = {User, _Server}, jid = JID, groups = Groups}) -> Username = ejabberd_odbc:escape(User), |