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
1089435c
Unverified
Commit
1089435c
authored
May 13, 2019
by
Filipe Brito
Committed by
GitHub
May 13, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2271 from HusseinElFeky/emoji-react
[NEW] Typing +:emoji_name: reacts to last message
parents
da53bc60
b3a4c770
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
21 deletions
+55
-21
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+40
-10
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+15
-11
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
1089435c
...
...
@@ -124,6 +124,7 @@ class ChatRoomPresenter @Inject constructor(
private
var
lastState
=
manager
.
state
private
var
typingStatusList
=
arrayListOf
<
String
>()
private
val
roomChangesChannel
=
Channel
<
Room
>(
Channel
.
CONFLATED
)
private
var
lastMessageId
:
String
?
=
null
private
lateinit
var
draftKey
:
String
fun
setupChatRoom
(
...
...
@@ -223,6 +224,7 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
lastMessageId
=
localMessages
.
firstOrNull
()
?.
id
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
view
.
showMessages
(
oldMessages
,
clearDataSet
)
...
...
@@ -235,7 +237,7 @@ class ChatRoomPresenter @Inject constructor(
}
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
// but should mark only when the user see the first unread message.
// but should mark only when the user see
s
the first unread message.
markRoomAsRead
(
chatRoomId
)
subscribeMessages
(
chatRoomId
)
...
...
@@ -371,6 +373,7 @@ class ChatRoomPresenter @Inject constructor(
throw
ex
}
}
lastMessageId
=
id
}
else
{
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
}
...
...
@@ -1089,6 +1092,31 @@ class ChatRoomPresenter @Inject constructor(
}
}
fun
reactToLastMessage
(
text
:
String
,
roomId
:
String
)
{
launchUI
(
strategy
)
{
lastMessageId
?.
let
{
messageId
->
val
emoji
=
text
.
substring
(
1
).
trimEnd
()
if
(
emoji
.
length
>=
2
&&
emoji
.
startsWith
(
":"
)
&&
emoji
.
endsWith
(
":"
))
{
try
{
retryIO
(
"toggleEmoji($messageId, $emoji)"
)
{
client
.
toggleReaction
(
messageId
,
emoji
.
removeSurrounding
(
":"
))
}
logReactionEvent
()
view
.
clearMessageComposition
(
true
)
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
// emoji is not valid, post it
sendMessage
(
roomId
,
text
,
null
)
}
}
else
{
sendMessage
(
roomId
,
text
,
null
)
}
}.
ifNull
{
sendMessage
(
roomId
,
text
,
null
)
}
}
}
private
fun
logReactionEvent
()
{
when
{
roomTypeOf
(
chatRoomType
)
is
RoomType
.
DirectMessage
->
...
...
@@ -1162,18 +1190,19 @@ class ChatRoomPresenter @Inject constructor(
sendMessage
(
roomId
,
text
,
null
)
}
else
{
view
.
disableSendMessageButton
()
val
command
=
text
.
split
(
" "
)
va
l
name
=
command
[
0
].
substring
(
1
)
val
index
=
text
.
indexOf
(
" "
)
va
r
name
=
""
var
params
=
""
command
.
forEachIndexed
{
index
,
param
->
if
(
index
>
0
)
{
params
+=
"$param "
}
if
(
index
>=
1
)
{
name
=
text
.
substring
(
1
,
index
)
params
=
text
.
substring
(
index
+
1
).
trim
()
}
val
result
=
retryIO
(
"runCommand($name, $params, $roomId)"
)
{
client
.
runCommand
(
Command
(
name
,
params
),
roomId
)
}
if
(!
result
)
{
if
(
result
)
{
view
.
clearMessageComposition
(
true
)
}
else
{
// failed, command is not valid so post it
sendMessage
(
roomId
,
text
,
null
)
}
...
...
@@ -1251,8 +1280,8 @@ class ChatRoomPresenter @Inject constructor(
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
...
...
@@ -1286,6 +1315,7 @@ class ChatRoomPresenter @Inject constructor(
fun
clearDraftMessage
()
{
localRepository
.
clear
(
draftKey
)
}
/**
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
1089435c
...
...
@@ -148,10 +148,14 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
,
EmojiKeyboardListener
,
EmojiReactionListener
,
ChatRoomAdapter
.
OnActionSelected
,
Drawable
.
Callback
{
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
parser
:
MessageParser
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
parser
:
MessageParser
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
private
lateinit
var
adapter
:
ChatRoomAdapter
internal
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomName
:
String
...
...
@@ -472,14 +476,15 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override
fun
sendMessage
(
text
:
String
)
{
ui
{
if
(!
text
.
isBlank
())
{
if
(!
text
.
startsWith
(
"/"
))
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
else
{
if
(
text
.
startsWith
(
"/"
))
{
presenter
.
runCommand
(
text
,
chatRoomId
)
}
else
if
(
text
.
startsWith
(
"+"
))
{
presenter
.
reactToLastMessage
(
text
,
chatRoomId
)
}
else
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
}
}
...
...
@@ -524,7 +529,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override
fun
clearMessageComposition
(
deleteMessage
:
Boolean
)
{
ui
{
citation
=
null
...
...
@@ -896,7 +900,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_take_a_photo
.
setOnClickListener
{
// Check for camera permission
context
?.
let
{
if
(
hasCameraPermission
(
it
))
{
if
(
hasCameraPermission
(
it
))
{
dispatchTakePictureIntent
()
}
else
{
getCameraPermission
(
this
)
...
...
@@ -964,7 +968,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
grantResults
:
IntArray
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
)
when
(
requestCode
)
{
when
(
requestCode
)
{
AndroidPermissionsHelper
.
CAMERA_CODE
->
{
if
(
grantResults
.
isNotEmpty
()
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
// permission was granted
...
...
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