Annotate

core/rostermanager.lua @ 101:c690fa382743

Added some roster management functions
author Waqas Hussain <waqas20@gmail.com>
date Sun, 12 Oct 2008 17:40:03 +0500
parent 80:523ac742cc19
child 103:ebdb7875443e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
1
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
2 local mainlog = log;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
3 local function log(type, message)
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
4 mainlog(type, "rostermanager", message);
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
5 end
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
6
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
7 local setmetatable = setmetatable;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
8 local format = string.format;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
9 local loadfile, setfenv, pcall = loadfile, setfenv, pcall;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
10
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
11 require "util.datamanager"
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
12
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
13 local datamanager = datamanager;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
14
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
15 module "rostermanager"
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
16
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
17 --[[function getroster(username, host)
3
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
18 return {
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
19 ["mattj@localhost"] = true,
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
20 ["tobias@getjabber.ath.cx"] = true,
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
21 ["waqas@getjabber.ath.cx"] = true,
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
22 ["thorns@getjabber.ath.cx"] = true,
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
23 ["idw@getjabber.ath.cx"] = true,
f674eb704134 "Shared roster" - well, kind of :)
matthew
parents: 0
diff changeset
24 }
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
25 --return datamanager.load(username, host, "roster") or {};
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
26 end]]
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
27
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
28 function add_to_roster(roster, jid, item)
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
29 roster[jid] = item;
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
30 -- TODO implement
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
31 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
32
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
33 function remove_from_roster(roster, jid)
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
34 roster[jid] = nil;
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
35 -- TODO implement
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
36 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
37
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
38 function load_roster(host, username)
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
39 if hosts[host] and hosts[host].sessions[username] then
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
40 local roster = hosts[host].sessions[username].roster;
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
41 if not roster then
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
42 return hosts[host].sessions[username].roster = datamanger.load(username, host, "roster") or {};
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
43 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
44 return roster;
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
45 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
46 error("Attempt to load roster for non-loaded user"); --return nil;
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
47 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
48
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
49 function save_roster(host, username)
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
50 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
51 return datamanager.save(username, host, "roster", hosts[host].sessions[username].roster);
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
52 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
53 return nil;
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
54 end
80
523ac742cc19 Fixed: rostermanager.lua now returns the module
Waqas Hussain <waqas20@gmail.com>
parents: 6
diff changeset
55
523ac742cc19 Fixed: rostermanager.lua now returns the module
Waqas Hussain <waqas20@gmail.com>
parents: 6
diff changeset
56 return _M;