Software /
code /
prosody
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 |
rev | line source |
---|---|
0 | 1 |
2 local mainlog = log; | |
3 local function log(type, message) | |
4 mainlog(type, "rostermanager", message); | |
5 end | |
6 | |
7 local setmetatable = setmetatable; | |
8 local format = string.format; | |
9 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; | |
10 | |
11 require "util.datamanager" | |
12 | |
13 local datamanager = datamanager; | |
14 | |
15 module "rostermanager" | |
16 | |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
17 --[[function getroster(username, host) |
3 | 18 return { |
19 ["mattj@localhost"] = true, | |
20 ["tobias@getjabber.ath.cx"] = true, | |
21 ["waqas@getjabber.ath.cx"] = true, | |
22 ["thorns@getjabber.ath.cx"] = true, | |
23 ["idw@getjabber.ath.cx"] = true, | |
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 | 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; |