Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
12f1f054
Commit
12f1f054
authored
Sep 14, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RoomDialogPresenter.kt
parent
566da739
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
10 deletions
+136
-10
RoomDialogPresenter.kt
...t/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
+136
-10
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
View file @
12f1f054
...
@@ -12,12 +12,10 @@ import okhttp3.HttpUrl
...
@@ -12,12 +12,10 @@ import okhttp3.HttpUrl
import
org.json.JSONArray
import
org.json.JSONArray
import
org.json.JSONObject
import
org.json.JSONObject
class
RoomDialogPresenter
(
val
context
:
Context
,
val
view
:
RoomDialogContract
.
View
):
RoomDialogContract
.
Presenter
{
class
RoomDialogPresenter
(
val
context
:
Context
,
val
view
:
RoomDialogContract
.
View
):
RoomDialogContract
.
Presenter
{
val
mainHandler
=
Handler
(
context
.
mainLooper
)
val
mainHandler
=
Handler
(
context
.
mainLooper
)
override
fun
getDataSet
(
roomId
:
String
,
override
fun
getDataSet
(
roomId
:
String
,
roomName
:
String
,
roomType
:
String
,
roomType
:
String
,
hostname
:
String
,
hostname
:
String
,
token
:
String
,
token
:
String
,
...
@@ -60,8 +58,28 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -60,8 +58,28 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
hostname
:
String
,
hostname
:
String
,
token
:
String
,
token
:
String
,
userId
:
String
)
{
userId
:
String
)
{
// TODO("not implemented")
OkHttpHelper
.
getClient
()
.
newCall
(
getRequestForPinnedMessages
(
roomId
,
roomType
,
hostname
,
token
,
userId
))
.
enqueue
(
object
:
Callback
{
override
fun
onFailure
(
call
:
Call
,
e
:
IOException
)
{
view
.
showMessage
(
e
.
printStackTrace
().
toString
())
}
@Throws
(
IOException
::
class
)
override
fun
onResponse
(
call
:
Call
,
response
:
Response
)
{
if
(
response
.
isSuccessful
)
{
val
jSONObject
=
JSONObject
(
response
.
body
()
?.
string
())
Log
.
i
(
"REST"
,
"= "
+
jSONObject
)
}
else
{
// TODO("move to strings.xml")
view
.
showMessage
(
"Response is not successful"
)
}
}
})
}
}
private
fun
getFavoriteMessages
(
roomId
:
String
,
private
fun
getFavoriteMessages
(
roomId
:
String
,
...
@@ -69,8 +87,28 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -69,8 +87,28 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
hostname
:
String
,
hostname
:
String
,
token
:
String
,
token
:
String
,
userId
:
String
)
{
userId
:
String
)
{
// TODO("not implemented")
OkHttpHelper
.
getClient
()
.
newCall
(
getRequestForFavoriteMessages
(
roomId
,
roomType
,
hostname
,
token
,
userId
))
.
enqueue
(
object
:
Callback
{
override
fun
onFailure
(
call
:
Call
,
e
:
IOException
)
{
view
.
showMessage
(
e
.
printStackTrace
().
toString
())
}
@Throws
(
IOException
::
class
)
override
fun
onResponse
(
call
:
Call
,
response
:
Response
)
{
if
(
response
.
isSuccessful
)
{
val
jSONObject
=
JSONObject
(
response
.
body
()
?.
string
())
Log
.
i
(
"REST"
,
"= "
+
jSONObject
)
}
else
{
// TODO("move to strings.xml")
view
.
showMessage
(
"Response is not successful"
)
}
}
})
}
}
private
fun
getFileList
(
roomId
:
String
,
private
fun
getFileList
(
roomId
:
String
,
...
@@ -139,6 +177,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -139,6 +177,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
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
(
"REST"
,
"= "
+
jSONObject
)
val
membersJSONArray
=
jSONObject
.
get
(
"members"
)
as
JSONArray
val
membersJSONArray
=
jSONObject
.
get
(
"members"
)
as
JSONArray
...
@@ -155,6 +194,64 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -155,6 +194,64 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
})
})
}
}
/**
* Returns an OkHttp3 request for pinned messages list accordingly with the room type.
*
* @param roomId The ID of the room.
* @param roomType The type of the room.
* @param hostname The server hostname.
* @param token The token.
* @param userId The user Id.
* @return A OkHttp3 request.
*/
private
fun
getRequestForPinnedMessages
(
roomId
:
String
,
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
):
Request
{
val
parsedHttpUrl
=
HttpUrl
.
parse
(
getEndpointUrlForMessages
(
roomType
,
hostname
))
?.
newBuilder
()
?.
addQueryParameter
(
"roomId"
,
roomId
)
?.
addQueryParameter
(
"query"
,
"{\"pinned\":true}"
)
?.
build
()
return
Request
.
Builder
()
.
url
(
parsedHttpUrl
)
.
get
()
.
addHeader
(
"X-Auth-Token"
,
token
)
.
addHeader
(
"X-User-Id"
,
userId
)
.
build
()
}
/**
* Returns an OkHttp3 request for favorite messages list accordingly with the room type.
*
* @param roomId The ID of the room.
* @param roomType The type of the room.
* @param hostname The server hostname.
* @param token The token.
* @param userId The user Id.
* @return A OkHttp3 request.
*/
private
fun
getRequestForFavoriteMessages
(
roomId
:
String
,
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
):
Request
{
val
parsedHttpUrl
=
HttpUrl
.
parse
(
getEndpointUrlForMessages
(
roomType
,
hostname
))
?.
newBuilder
()
?.
addQueryParameter
(
"roomId"
,
roomId
)
?.
addQueryParameter
(
"query"
,
"{\"starred._id\":{\"\$in\":[\"$userId\"] } }"
)
?.
build
()
return
Request
.
Builder
()
.
url
(
parsedHttpUrl
)
.
get
()
.
addHeader
(
"X-Auth-Token"
,
token
)
.
addHeader
(
"X-User-Id"
,
userId
)
.
build
()
}
/**
/**
* Returns an OkHttp3 request for file list accordingly with the room type.
* Returns an OkHttp3 request for file list accordingly with the room type.
*
*
...
@@ -211,6 +308,18 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -211,6 +308,18 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
.
build
()
.
build
()
}
}
/**
* Returns a Rest API endpoint URL for favorite or pinned messages accordingly with the room type.
*
* @param roomType The type of the room.
* @param hostname The server hostname.
* @return A Rest API URL endpoint.
*/
private
fun
getEndpointUrlForMessages
(
roomType
:
String
,
hostname
:
String
):
String
=
"https://"
+
hostname
.
replace
(
"http://"
,
""
).
replace
(
"https://"
,
""
)
+
getRestApiUrlForMessages
(
roomType
)
/**
/**
* Returns a Rest API endpoint URL for member list accordingly with the room type.
* Returns a Rest API endpoint URL for member list accordingly with the room type.
*
*
...
@@ -233,21 +342,20 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -233,21 +342,20 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
hostname
.
replace
(
"http://"
,
""
).
replace
(
"https://"
,
""
)
+
hostname
.
replace
(
"http://"
,
""
).
replace
(
"https://"
,
""
)
+
getRestApiUrlForFileList
(
roomType
)
getRestApiUrlForFileList
(
roomType
)
/**
/**
* Returns the correspondent Rest API URL accordingly with the room type to get its
members list
.
* Returns the correspondent Rest API URL accordingly with the room type to get its
favorite or pinned messages
.
*
*
* REMARK: To see all the REST API calls take a look at https://rocket.chat/docs/developer-guides/rest-api/.
* REMARK: To see all the REST API calls take a look at https://rocket.chat/docs/developer-guides/rest-api/.
*
*
* @param roomType The type of the room.
* @param roomType The type of the room.
* @return A Rest API URL or null if the room type does not match.
* @return A Rest API URL or null if the room type does not match.
*/
*/
private
fun
getRestApiUrlForMe
mberList
(
roomType
:
String
):
String
?
{
private
fun
getRestApiUrlForMe
ssages
(
roomType
:
String
):
String
?
{
var
restApiUrl
:
String
?
=
null
var
restApiUrl
:
String
?
=
null
when
(
roomType
)
{
when
(
roomType
)
{
Room
.
TYPE_CHANNEL
->
restApiUrl
=
"/api/v1/channels.me
mber
s"
Room
.
TYPE_CHANNEL
->
restApiUrl
=
"/api/v1/channels.me
ssage
s"
Room
.
TYPE_PRIVATE
->
restApiUrl
=
"/api/v1/groups.me
mber
s"
Room
.
TYPE_PRIVATE
->
restApiUrl
=
"/api/v1/groups.me
ssage
s"
Room
.
TYPE_DIRECT_MESSAGE
->
restApiUrl
=
"/api/v1/dm.me
mber
s"
Room
.
TYPE_DIRECT_MESSAGE
->
restApiUrl
=
"/api/v1/dm.me
ssage
s"
}
}
return
restApiUrl
return
restApiUrl
}
}
...
@@ -269,4 +377,22 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -269,4 +377,22 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
}
}
return
restApiUrl
return
restApiUrl
}
}
/**
* Returns the correspondent Rest API URL accordingly with the room type to get its members list.
*
* REMARK: To see all the REST API calls take a look at https://rocket.chat/docs/developer-guides/rest-api/.
*
* @param roomType The type of the room.
* @return A Rest API URL or null if the room type does not match.
*/
private
fun
getRestApiUrlForMemberList
(
roomType
:
String
):
String
?
{
var
restApiUrl
:
String
?
=
null
when
(
roomType
)
{
Room
.
TYPE_CHANNEL
->
restApiUrl
=
"/api/v1/channels.members"
Room
.
TYPE_PRIVATE
->
restApiUrl
=
"/api/v1/groups.members"
Room
.
TYPE_DIRECT_MESSAGE
->
restApiUrl
=
"/api/v1/dm.members"
}
return
restApiUrl
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment