Comparison

mod_roster_command/mod_roster_command.lua @ 1565:f9cb09d451c7

mod_roster_command: Add 'remove' command
author Kim Alvefur <zash@zash.se>
date Mon, 10 Nov 2014 11:06:26 +0100
parent 1509:01e37ce7532e
child 1946:1f263aaba83e
comparison
equal deleted inserted replaced
1564:cb4111a4cd36 1565:f9cb09d451c7
115 end 115 end
116 rostermanager.save_roster(user_username, user_host, roster); 116 rostermanager.save_roster(user_username, user_host, roster);
117 end 117 end
118 end 118 end
119 119
120 function remove(user_jid, contact_jid)
121 unsubscribe_both(user_jid, contact_jid);
122 local user_username, user_host = jid.split(user_jid);
123 local roster = rostermanager.load_roster(user_username, user_host);
124 roster[contact_jid] = nil;
125 rostermanager.save_roster(user_username, user_host, roster);
126 end
127
120 function module.command(arg) 128 function module.command(arg)
121 local command = arg[1]; 129 local command = arg[1];
122 if not command then 130 if not command then
123 warn("Valid subcommands: (un)subscribe(_both) | rename"); 131 warn("Valid subcommands: (un)subscribe(_both) | rename");
124 return 0; 132 return 0;
134 unsubscribe(arg[1], arg[2]); 142 unsubscribe(arg[1], arg[2]);
135 return 0; 143 return 0;
136 elseif command == "unsubscribe_both" then 144 elseif command == "unsubscribe_both" then
137 unsubscribe_both(arg[1], arg[2]); 145 unsubscribe_both(arg[1], arg[2]);
138 return 0; 146 return 0;
147 elseif command == "remove" then
148 remove(arg[1], arg[2]);
149 return 0;
139 elseif command == "rename" then 150 elseif command == "rename" then
140 rename(arg[1], arg[2], arg[3], arg[4]); 151 rename(arg[1], arg[2], arg[3], arg[4]);
141 return 0; 152 return 0;
142 else 153 else
143 warn("Unknown command: %s", command); 154 warn("Unknown command: %s", command);