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
f1b43573
Commit
f1b43573
authored
Mar 14, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request to run commands if message starts with "/"
parent
0d49577b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+30
-0
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+5
-1
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
f1b43573
...
@@ -24,6 +24,7 @@ import chat.rocket.common.model.roomTypeOf
...
@@ -24,6 +24,7 @@ import chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.internal.realtime.State
import
chat.rocket.core.internal.realtime.State
import
chat.rocket.core.internal.rest.*
import
chat.rocket.core.internal.rest.*
import
chat.rocket.core.model.Command
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.Value
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.CommonPool
...
@@ -504,6 +505,35 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -504,6 +505,35 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
}
}
fun
runCommand
(
text
:
String
,
roomId
:
String
)
{
launchUI
(
strategy
)
{
try
{
if
(
text
.
length
==
1
)
{
// we have just the slash, post it anyway
sendMessage
(
roomId
,
text
,
null
)
}
else
{
val
command
=
text
.
split
(
" "
)
val
name
=
command
[
0
].
substring
(
1
)
var
params
:
String
=
""
command
.
forEachIndexed
{
index
,
param
->
if
(
index
>
0
)
{
params
+=
"$param "
}
}
val
result
=
client
.
runCommand
(
Command
(
name
,
params
),
roomId
)
if
(!
result
)
{
// failed, command is not valid so post it
sendMessage
(
roomId
,
text
,
null
)
}
}
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
// command is not valid, post it
sendMessage
(
roomId
,
text
,
null
)
}
}
}
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
)
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
)
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
f1b43573
...
@@ -216,7 +216,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
...
@@ -216,7 +216,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override
fun
sendMessage
(
text
:
String
)
{
override
fun
sendMessage
(
text
:
String
)
{
if
(!
text
.
isBlank
())
{
if
(!
text
.
isBlank
())
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
if
(!
text
.
startsWith
(
"/"
))
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
else
{
presenter
.
runCommand
(
text
,
chatRoomId
)
}
}
}
}
}
...
...
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