mod_mix: Make the linter happy
This commit is contained in:
		
							parent
							
								
									dc9d388ec3
								
							
						
					
					
						commit
						b0aca926fe
					
				| @ -1,5 +1,5 @@ | ||||
| -- Helper functions for mod_mix | ||||
| function find(array, f) | ||||
| local function find(array, f) | ||||
|     -- Searches for an element for which f returns true. The first element | ||||
|     -- and its index are returned. If none are found, then -1, nil is returned. | ||||
|     -- | ||||
| @ -11,9 +11,9 @@ function find(array, f) | ||||
|     return -1, nil; | ||||
| end | ||||
| 
 | ||||
| function find_str(array, str) | ||||
| local function find_str(array, str) | ||||
|     -- Returns the index of str in array. -1 if array does not contain str | ||||
|     local i, v = find(array, function(v) return v == str end); | ||||
|     local i, _ = find(array, function(v) return v == str end); | ||||
|     return i; | ||||
| end | ||||
| 
 | ||||
|  | ||||
| @ -81,7 +81,7 @@ function Channel:debug_print() | ||||
|         module:log("debug", "Subscriptions:"); | ||||
|         for user, subs in pairs(self.subscriptions) do | ||||
|             module:log("debug", "[%s]", user); | ||||
|             for _, sub in pairs(self.subscriptions[user]) do | ||||
|             for _, sub in pairs(subs) do | ||||
|                 module:log("debug", "=> %s", sub); | ||||
|             end | ||||
|         end | ||||
|  | ||||
| @ -28,9 +28,9 @@ local mix_anon_xmlns = "urn:xmpp:mix:anon:0"; | ||||
| local mix_node_messages = "urn:xmpp:mix:nodes:messages"; | ||||
| local mix_node_participants = "urn:xmpp:mix:nodes:participants"; | ||||
| local mix_node_info = "urn:xmpp:mix:nodes:info"; | ||||
| local mix_node_allowed = "urn:xmpp:mix:nodes:allowed"; | ||||
| local mix_node_banned = "urn:xmpp:mix:nodes:banned"; | ||||
| local mix_node_config = "urn:xmpp:mix:nodes:config"; | ||||
| --local mix_node_allowed = "urn:xmpp:mix:nodes:allowed"; | ||||
| --local mix_node_banned = "urn:xmpp:mix:nodes:banned"; | ||||
| --local mix_node_config = "urn:xmpp:mix:nodes:config"; | ||||
| 
 | ||||
| local mam_xmlns = "urn:xmpp:mam:2"; | ||||
| 
 | ||||
| @ -88,13 +88,13 @@ module:add_feature(mix_core_xmlns); | ||||
| 
 | ||||
| local channels = {}; | ||||
| 
 | ||||
| function get_channel(jid) | ||||
| local function get_channel(channel_jid) | ||||
|     -- Return the channel object from the channels array for which the | ||||
|     -- JID matches. If none is found, returns -1, nil | ||||
|     return helpers.find(channels, function(c) return c.jid == jid; end); | ||||
|     return helpers.find(channels, function(c) return c.jid == channel_jid; end); | ||||
| end | ||||
| 
 | ||||
| function save_channels() | ||||
| local function save_channels() | ||||
|     module:log("debug", "Saving channel list..."); | ||||
|     local channel_list = {}; | ||||
|     for _, channel in pairs(channels) do | ||||
| @ -115,7 +115,7 @@ function Channel:save_state() | ||||
|     module:log("debug", "Saving state done.", self.jid); | ||||
| end | ||||
| 
 | ||||
| function publish_participant(service, channel, spid, participant) | ||||
| local function publish_participant(service, channel, spid, participant) | ||||
|     -- Publish a new participant on the service | ||||
|     -- NOTE: This function has be to called *after* the new participant | ||||
|     --       has been added to the channel.participants attay | ||||
| @ -136,8 +136,8 @@ function module.load() | ||||
| 
 | ||||
|     local channel_list = persistent_channels:get("channels"); | ||||
|     if channel_list then | ||||
|         for _, channel in pairs(channel_list) do | ||||
|             local channel = Channel:from(persistent_channel_data:get(channel)); | ||||
|         for _, channel_data in pairs(channel_list) do | ||||
|             local channel = Channel:from(persistent_channel_data:get(channel_data)); | ||||
|             table.insert(channels, channel); | ||||
|             module:log("debug", "MIX channel %s loaded", channel.jid); | ||||
|         end | ||||
| @ -147,7 +147,7 @@ function module.load() | ||||
|     module:log("info", "Loading MIX channels done."); | ||||
| end | ||||
| 
 | ||||
