mod_mix: Add events and fix <nick> when joining
This commit is contained in:
		
							parent
							
								
									08c513a957
								
							
						
					
					
						commit
						15c1179f4d
					
				| @ -350,7 +350,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|     local j, _ = channel:find_participant(from); | ||||
|     local j, participant = channel:find_participant(from); | ||||
|     if j == -1 then | ||||
|         origin.send(st.error_reply(stanza, | ||||
|                                    "cancel", | ||||
| @ -379,6 +379,8 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) | ||||
|     table.remove(channel.participants, j); | ||||
|     channel:save_state(); | ||||
| 
 | ||||
|     module:fire_event("mix-channel-leave", { channel = channel, participant = participant }); | ||||
| 
 | ||||
|     origin.send(st.reply(stanza):tag("leave", { xmlns = mix_core_xmlns })); | ||||
|     return true; | ||||
| end); | ||||
| @ -475,7 +477,9 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) | ||||
|     publish_participant(srv, channel, spid, participant); | ||||
|     channel:save_state(); | ||||
| 
 | ||||
|     reply:add_child(nick); | ||||
|     module:fire_event("mix-channel-join", { channel = channel, participant = participant }); | ||||
| 
 | ||||
|     reply:add_child(nick_tag); | ||||
|     reply:tag("x", { xmlns = "jabber:x:data", type = "result" }) | ||||
|         :tag("field", { var = "FORM_TYPE", type = "hidden" }) | ||||
|             :tag("value"):text(mix_anon_xmlns):up():up() | ||||
| @ -524,6 +528,8 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event) | ||||
|     --local participant = channel.participants[participant_index]; | ||||
|     publish_participant(srv, channel, channel:get_spid(participant.jid), participant); | ||||
| 
 | ||||
|     module:fire_event("mix-change-nick", { channel = channel, participant = participant }); | ||||
| 
 | ||||
|     origin.send(st.reply(stanza) | ||||
|                     :tag("setnick", { xmlns = mix_core_xmlns }) | ||||
|                         :tag("nick"):text(nick:get_text())); | ||||
| @ -628,6 +634,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":create", function(event) | ||||
|         create_channel(node, from, true); | ||||
|     end | ||||
|     module:log("debug", "Channel %s created with %s as owner", node, from); | ||||
|     -- TODO: Add an event | ||||
| 
 | ||||
|     origin.send(st.reply(stanza) | ||||
|                 :tag("create", { xmlns = mix_core_xmlns, channel = node })); | ||||
| @ -662,6 +669,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":destroy", function(event) | ||||
|     end | ||||
|     table.remove(channels, i); | ||||
| 
 | ||||
|     module:fire_event("mix-destroy-channel", { channel = channel }); | ||||
|     module:log("debug", "Channel %s destroyed", node); | ||||
| 
 | ||||
|     origin.send(st.reply(stanza)); | ||||
| @ -703,7 +711,7 @@ module:hook("message/bare", function(event) | ||||
|     message_archive:append(stanza.attr.to, mam_id, msg, time.now()); | ||||
|     msg.attr.from = channel.jid.."/"..channel:get_spid(from); | ||||
| 
 | ||||
|     if module:fire_event("mix-broadcast-message", msg) then | ||||
|     if module:fire_event("mix-broadcast-message", { message = msg, channel = channel }) then | ||||
|         return true; | ||||
|     end | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user