浏览代码

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

j8
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
             "there are %s occupants in room", tostring(participant_count));
105
             "there are %s occupants in room", tostring(participant_count));
106
 	else
106
 	else
107
 		log("debug", "no such room exists");
107
 		log("debug", "no such room exists");
108
+		return 404;
108
 	end
109
 	end
109
 
110
 
110
 	if participant_count > 1 then
111
 	if participant_count > 1 then
111
 		participant_count = participant_count - 1;
112
 		participant_count = participant_count - 1;
112
 	end
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
 end
116
 end
122
 
117
 
123
 --- Handles request for retrieving the room participants details
118
 --- Handles request for retrieving the room participants details
171
             "there are %s occupants in room", tostring(participant_count));
166
             "there are %s occupants in room", tostring(participant_count));
172
 	else
167
 	else
173
 		log("debug", "no such room exists");
168
 		log("debug", "no such room exists");
169
+		return 404;
174
 	end
170
 	end
175
 
171
 
176
 	if participant_count > 1 then
172
 	if participant_count > 1 then
177
 		participant_count = participant_count - 1;
173
 		participant_count = participant_count - 1;
178
 	end
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
 end;
177
 end;
188
 
178
 
189
 function module.load()
179
 function module.load()

+ 10
- 3
resources/prosody-plugins/util.lib.lua 查看文件

66
     -- the handler is done.
66
     -- the handler is done.
67
     local response = event.response;
67
     local response = event.response;
68
     local async_func = runner(function (event)
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
     end)
79
     end)
73
     async_func:run(event)
80
     async_func:run(event)
74
     -- return true to keep the client http connection open.
81
     -- return true to keep the client http connection open.

正在加载...
取消
保存