diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 83bb379e3..7d7fd061f 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -135,4 +135,10 @@ function process_inbound_unsubscribe(username, host, jid) end end +function is_contact_subscribed(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + return item and (item.subscription == "from" or item.subscription == "both"); +end + return _M; \ No newline at end of file diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 16658f30d..be4f91855 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -207,7 +207,16 @@ function core_route_stanza(origin, stanza) send(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); end elseif stanza.attr.type == "subscribe" then - -- TODO + if rostermanager.is_contact_subscribed(node, host, from_bare) then + send(origin, st.presence(from=to_bare, to=from_bare, type="subscribed")); -- already subscribed + else + local pres = st.presence({from=from_bare}, type="subscribe"); + for k in pairs(user.sessions) do -- return presence for all resources + if user.sessions[k].presence then + send(user.sessions[k], pres); + end + end + end elseif stanza.attr.type == "unsubscribe" then if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then rostermanager.roster_push(node, host, from_bare);