Software /
code /
prosody
Comparison
core/rostermanager.lua @ 2049:227f3fd2caaf
rostermanager: Refactored roster loading to remove duplicate code.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 22 Oct 2009 03:46:54 +0500 |
parent | 2048:d420722519e1 |
child | 2050:adc1b92b8c6b |
comparison
equal
deleted
inserted
replaced
2048:d420722519e1 | 2049:227f3fd2caaf |
---|---|
81 end | 81 end |
82 | 82 |
83 function load_roster(username, host) | 83 function load_roster(username, host) |
84 local jid = username.."@"..host; | 84 local jid = username.."@"..host; |
85 log("debug", "load_roster: asked for: "..jid); | 85 log("debug", "load_roster: asked for: "..jid); |
86 local user = bare_sessions[jid]; | |
86 local roster; | 87 local roster; |
87 if hosts[host] and hosts[host].sessions[username] then | 88 if user then |
88 roster = hosts[host].sessions[username].roster; | 89 roster = user.roster; |
89 if not roster then | 90 if roster then return roster; end |
90 log("debug", "load_roster: loading for new user: "..username.."@"..host); | 91 log("debug", "load_roster: loading for new user: "..username.."@"..host); |
91 roster = datamanager.load(username, host, "roster") or {}; | 92 else -- Attempt to load roster for non-loaded user |
92 if not roster[false] then roster[false] = { }; end | 93 log("debug", "load_roster: loading for offline user: "..username.."@"..host); |
93 if roster[jid] then | 94 end |
94 roster[jid] = nil; | |
95 log("warn", "roster for "..jid.." has a self-contact"); | |
96 end | |
97 hosts[host].sessions[username].roster = roster; | |
98 hosts[host].events.fire_event("roster-load", username, host, roster); | |
99 end | |
100 return roster; | |
101 end | |
102 | |
103 -- Attempt to load roster for non-loaded user | |
104 log("debug", "load_roster: loading for offline user: "..username.."@"..host); | |
105 roster = datamanager.load(username, host, "roster") or {}; | 95 roster = datamanager.load(username, host, "roster") or {}; |
96 if user then user.roster = roster; end | |
106 if not roster[false] then roster[false] = { }; end | 97 if not roster[false] then roster[false] = { }; end |
107 if roster[jid] then | 98 if roster[jid] then |
108 roster[jid] = nil; | 99 roster[jid] = nil; |
109 log("warn", "roster for "..jid.." has a self-contact"); | 100 log("warn", "roster for "..jid.." has a self-contact"); |
110 end | 101 end |