Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' into sb_add_user
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbrito authored Jun 21, 2019
2 parents 6c11033 + 99530b8 commit daaf213
Show file tree
Hide file tree
Showing 28 changed files with 620 additions and 306 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "chat.rocket.android"
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 2067
versionName "3.4.0"
versionCode 2070
versionName "3.4.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class LoginOptionsPresenter @Inject constructor(
)
localRepository.saveCurrentUser(url = currentServer, user = user)
saveCurrentServer.save(currentServer)
localRepository.save(LocalRepository.CURRENT_USERNAME_KEY, username)
saveAccount(username)
saveToken(token)
analyticsManager.logLogin(loginMethod, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import androidx.recyclerview.widget.RecyclerView
import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager
import chat.rocket.android.chatroom.presentation.ChatRoomNavigator
import chat.rocket.android.chatroom.ui.bottomsheet.COMPACT_CONFIGURATION
import chat.rocket.android.chatroom.ui.bottomsheet.FULL_CONFIGURATION
import chat.rocket.android.chatroom.ui.bottomsheet.TALL_CONFIGURATION
import chat.rocket.android.chatroom.uimodel.AttachmentUiModel
import chat.rocket.android.chatroom.uimodel.BaseUiModel
import chat.rocket.android.chatroom.uimodel.MessageReplyUiModel
Expand Down Expand Up @@ -179,7 +182,8 @@ class ChatRoomAdapter(
notifyDataSetChanged()
}

fun updateItem(message: BaseUiModel<*>): Boolean {
// FIXME What's 0,1 and 2 means for here?
fun updateItem(message: BaseUiModel<*>): Int {
val index = dataSet.indexOfLast { it.messageId == message.messageId }
val indexOfNext = dataSet.indexOfFirst { it.messageId == message.messageId }
Timber.d("index: $index")
Expand All @@ -190,17 +194,23 @@ class ChatRoomAdapter(
if (viewModel.nextDownStreamMessage == null) {
viewModel.reactions = message.reactions
}
notifyItemChanged(ind)

if (ind > 0 &&
dataSet[ind].message.timestamp > dataSet[ind - 1].message.timestamp) {
return 2
} else {
notifyItemChanged(ind)
}
}
}
// Delete message only if current is a system message update, i.e.: Message Removed
if (message.message.isSystemMessage() && indexOfNext > -1 && indexOfNext != index) {
dataSet.removeAt(indexOfNext)
notifyItemRemoved(indexOfNext)
}
return true
return 0
}
return false
return 1
}

