Commit fb925ed0 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RoomListPresenter.kt

parent 8bbb746d
...@@ -162,55 +162,54 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -162,55 +162,54 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
}) })
} }
// TODO (need test) // TODO (need a rest api fix)
override fun requestFileList(roomId: String, override fun requestFileList(roomId: String,
roomType: String, roomType: String,
hostname: String, hostname: String,
token: String, token: String,
userId: String) { userId: String) {
OkHttpHelper.getClient() // OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForFileList(roomId, // .newCall(RestApiHelper.getRequestForFileList(roomId,
roomType, // roomType,
hostname, // hostname,
token, // token,
userId)) // userId))
.enqueue(object : Callback { // .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { // override fun onFailure(call: Call, e: IOException) {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) } // mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) }
} // }
//
@Throws(IOException::class) // @Throws(IOException::class)
override fun onResponse(call: Call, response: Response) { // override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) { // if (response.isSuccessful) {
val jSONObject = JSONObject(response.body()?.string()) // val jSONObject = JSONObject(response.body()?.string())
val filesJSONArray = jSONObject.get("files") as JSONArray // val filesJSONArray = jSONObject.get("files") as JSONArray
//
val filesJSONArrayLength = filesJSONArray.length() // val filesJSONArrayLength = filesJSONArray.length()
val amazonS3JSONArray = JSONArray() // val amazonS3JSONArray = JSONArray()
for (i in 0 until filesJSONArrayLength) { // for (i in 0 until filesJSONArrayLength) {
amazonS3JSONArray.put(filesJSONArray.getJSONObject(i).get("AmazonS3")) // amazonS3JSONArray.put(filesJSONArray.getJSONObject(i).get("AmazonS3"))
} // }
//
val pathJSONArray = JSONArray() // val pathJSONArray = JSONArray()
val amazonS3JSONArrayLength = amazonS3JSONArray.length() // val amazonS3JSONArrayLength = amazonS3JSONArray.length()
for (i in 0 until amazonS3JSONArrayLength) { // for (i in 0 until amazonS3JSONArrayLength) {
pathJSONArray.put(amazonS3JSONArray.getJSONObject(i).get("path")) // pathJSONArray.put(amazonS3JSONArray.getJSONObject(i).get("path"))
} // }
val pathJSONArrayLength = pathJSONArray.length() // val pathJSONArrayLength = pathJSONArray.length()
val dataSet = ArrayList<String>(pathJSONArrayLength) // val dataSet = ArrayList<String>(pathJSONArrayLength)
(0 until pathJSONArrayLength).mapTo(dataSet) { // (0 until pathJSONArrayLength).mapTo(dataSet) {
UrlHelper.getUrlForFile(pathJSONArray.get(it).toString(), userId, token) // UrlHelper.getUrlForFile(pathJSONArray.get(it).toString(), userId, token)
} // }
//
mainHandler.post { view.showFileList(dataSet) } // mainHandler.post { view.showFileList(dataSet) }
} else { // } else {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, response.message())) } // mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, response.message())) }
} // }
} // }
}) // })
} }
// TODO (Requires the user id ("_id) and user status ("status") to be returned from the REST API call. Check out current PR status here: https://github.com/RocketChat/Rocket.Chat/pull/8147)
override fun requestMemberList(roomId: String, override fun requestMemberList(roomId: String,
roomType: String, roomType: String,
hostname: String, hostname: String,
...@@ -231,24 +230,27 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -231,24 +230,27 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) { if (response.isSuccessful) {
val jSONObject = JSONObject(response.body()?.string()) val jSONObject = JSONObject(response.body()?.string())
Log.i("json", "= " + jSONObject)
Log.i("json", "total = " + jSONObject.get("total"))
val membersJSONArray = jSONObject.get("members") as JSONArray val membersJSONArray = jSONObject.get("members") as JSONArray
val membersJSONArrayLength = membersJSONArray.length() val membersJSONArrayLength = membersJSONArray.length()
val dataSet = ArrayList<User>(membersJSONArrayLength) val dataSet = ArrayList<User>(membersJSONArrayLength)
(0 until membersJSONArrayLength).mapTo(dataSet) { (0 until membersJSONArrayLength).mapTo(dataSet) {
User.builder() User.builder()
.setId("") .setId(membersJSONArray.getJSONObject(it).optString("_id"))
.setUsername(membersJSONArray.get(it).toString()) .setName(membersJSONArray.getJSONObject(it).optString("name"))
// Note: There is no result to UTC OFFSET but as it is a required attribute to the user we can set it as 0. .setUsername(membersJSONArray.getJSONObject(it).optString("username"))
.setStatus("") .setStatus(membersJSONArray.getJSONObject(it).optString("status"))
.setUtcOffset(0.0) .setUtcOffset(membersJSONArray.getJSONObject(it).optLong("utcOffset").toDouble())
.build() .build()
} }
mainHandler.post { view.showMemberList(dataSet) } mainHandler.post { view.showMemberList(dataSet, jSONObject.get("total").toString()) }
} else { } else {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, response.message())) } mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, response.message())) }
} }
} }
}) })
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment