Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 8219:2e68ae095645

mod_pubsub: Store data in users store, node in 'with' metadata field
author Kim Alvefur <zash@zash.se>
date Wed, 26 Apr 2017 12:11:11 +0200
parent 8218:2c75a5ba58fc
child 8295:8e82aa858ed2
comparison
equal deleted inserted replaced
8218:2c75a5ba58fc 8219:2e68ae095645
329 local function simple_itemstore(archive, config, user, node, expose_publisher) 329 local function simple_itemstore(archive, config, user, node, expose_publisher)
330 module:log("debug", "Creation of itemstore for node %s with config %s", node, config); 330 module:log("debug", "Creation of itemstore for node %s with config %s", node, config);
331 local get_set = {}; 331 local get_set = {};
332 function get_set:items() 332 function get_set:items()
333 local store = self.store; 333 local store = self.store;
334 local data, err = archive:find(node); 334 local data, err = archive:find(user, { with = node });
335 if not data then 335 if not data then
336 module:log("error", "Unable to get items: %s", err); 336 module:log("error", "Unable to get items: %s", err);
337 return true; 337 return true;
338 end 338 end
339 module:log("debug", "Listed items %s from store %s", data, store); 339 module:log("debug", "Listed items %s from store %s", data, store);
346 return id, item; 346 return id, item;
347 end; 347 end;
348 end 348 end
349 function get_set:get(key) 349 function get_set:get(key)
350 local store = self.store; 350 local store = self.store;
351 local data, err = archive:find(node, { 351 local data, err = archive:find(user, {
352 with = node;
352 key = key; 353 key = key;
353 }); 354 });
354 if not data then 355 if not data then
355 module:log("error", "Unable to get item: %s", err); 356 module:log("error", "Unable to get item: %s", err);
356 return nil, err; 357 return nil, err;
371 module:log("debug", "Set item %s to %s for %s in store %s", key, value, node, store); 372 module:log("debug", "Set item %s to %s for %s in store %s", key, value, node, store);
372 local data, err; 373 local data, err;
373 if value ~= nil then 374 if value ~= nil then
374 local publisher = value.attr.publisher; 375 local publisher = value.attr.publisher;
375 local payload = value.tags[1]; 376 local payload = value.tags[1];
376 data, err = archive:append(node, key, payload, time_now(), publisher); 377 data, err = archive:append(user, key, payload, time_now(), node);
377 else 378 else
378 data, err = archive:delete(node, { 379 data, err = archive:delete(user, {
379 key = key; 380 key = key;
381 with = node;
380 }); 382 });
381 end 383 end
382 if not data then 384 if not data then
383 module:log("error", "Unable to set item: %s", err); 385 module:log("error", "Unable to set item: %s", err);
384 return nil, err; 386 return nil, err;