fun removeItem(messageId: String) {
Expand All @@ -216,11 +226,18 @@ class ChatRoomAdapter(
}

private val actionAttachmentOnClickListener = object : ActionAttachmentOnClickListener {

override fun onActionClicked(view: View, action: Action) {
val temp = action as ButtonAction
if (temp.url != null && temp.isWebView != null) {
if (temp.isWebView == true) {
//TODO: Open in a configurable sizable webview
//Open in a configurable sizable WebView
when(temp.webViewHeightRatio){
FULL_CONFIGURATION -> openFullWebPage(temp, roomId)
COMPACT_CONFIGURATION -> openConfigurableWebPage(temp, roomId, FULL_CONFIGURATION)
TALL_CONFIGURATION -> openConfigurableWebPage(temp, roomId, TALL_CONFIGURATION)
else -> Unit
}
Timber.d("Open in a configurable sizable webview")
} else {
//Open in chrome custom tab
Expand All @@ -240,6 +257,22 @@ class ChatRoomAdapter(
}
}
}

private fun openConfigurableWebPage(temp: ButtonAction, roomId: String?, heightRatio: String) {
temp.url?.let {
if(roomId != null){
actionSelectListener?.openConfigurableWebPage(roomId, it, heightRatio)
}
}
}

private fun openFullWebPage(temp: ButtonAction, roomId: String?) {
temp.url?.let {
if(roomId != null){
actionSelectListener?.openFullWebPage(roomId, it)
}
}
}
}

private val actionsListener = object : BaseViewHolder.ActionsListener {
Expand Down Expand Up @@ -340,5 +373,9 @@ class ChatRoomAdapter(
fun copyPermalink(id: String)

fun reportMessage(id: String)

fun openFullWebPage(roomId: String, url: String)

fun openConfigurableWebPage(roomId: String, url: String, heightRatio: String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chat.rocket.android.R
import chat.rocket.android.chatdetails.ui.TAG_CHAT_DETAILS_FRAGMENT
import chat.rocket.android.chatinformation.ui.messageInformationIntent
import chat.rocket.android.chatroom.ui.ChatRoomActivity
import chat.rocket.android.chatroom.ui.bottomsheet.WebUrlBottomSheet
import chat.rocket.android.chatroom.ui.chatRoomIntent
import chat.rocket.android.favoritemessages.ui.TAG_FAVORITE_MESSAGES_FRAGMENT
import chat.rocket.android.files.ui.TAG_FILES_FRAGMENT
Expand All @@ -17,6 +18,7 @@ import chat.rocket.android.server.ui.changeServerIntent
import chat.rocket.android.userdetails.ui.TAG_USER_DETAILS_FRAGMENT
import chat.rocket.android.util.extensions.addFragmentBackStack
import chat.rocket.android.videoconference.ui.videoConferenceIntent
import chat.rocket.android.webview.ui.webViewIntent

class ChatRoomNavigator(internal val activity: ChatRoomActivity) {

Expand Down Expand Up @@ -160,4 +162,14 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
activity.startActivity(activity.messageInformationIntent(messageId = messageId))
activity.overridePendingTransition(R.anim.open_enter, R.anim.open_exit)
}

fun toFullWebPage(roomId: String, url: String) {
activity.startActivity(activity.webViewIntent(url,null))
activity.overridePendingTransition(R.anim.open_enter, R.anim.open_exit)
}

fun toConfigurableWebPage(roomId: String, url: String, heightRatio: String) {
val weburlbottomsheet = WebUrlBottomSheet.newInstance(url, roomId, heightRatio)
weburlbottomsheet.show(activity.supportFragmentManager, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ class ChatRoomPresenter @Inject constructor(
val id = UUID.randomUUID().toString()
val username = userHelper.username()
val user = userHelper.user()
val timestamp = maxOf(getTimeStampOfLastMessageInRoom() + 1,
Instant.now().toEpochMilli())
val newMessage = Message(
id = id,
roomId = chatRoomId,
message = text,
timestamp = Instant.now().toEpochMilli(),
timestamp = timestamp,
sender = SimpleUser(user?.id, user?.username ?: username, user?.name),
attachments = null,
avatar = currentServer.avatarUrl(
Expand Down Expand Up @@ -1101,9 +1103,13 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
} catch (ex: Exception) {
Timber.e(ex)
view.showMessage(ex.message!!)
} catch (exception: Exception) {
Timber.e(exception)
exception.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
Expand All @@ -1120,8 +1126,13 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
} catch (ex: Exception) {
Timber.e(ex)
} catch (exception: Exception) {
Timber.e(exception)
exception.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
Expand All @@ -1136,8 +1147,13 @@ class ChatRoomPresenter @Inject constructor(
client.toggleReaction(messageId, emoji.removeSurrounding(":"))
}
logReactionEvent()
} catch (ex: RocketChatException) {
Timber.e(ex)
} catch (exception: RocketChatException) {
Timber.e(exception)
exception.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
Expand Down Expand Up @@ -1375,4 +1391,20 @@ class ChatRoomPresenter @Inject constructor(
fun getDraftUnfinishedMessage(): String? {
return localRepository.get(draftKey)
}

private suspend fun getTimeStampOfLastMessageInRoom(): Long {
return withContext(Dispatchers.IO + strategy.jobs) {
chatRoomId?.let {
dbManager.messageDao().getRecentMessagesByRoomId(it, 1).first().message.message.timestamp
}
} ?: 0
}

fun openFullWebPage(roomId: String, url: String){
navigator.toFullWebPage(roomId, url)
}

fun openConfigurableWebPage(roomId: String, url: String, heightRatio: String){
navigator.toConfigurableWebPage(roomId, url, heightRatio)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
super.onPrepareOptionsMenu(menu)
}

override fun openFullWebPage(roomId: String, url: String) {
presenter.openFullWebPage(roomId, url)
}

override fun openConfigurableWebPage(roomId: String, url: String, heightRatio: String) {
presenter.openConfigurableWebPage(roomId, url, heightRatio)
}


override fun showMessages(dataSet: List<BaseUiModel<*>>, clearDataSet: Boolean) {
ui {
Expand Down Expand Up @@ -536,7 +544,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
if (newMessageCount <= 99) {
text_count.text = newMessageCount.toString()
} else {
text_count.text = "99+"
text_count.text = getString(R.string.msg_more_than_ninety_nine_unread_messages)
}
text_count.isVisible = true
} else if (!button_fab.isVisible) {
Expand All @@ -553,12 +561,22 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
// TODO - investigate WHY we get a empty list here
if (message.isEmpty()) return@ui

if (chatRoomAdapter.updateItem(message.last())) {
if (message.size > 1) {
chatRoomAdapter.prependData(listOf(message.first()))
when (chatRoomAdapter.updateItem(message.last())) {
// FIXME: What's 0,1 and 2 means for here?
0 -> {
if (message.size > 1) {
chatRoomAdapter.prependData(listOf(message.first()))
}
}
1 -> showNewMessage(message, true)
2 -> {
// Position of new sent message is wrong because of device local time is behind server time
with(chatRoomAdapter) {
removeItem(message.last().messageId)
prependData(listOf(message.last()))
notifyDataSetChanged()
}
}
} else {
showNewMessage(message, true)
}
dismissEmojiKeyboard()
}
Expand Down
Loading

0 comments on commit daaf213

Please sign in to comment.