| function channel_not_found(stanza) | ||||
| local function channel_not_found(stanza) | ||||
|     -- Wrapper for returning a "Channel-not-found" error stanza | ||||
|     return st.error_reply(stanza, | ||||
|                           "cancel", | ||||
| @ -198,7 +198,7 @@ module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(eve | ||||
|     return true; | ||||
| end); | ||||
| 
 | ||||
| function can_create_channels(user) | ||||
| local function can_create_channels(user) | ||||
|     -- Returns true when the jid is allowed to create MIX channels. False otherwise. | ||||
|     -- NOTE: Taken from plugins/muc/mod_muc.lua | ||||
|     local host_suffix = host:gsub("^[^%.]+%.", ""); | ||||
| @ -287,6 +287,7 @@ module:hook("iq-set/bare/"..mam_xmlns..":query", function(event) | ||||
|     local query_id = query.attr.queryid; | ||||
|     local x = query:get_child("x", "jabber:x:data"); | ||||
|     if x ~= nil then | ||||
|         -- TODO: Error handling | ||||
|         local form, err = mam_query_form:data(x); | ||||
| 
 | ||||
|         -- Validate | ||||
| @ -311,9 +312,9 @@ module:hook("iq-set/bare/"..mam_xmlns..":query", function(event) | ||||
|         end | ||||
|         return true; | ||||
|     end | ||||
|     for id, item, when in data do | ||||
|     for message_id, item, when in data do | ||||
|         local msg = st.stanza("message", { from = channel_jid, to = stanza.attr.from, type = "groupchat" }) | ||||
|                         :tag("result", { xmlns = mam_xmlns, queryid = query_id, id = id }) | ||||
|                         :tag("result", { xmlns = mam_xmlns, queryid = query_id, id = message_id }) | ||||
|                             :tag("forwarded", { xmlns = "urn:xmpp:forward:0" }) | ||||
|                                 :tag("delay", { xmlns = "urn:xmpp:delay", stamp = datetime.datetime(when) }):up(); | ||||
|         msg:add_child(item); | ||||
| @ -343,7 +344,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) | ||||
|     module:log("debug", "MIX leave received"); | ||||
|     local origin, stanza = event.origin, event.stanza; | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return true; | ||||
| @ -384,7 +385,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) | ||||
| 
 | ||||
|     local origin, stanza = event.origin, event.stanza; | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return true; | ||||
| @ -404,10 +405,10 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) | ||||
|     local join = stanza:get_child("join", mix_core_xmlns); | ||||
|     local nick_tag = join:get_child("nick"); | ||||
|     local nick; | ||||
|     if not join:get_child("nick") then | ||||
|     if not nick_tag then | ||||
|         nick = jid.node(from); | ||||
|     else | ||||
|         nick = join:get_child("nick"):get_text(); | ||||
|         nick = nick_tag:get_text(); | ||||
|     end | ||||
|     module:log("debug", "User joining as nick %s", nick); | ||||
| 
 | ||||
| @ -492,7 +493,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event) | ||||
|     module:log("debug", "MIX setnick received"); | ||||
|     local origin, stanza = event.origin, event.stanza; | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return true; | ||||
| @ -542,7 +543,7 @@ function Channel:publish_info(srv) | ||||
|     srv:publish(mix_node_info, true, timestamp, info); | ||||
| end | ||||
| 
 | ||||
| function create_channel(node, creator, adhoc) | ||||
| local function create_channel(node, creator, adhoc) | ||||
|     local channel = Channel:new(string.format("%s@%s", node, host), | ||||
|                                 default_channel_name, | ||||
|                                 default_channel_description, | ||||
| @ -553,7 +554,6 @@ function create_channel(node, creator, adhoc) | ||||
|                                 adhoc); | ||||
|     -- Create the PEP nodes | ||||
|     local srv = pep.get_pep_service(node); | ||||
|     local timestamp = datetime.datetime(time.now()); | ||||
|     -- MIX-CORE | ||||
|     for _, psnode in pairs({ mix_node_info, mix_node_participants, mix_node_messages }) do | ||||
|         srv:create(psnode, true, { | ||||
| @ -637,8 +637,8 @@ module:hook("iq-set/host/"..mix_core_xmlns..":destroy", function(event) | ||||
|     local origin, stanza = event.origin, event.stanza; | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
| 
 | ||||
|     local destroy = stanza:get_child("create", mix_core_xmlns); | ||||
|     local node = destory.attr.channel; | ||||
|     local destroy = stanza:get_child("destroy", mix_core_xmlns); | ||||
|     local node = destroy.attr.channel; | ||||
|     local node_jid = string.format("%s@%s", node, host); | ||||
|     local i, channel = get_channel(node_jid); | ||||
|     if not channel then | ||||
| @ -674,7 +674,7 @@ module:hook("message/bare", function(event) | ||||
|     end | ||||
| 
 | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return true; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user