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
a395ec75
Commit
a395ec75
authored
Sep 13, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RoomDialogPresenter.kt
parent
ef2e045a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
149 additions
and
0 deletions
+149
-0
RoomDialogPresenter.kt
...t/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
+149
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
0 → 100644
View file @
a395ec75
package
chat.rocket.android.fragment.chatroom.dialog
import
android.content.Context
import
android.util.Log
import
chat.rocket.android.R
import
chat.rocket.android.helper.OkHttpHelper
import
chat.rocket.core.models.Room
import
okhttp3.*
import
java.io.IOException
class
RoomDialogPresenter
(
val
context
:
Context
,
val
view
:
RoomDialogContract
.
View
):
RoomDialogContract
.
Presenter
{
override
fun
getDataSet
(
roomId
:
String
,
roomName
:
String
,
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
,
action
:
Int
)
{
when
(
action
)
{
R
.
id
.
action_pinned_messages
->
getPinnedMessages
(
roomType
,
hostname
,
token
,
userId
)
R
.
id
.
action_favorite_messages
->
getFavoriteMessages
(
roomType
,
hostname
,
token
,
userId
)
R
.
id
.
action_file_list
->
{
getFileList
(
roomId
,
roomType
,
hostname
,
token
,
userId
)
}
R
.
id
.
action_member_list
->
getMemberList
(
roomType
,
hostname
,
token
,
userId
)
}
}
private
fun
getPinnedMessages
(
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
)
{
view
.
showPinnedMessages
()
}
private
fun
getFavoriteMessages
(
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
)
{
view
.
showFavoriteMessages
()
}
private
fun
getFileList
(
roomId
:
String
,
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
)
{
OkHttpHelper
.
getClient
()
.
newCall
(
getRequest
(
roomId
,
roomType
,
hostname
,
token
,
userId
))
.
enqueue
(
object
:
Callback
{
override
fun
onFailure
(
call
:
Call
,
e
:
IOException
)
{
Log
.
i
(
"REST"
,
"FAIL = "
+
e
.
message
)
}
@Throws
(
IOException
::
class
)
override
fun
onResponse
(
call
:
Call
,
response
:
Response
)
{
Log
.
i
(
"REST"
,
"SUCCESS = "
+
response
.
body
()
?.
string
())
val
res
=
response
.
body
()
}
})
view
.
showFileList
()
}
private
fun
getMemberList
(
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
)
{
view
.
showMemberList
()
}
/**
* Returns an OkHttp3 request corresponding to the Rest API call.
*
* @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
getRequest
(
roomId
:
String
,
roomType
:
String
,
hostname
:
String
,
token
:
String
,
userId
:
String
):
Request
{
val
httpUrl
=
HttpUrl
.
Builder
()
.
scheme
(
"http"
)
.
host
(
getEndpointUrl
(
roomType
,
hostname
))
.
addQueryParameter
(
"roomId"
,
roomId
)
.
build
()
return
Request
.
Builder
()
.
url
(
httpUrl
)
.
get
()
.
addHeader
(
"X-Auth-Token"
,
token
)
.
addHeader
(
"X-User-Id"
,
userId
)
.
build
()
}
/**
* Returns an endpoint URL (without the https or http schemas) corresponding to the Rest API call.
*
* @param roomType The type of the room.
* @param hostname The server hostname.
* @return A Rest API URL endpoint starting with www.
*/
private
fun
getEndpointUrl
(
roomType
:
String
,
hostname
:
String
):
String
=
"www."
+
hostname
.
replace
(
"http://"
,
""
)
.
replace
(
"https://"
,
""
)
.
replace
(
"www"
,
""
)
+
getRestApiUrlForMemberList
(
roomType
)
/**
* 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
}
/**
* Returns the correspondent Rest API URL accordingly with the room type to get its file 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
getRestApiUrlForFileList
(
roomType
:
String
):
String
?
{
var
restApiUrl
:
String
?
=
null
when
(
roomType
)
{
Room
.
TYPE_CHANNEL
->
restApiUrl
=
"/api/v1/channels.files"
Room
.
TYPE_PRIVATE
->
restApiUrl
=
"/api/v1/groups.files"
Room
.
TYPE_DIRECT_MESSAGE
->
restApiUrl
=
"/api/v1/dm.files"
}
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