Comparison

core/rostermanager.lua @ 7167:7ae430fecf12

rostermanager: Require storagemanager at the top, fixes traceback on Lua 5.2
author Matthew Wild <mwild1@gmail.com>
date Fri, 19 Feb 2016 12:15:02 +0000
parent 7155:4a0825984e42
child 7271:dae47cd774ac
comparison
equal deleted inserted replaced
7165:f0e6757261bc 7167:7ae430fecf12
18 local hosts = hosts; 18 local hosts = hosts;
19 local bare_sessions = prosody.bare_sessions; 19 local bare_sessions = prosody.bare_sessions;
20 20
21 local um_user_exists = require "core.usermanager".user_exists; 21 local um_user_exists = require "core.usermanager".user_exists;
22 local st = require "util.stanza"; 22 local st = require "util.stanza";
23 local storagemanager = require "core.storagemanager";
23 24
24 local _ENV = nil; 25 local _ENV = nil;
25 26
26 local save_roster; -- forward declaration 27 local save_roster; -- forward declaration
27 28
106 if roster then return roster; end 107 if roster then return roster; end
107 log("debug", "load_roster: loading for new user: %s@%s", username, host); 108 log("debug", "load_roster: loading for new user: %s@%s", username, host);
108 else -- Attempt to load roster for non-loaded user 109 else -- Attempt to load roster for non-loaded user
109 log("debug", "load_roster: loading for offline user: %s@%s", username, host); 110 log("debug", "load_roster: loading for offline user: %s@%s", username, host);
110 end 111 end
111 local roster_store = require "core.storagemanager".open(host, "roster", "keyval"); 112 local roster_store = storagemanager.open(host, "roster", "keyval");
112 local data, err = roster_store:get(username); 113 local data, err = roster_store:get(username);
113 roster = data or {}; 114 roster = data or {};
114 if user then user.roster = roster; end 115 if user then user.roster = roster; end
115 roster_metadata(roster, err); 116 roster_metadata(roster, err);
116 if roster[jid] then 117 if roster[jid] then
142 if metadata.version ~= true then 143 if metadata.version ~= true then
143 metadata.version = (metadata.version or 0) + 1; 144 metadata.version = (metadata.version or 0) + 1;
144 end 145 end
145 if metadata.broken then return nil, "Not saving broken roster" end 146 if metadata.broken then return nil, "Not saving broken roster" end
146 if jid == nil then 147 if jid == nil then
147 local roster_store = require "core.storagemanager".open(host, "roster", "keyval"); 148 local roster_store = storagemanager.open(host, "roster", "keyval");
148 return roster_store:set(username, roster); 149 return roster_store:set(username, roster);
149 else 150 else
150 local roster_store = require "core.storagemanager".open(host, "roster", "map"); 151 local roster_store = storagemanager.open(host, "roster", "map");
151 return roster_store:set_keys(username, { [false] = metadata, [jid] = roster[jid] or roster_store.remove }); 152 return roster_store:set_keys(username, { [false] = metadata, [jid] = roster[jid] or roster_store.remove });
152 end 153 end
153 end 154 end
154 log("warn", "save_roster: user had no roster to save"); 155 log("warn", "save_roster: user had no roster to save");
155 return nil; 156 return nil;