mix: Fix smaller issues
This commit is contained in:
		
							parent
							
								
									51cecc0494
								
							
						
					
					
						commit
						d996bd34b9
					
				| @ -26,7 +26,7 @@ local restrict_channel_creation = module:get_option("restrict_local_channels", " | ||||
| 
 | ||||
| module:depends("disco"); | ||||
| -- module:depends("mam"); TODO: Once message sending works | ||||
| module:add_identity("conference", "mix", module:get_option("name", "Prosody MIX service"); | ||||
| module:add_identity("conference", "mix", module:get_option("name", "Prosody MIX service")); | ||||
| module:add_feature("http://jabber.org/protocol/disco#info"); | ||||
| module:add_feature(mix_core_xmlns); | ||||
| 
 | ||||
| @ -62,6 +62,11 @@ function Channel:get_spid(jid) | ||||
|     return self.spid[jid]; | ||||
| end | ||||
| 
 | ||||
| function Channel:set_spid(jid, spid) | ||||
|     -- Sets the Stable Participant ID for the *BARE* jid | ||||
|     self.spid[jid] = spid; | ||||
| end | ||||
| 
 | ||||
| function Channel:debug_print() | ||||
|     module:log("debug", "Channel %s (%s)", self.jid, self.name); | ||||
|     module:log("debug", "'%s'", self.description); | ||||
| @ -168,10 +173,10 @@ module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(eve | ||||
|     module:log("debug", "IQ-GET disco#items"); | ||||
| 
 | ||||
|     local origin, stanza = event.origin, event.stanza; | ||||
|     local _, channel = get_channel(staza.attr.to); | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|      | ||||
|     -- TODO: Maybe check permissions | ||||
| @ -226,7 +231,7 @@ module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function( | ||||
|     local _, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|     local reply = st.reply(stanza):tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }); | ||||
|     reply:tag("feature", { var = "http://jabber.org/protocol/disco#info" }):up(); | ||||
| @ -258,7 +263,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local participant_index = find_participant(channel.participants, from); | ||||
| @ -269,7 +274,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) | ||||
|                                    "Not a participant")); | ||||
|         channel:debug_print(); | ||||
|         module:log("debug", "%s is not a participant in %s", from, channel.jid); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     -- Remove the user as a participant by... | ||||
| @ -298,14 +303,14 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|      | ||||
|     -- Prevent the user from joining multiple times | ||||
|     local participant_index = find_participant(channel.participants, from); | ||||
|     if participant_index ~= -1 then | ||||
|         origin.send(st.error_reply(stanza, "cancel", "bad-request", "User already joined")); | ||||
|         return; | ||||
|         module:send(st.error_reply(stanza, "cancel", "bad-request", "User already joined")); | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local spid = channel:get_spid(from) or uuid.generate(); -- Stable Participant ID | ||||
| @ -339,13 +344,13 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) | ||||
| 
 | ||||
