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
e318f11d
Unverified
Commit
e318f11d
authored
May 14, 2019
by
Hussein El Feky
Committed by
GitHub
May 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into language-setter
parents
87722d94
1089435c
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 @
e318f11d
...
@@ -124,6 +124,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -124,6 +124,7 @@ class ChatRoomPresenter @Inject constructor(
private
var
lastState
=
manager
.
state
private
var
lastState
=
manager
.
state
private
var
typingStatusList
=
arrayListOf
<
String
>()
private
var
typingStatusList
=
arrayListOf
<
String
>()
private
val
roomChangesChannel
=
Channel
<
Room
>(
Channel
.
CONFLATED
)
private
val
roomChangesChannel
=
Channel
<
Room
>(
Channel
.
CONFLATED
)
private
var
lastMessageId
:
String
?
=
null
private
lateinit
var
draftKey
:
String
private
lateinit
var
draftKey
:
String
fun
setupChatRoom
(
fun
setupChatRoom
(
...
@@ -223,6 +224,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -223,6 +224,7 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
)
)
lastMessageId
=
localMessages
.
firstOrNull
()
?.
id
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
view
.
showMessages
(
oldMessages
,
clearDataSet
)
view
.
showMessages
(
oldMessages
,
clearDataSet
)
...
@@ -235,7 +237,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -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)
// 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
)
markRoomAsRead
(
chatRoomId
)
subscribeMessages
(
chatRoomId
)
subscribeMessages
(
chatRoomId
)
...
@@ -371,6 +373,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -371,6 +373,7 @@ class ChatRoomPresenter @Inject constructor(
throw
ex
throw
ex
}
}
}
}
lastMessageId
=
id
}
else
{
}
else
{
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
}
}
...
@@ -1089,6 +1092,31 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -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
()
{
private
fun
logReactionEvent
()
{
when
{
when
{
roomTypeOf
(
chatRoomType
)
is
RoomType
.
DirectMessage
->
roomTypeOf
(
chatRoomType
)
is
RoomType
.
DirectMessage
->
...
@@ -1162,18 +1190,19 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -1162,18 +1190,19 @@ class ChatRoomPresenter @Inject constructor(
sendMessage
(
roomId
,
text
,
null
)
sendMessage
(
roomId
,
text
,
null
)
}
else
{
}
else
{
view
.
disableSendMessageButton
()
view
.
disableSendMessageButton
()
val
command
=
text
.
split
(
" "
)
val
index
=
text
.
indexOf
(
" "
)
va
l
name
=
command
[
0
].
substring
(
1
)
va
r
name
=
""
var
params
=
""
var
params
=
""
command
.
forEachIndexed
{
index
,
param
->
if
(
index
>=
1
)
{
if
(
index
>
0
)
{
name
=
text
.
substring
(
1
,
index
)
params
+=
"$param "
params
=
text
.
substring
(
index
+
1
).
trim
()
}
}
}
val
result
=
retryIO
(
"runCommand($name, $params, $roomId)"
)
{
val
result
=
retryIO
(
"runCommand($name, $params, $roomId)"
)
{
client
.
runCommand
(
Command
(
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
// failed, command is not valid so post it
sendMessage
(
roomId
,
text
,
null
)
sendMessage
(
roomId
,
text
,
null
)
}
}
...
@@ -1251,8 +1280,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -1251,8 +1280,8 @@ class ChatRoomPresenter @Inject constructor(
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
map
(
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
,
RoomUiModel
(
streamedMessage
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
)
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
...
@@ -1286,6 +1315,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -1286,6 +1315,7 @@ class ChatRoomPresenter @Inject constructor(
fun
clearDraftMessage
()
{
fun
clearDraftMessage
()
{
localRepository
.
clear
(
draftKey
)
localRepository
.
clear
(
draftKey
)
}
}
/**
/**
* Get unfinished message from local repository, when user left chat room without
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
* sending a message and now the user is back.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
e318f11d
...
@@ -148,10 +148,14 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
...
@@ -148,10 +148,14 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
,
EmojiKeyboardListener
,
EmojiReactionListener
,
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
,
EmojiKeyboardListener
,
EmojiReactionListener
,
ChatRoomAdapter
.
OnActionSelected
,
Drawable
.
Callback
{
ChatRoomAdapter
.
OnActionSelected
,
Drawable
.
Callback
{
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
@Inject
lateinit
var
parser
:
MessageParser
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
lateinit
var
parser
:
MessageParser
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
private
lateinit
var
adapter
:
ChatRoomAdapter
private
lateinit
var
adapter
:
ChatRoomAdapter
internal
lateinit
var
chatRoomId
:
String
internal
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomName
:
String
...
@@ -472,14 +476,15 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
...
@@ -472,14 +476,15 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
}
}
override
fun
sendMessage
(
text
:
String
)
{
override
fun
sendMessage
(
text
:
String
)
{
ui
{
ui
{
if
(!
text
.
isBlank
())
{
if
(!
text
.
isBlank
())
{
if
(!
text
.
startsWith
(
"/"
))
{
if
(
text
.
startsWith
(
"/"
))
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
else
{
presenter
.
runCommand
(
text
,
chatRoomId
)
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
...
@@ -524,7 +529,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
}
}
override
fun
clearMessageComposition
(
deleteMessage
:
Boolean
)
{
override
fun
clearMessageComposition
(
deleteMessage
:
Boolean
)
{
ui
{
ui
{
citation
=
null
citation
=
null
...
@@ -896,7 +900,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
...
@@ -896,7 +900,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_take_a_photo
.
setOnClickListener
{
button_take_a_photo
.
setOnClickListener
{
// Check for camera permission
// Check for camera permission
context
?.
let
{
context
?.
let
{
if
(
hasCameraPermission
(
it
))
{
if
(
hasCameraPermission
(
it
))
{
dispatchTakePictureIntent
()
dispatchTakePictureIntent
()
}
else
{
}
else
{
getCameraPermission
(
this
)
getCameraPermission
(
this
)
...
@@ -964,7 +968,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
...
@@ -964,7 +968,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
grantResults
:
IntArray
grantResults
:
IntArray
)
{
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
)
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
)
when
(
requestCode
)
{
when
(
requestCode
)
{
AndroidPermissionsHelper
.
CAMERA_CODE
->
{
AndroidPermissionsHelper
.
CAMERA_CODE
->
{
if
(
grantResults
.
isNotEmpty
()
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
grantResults
.
isNotEmpty
()
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
// permission was 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