mod_cloud_notify/mod_cloud_notify.lua
changeset 3089 1ea6861b533f
parent 3083 2a918a8c47db
child 3112 cfcb020bcd1d
equal deleted inserted replaced
3088:5b4e7db5943c 3089:1ea6861b533f
   136 	local error_type, condition = stanza:get_error();
   136 	local error_type, condition = stanza:get_error();
   137 	local node = id2node[stanza.attr.id];
   137 	local node = id2node[stanza.attr.id];
   138 	if node == nil then return false; end		-- unknown stanza? Ignore for now!
   138 	if node == nil then return false; end		-- unknown stanza? Ignore for now!
   139 	local from = stanza.attr.from;
   139 	local from = stanza.attr.from;
   140 	local user_push_services = push_store:get(node);
   140 	local user_push_services = push_store:get(node);
       
   141 	local changed = false;
   141 	
   142 	
   142 	for push_identifier, _ in pairs(user_push_services) do
   143 	for push_identifier, _ in pairs(user_push_services) do
   143 		local stanza_id = hashes.sha256(push_identifier, true);
   144 		local stanza_id = hashes.sha256(push_identifier, true);
   144 		if stanza_id == stanza.attr.id then
   145 		if stanza_id == stanza.attr.id then
   145 			if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then
   146 			if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then
   157 								session.push_settings = nil;
   158 								session.push_settings = nil;
   158 							end
   159 							end
   159 						end
   160 						end
   160 					end
   161 					end
   161 					-- save changed global config
   162 					-- save changed global config
   162 					push_store:set_identifier(node, push_identifier, nil);
   163 					changed = true;
       
   164 					user_push_services[push_identifier] = nil
   163 					push_errors[push_identifier] = nil;
   165 					push_errors[push_identifier] = nil;
   164 					-- unhook iq handlers for this identifier (if possible)
   166 					-- unhook iq handlers for this identifier (if possible)
   165 					if module.unhook then
   167 					if module.unhook then
   166 						module:unhook("iq-error/host/"..stanza_id, handle_push_error);
   168 						module:unhook("iq-error/host/"..stanza_id, handle_push_error);
   167 						module:unhook("iq-result/host/"..stanza_id, handle_push_success);
   169 						module:unhook("iq-result/host/"..stanza_id, handle_push_success);
   171 			elseif user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type == "wait" then
   173 			elseif user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type == "wait" then
   172 				module:log("debug", "Got error of type '%s' (%s) for identifier '%s': "
   174 				module:log("debug", "Got error of type '%s' (%s) for identifier '%s': "
   173 					.."NOT increasing error count for this identifier", error_type, condition, push_identifier);
   175 					.."NOT increasing error count for this identifier", error_type, condition, push_identifier);
   174 			end
   176 			end
   175 		end
   177 		end
       
   178 	end
       
   179 	if changed then
       
   180 		push_store:set(node, user_push_services);
   176 	end
   181 	end
   177 	return true;
   182 	return true;
   178 end
   183 end
   179 
   184 
   180 function handle_push_success(event)
   185 function handle_push_success(event)