|     if not has_subscribed_once then | ||||
|         origin.send(st.error_reply(stanza, "cancel", first_error)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local participant = Participant:new(jid.bare(from), nick:get_text()) | ||||
|     channels[i].subscriptions[from] = nodes; | ||||
|     table.insert(channels[i].participants, participant) | ||||
|     channels[i]:get_spid(jid.bare(stanza.attr.from)) = spid; | ||||
|     channels[i]:set_spid(jid.bare(stanza.attr.from), spid); | ||||
|     publish_participant(srv, spid, participant); | ||||
|     channels[i]:save_state(); | ||||
| 
 | ||||
| @ -361,14 +366,14 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event) | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local participant_index = find_participant(channel.participants, from); | ||||
|     if participant_index == -1 then | ||||
|         channel:debug_print(); | ||||
|         module:log("debug", "%s is not a participant in %s", from, channel.jid); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|      | ||||
|     -- NOTE: Prosody should guarantee us that the setnick stanza exists | ||||
| @ -376,7 +381,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event) | ||||
|     local nick = setnick:get_child("nick"); | ||||
|     if nick_stanza == nil then | ||||
|         origin.send(st.error_reply(stanza, "cancel", "bad-request", "Missing <nick>")); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     -- Change the nick | ||||
| @ -417,11 +422,17 @@ function create_channel(node, creator, adhoc) | ||||
|     -- Create the PEP nodes | ||||
|     local srv = pep.get_pep_service(node); | ||||
|     local timestamp = datetime.datetime(time.now()); | ||||
|     srv:create("urn:xmpp:mix:nodes:info", true, { ["access_model"] = "open" }); | ||||
|     local access_model = adhoc and "whitelist" or "open"; | ||||
|     for _, psnode in pairs({"urn:xmpp:mix:nodes:info", "urn:xmpp:mix:nodes:participants", "urn:xmpp:mix:nodes:messages" }) do | ||||
|         srv:create(psnode, true, { ["access_model"] = access_model }); | ||||
|          | ||||
|         -- If the channel is an adhoc channel, then we need to make sure that | ||||
|         -- node affiliations are correct | ||||
|         if adhoc then | ||||
|             srv:set_affiliation(psnode, true, creator, "owner"); | ||||
|         end | ||||
|     end | ||||
|     channel:publish_info(srv); | ||||
|     -- TODO: This seems bad | ||||
|     srv:create("urn:xmpp:mix:nodes:participants", true, { ["access_model"] = "open"}); | ||||
|     srv:create("urn:xmpp:mix:nodes:messages", true, { ["access_model"] = "open"}); | ||||
|     table.insert(channels, channel); | ||||
| end | ||||
| 
 | ||||
| @ -433,7 +444,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":create", function(event) | ||||
|     -- Check permissions | ||||
|     if not can_create_channels(from) then | ||||
|         origin.send(st.error_reply(stanza, "cancel", "forbidden", "Not authorized to create channels")); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local create = stanza:get_child("create", mix_core_xmlns); | ||||
| @ -447,7 +458,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":create", function(event) | ||||
|                                        "cancel", | ||||
|                                        "conflict", | ||||
|                                        "Channel already exists")); | ||||
|             return; | ||||
|             return true; | ||||
|         end | ||||
| 
 | ||||
|         create_channel(create.attr.channel, from, false); | ||||
| @ -482,7 +493,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":destroy", function(event) | ||||
|     local i, channel = get_channel(node_jid); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|     -- TODO: Check permissions: can_create_channels and maybe compare to the contact JIDs | ||||
|      | ||||
| @ -507,20 +518,20 @@ module:hook("message/bare", function(event) | ||||
|     if stanza.attr.type ~= "groupchat" then | ||||
|         -- TODO: Is this correct? | ||||
|         origin.send(st.error_reply(stanza, "cancel", "bad-request", "Non-groupchat message")); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local from = jid.bare(stanza.attr.from); | ||||
|     local i, channel = get_channel(stanza.attr.to); | ||||
|     if not channel then | ||||
|         origin.send(channel_not_found(stanza)); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|      | ||||
|     local participant_index = find_participant(channel.participants, from); | ||||
|     if participant_index == -1 then | ||||
|         origin.send(st.error_reply(stanza, "cancel", "forbidden", "Not a participant")); | ||||
|         return; | ||||
|         return true; | ||||
|     end | ||||
|     local participant = channel.participants[participant_index]; | ||||
| 
 | ||||
| @ -530,12 +541,11 @@ module:hook("message/bare", function(event) | ||||
|                     :tag("jid"):text(participant.jid):up()); | ||||
|     msg.attr.from = channel.jid.."/"..channel:get_spid(from); | ||||
|     for _, p in pairs(channel.participants) do | ||||
|         if p.jid ~= participant.jid then | ||||
|             msg.attr.to = p.jid; | ||||
|             module:send(msg); | ||||
|             module:log("debug", msg:pretty_print()); | ||||
|             module:log("debug", "Message from %s sent to %s", participant.jid, p.jid); | ||||
|         end | ||||
|         -- TODO: Add message to the MAM and return its ID | ||||
|         local tmp = st.clone(msg); | ||||
|         tmp.attr.to = p.jid; | ||||
|         module:send(tmp); | ||||
|         module:log("debug", "Message from %s sent to %s", participant.jid, p.jid); | ||||
|     end | ||||
|     return true; | ||||
| end); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user