comparison mod_vjud/mod_vjud.lua @ 880:312602605269

mod_vjud: Do case-insensitive matching
author Kim Alvefur <zash@zash.se>
date Sun, 16 Dec 2012 12:29:02 +0100
parents 3a17fc0127b1
children 4b06d6c79b15
comparison
equal deleted inserted replaced
879:3a17fc0127b1 880:312602605269
4 local usermanager = require "core.usermanager"; 4 local usermanager = require "core.usermanager";
5 local dataforms_new = require "util.dataforms".new; 5 local dataforms_new = require "util.dataforms".new;
6 local jid_split = require "util.jid".prepped_split; 6 local jid_split = require "util.jid".prepped_split;
7 local vcard = module:require "vcard"; 7 local vcard = module:require "vcard";
8 local rawget, rawset = rawget, rawset; 8 local rawget, rawset = rawget, rawset;
9 local s_lower = string.lower;
10 local s_find = string.find;
9 11
10 local st = require "util.stanza"; 12 local st = require "util.stanza";
11 local template = require "util.template"; 13 local template = require "util.template";
12 14
13 local get_reply = template[[ 15 local get_reply = template[[
114 }); 116 });
115 end 117 end
116 else 118 else
117 for username in pairs(opted_in) do 119 for username in pairs(opted_in) do
118 local vCard = get_user_vcard(username); 120 local vCard = get_user_vcard(username);
119 if vCard and ( 121 if vCard
120 (vCard.N and vCard.N[2] == first) or 122 and ((first and vCard.N and s_find(s_lower(vCard.N[2]), first, nil, true))
121 (vCard.N and vCard.N[1] == last) or 123 or (last and vCard.N and s_find(s_lower(vCard.N[1]), last, nil, true))
122 (vCard.NICKNAME and vCard.NICKNAME[1] == nick) or 124 or (nick and vCard.NICKNAME and s_find(s_lower(vCard.NICKNAME[1]), nick, nil, true))
123 (vCard.EMAIL and vCard.EMAIL[1] == email)) then 125 or (email and vCard.EMAIL and s_find(s_lower(vCard.EMAIL[1]), email, nil, true))) then
124 reply:add_child(item_template.apply{ 126 reply:add_child(item_template.apply{
125 jid = username..at_host; 127 jid = username..at_host;
126 first = vCard.N and vCard.N[2] or nil; 128 first = vCard.N and vCard.N[2] or nil;
127 last = vCard.N and vCard.N[1] or nil; 129 last = vCard.N and vCard.N[1] or nil;
128 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username; 130 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username;