Преглед на файлове

Fixes the room size api which returns string result back to client.

master
damencho преди 7 години
родител
ревизия
d12afc5c07
променени са 2 файла, в които са добавени 14 реда и са изтрити 17 реда
  1. 4
    14
      resources/prosody-plugins/mod_muc_size.lua
  2. 10
    3
      resources/prosody-plugins/util.lib.lua

+ 4
- 14
resources/prosody-plugins/mod_muc_size.lua Целия файл

@@ -105,19 +105,14 @@ function handle_get_room_size(event)
105 105
             "there are %s occupants in room", tostring(participant_count));
106 106
 	else
107 107
 		log("debug", "no such room exists");
108
+		return 404;
108 109
 	end
109 110
 
110 111
 	if participant_count > 1 then
111 112
 		participant_count = participant_count - 1;
112 113
 	end
113 114
 
114
-	local GET_response = {
115
-		headers = {
116
-			content_type = "application/json";
117
-		};
118
-		body = [[{"participants":]]..participant_count..[[}]];
119
-	};
120
-	return GET_response;
115
+	return [[{"participants":]]..participant_count..[[}]];
121 116
 end
122 117
 
123 118
 --- Handles request for retrieving the room participants details
@@ -171,19 +166,14 @@ function handle_get_room (event)
171 166
             "there are %s occupants in room", tostring(participant_count));
172 167
 	else
173 168
 		log("debug", "no such room exists");
169
+		return 404;
174 170
 	end
175 171
 
176 172
 	if participant_count > 1 then
177 173
 		participant_count = participant_count - 1;
178 174
 	end
179 175
 
180
-	local GET_response = {
181
-		headers = {
182
-			content_type = "application/json";
183
-		};
184
-		body = json.encode(occupants_json);
185
-	};
186
-	return GET_response;
176
+	return json.encode(occupants_json);
187 177
 end;
188 178
 
189 179
 function module.load()

+ 10
- 3
resources/prosody-plugins/util.lib.lua Целия файл

@@ -66,9 +66,16 @@ function wrap_async_run(event,handler)
66 66
     -- the handler is done.
67 67
     local response = event.response;
68 68
     local async_func = runner(function (event)
69
-          response.status_code = handler(event);
70
-          -- Send the response to the waiting http client.
71
-          response:send();
69
+        local result = handler(event);
70
+        -- if it is a number, it is a status code, else it is the body
71
+        -- result we will return
72
+        if (tonumber(result) ~= nil) then
73
+            response.status_code = result;
74
+        else
75
+            response.body = result;
76
+        end;
77
+        -- Send the response to the waiting http client.
78
+        response:send();
72 79
     end)
73 80
     async_func:run(event)
74 81
     -- return true to keep the client http connection open.

Loading…
Отказ
Запис