1
0
mirror of https://github.com/nextcloud/talk-android synced 2025-07-12 07:14:05 +01:00

Various fix for crashes

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-09-30 14:15:01 +02:00
parent 79c8fe7387
commit f308a5093d
2 changed files with 321 additions and 276 deletions
app
build.gradle
src/main/java/com/nextcloud/talk/controllers

View File

@ -22,6 +22,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'findbugs' apply plugin: 'findbugs'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
def taskRequest = getGradle().getStartParameter().getTaskRequests().toString() def taskRequest = getGradle().getStartParameter().getTaskRequests().toString()
if (taskRequest.contains("Gplay") || taskRequest.contains("findbugs") || taskRequest.contains("lint")) { if (taskRequest.contains("Gplay") || taskRequest.contains("findbugs") || taskRequest.contains("lint")) {

View File

@ -111,31 +111,44 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
.OnMessageLongClickListener<IMessage>, MessageHolders.ContentChecker<IMessage> { .OnMessageLongClickListener<IMessage>, MessageHolders.ContentChecker<IMessage> {
@Inject @Inject
lateinit var ncApi: NcApi @JvmField
var ncApi: NcApi? = null
@Inject @Inject
lateinit var userUtils: UserUtils @JvmField
var userUtils: UserUtils? = null
@Inject @Inject
lateinit var appPreferences: AppPreferences @JvmField
var appPreferences: AppPreferences? = null
@Inject @Inject
lateinit var context: Context @JvmField
var context: Context? = null
@Inject @Inject
lateinit var eventBus: EventBus @JvmField
var eventBus: EventBus? = null
@BindView(R.id.messagesListView) @BindView(R.id.messagesListView)
lateinit var messagesListView: MessagesList @JvmField
var messagesListView: MessagesList? = null
@BindView(R.id.messageInputView) @BindView(R.id.messageInputView)
lateinit var messageInputView: MessageInput @JvmField
var messageInputView: MessageInput? = null
@BindView(R.id.messageInput) @BindView(R.id.messageInput)
lateinit var messageInput: EmojiEditText @JvmField
var messageInput: EmojiEditText? = null
@BindView(R.id.popupBubbleView) @BindView(R.id.popupBubbleView)
lateinit var popupBubble: PopupBubble @JvmField
var popupBubble: PopupBubble? = null
@BindView(R.id.progressBar) @BindView(R.id.progressBar)
lateinit var loadingProgressBar: ProgressBar @JvmField
var loadingProgressBar: ProgressBar? = null
@BindView(R.id.smileyButton) @BindView(R.id.smileyButton)
lateinit var smileyButton: ImageButton @JvmField
var smileyButton: ImageButton? = null
@BindView(R.id.lobby_view) @BindView(R.id.lobby_view)
lateinit var lobbyView: RelativeLayout @JvmField
var lobbyView: RelativeLayout? = null
@BindView(R.id.lobby_text_view) @BindView(R.id.lobby_text_view)
lateinit var conversationLobbyText: TextView @JvmField
var conversationLobbyText: TextView? = null
val disposableList = ArrayList<Disposable>() val disposableList = ArrayList<Disposable>()
var roomToken: String? = null var roomToken: String? = null
val conversationUser: UserEntity? val conversationUser: UserEntity?
@ -186,7 +199,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "") this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "")
if (conversationUser!!.userId == "?") { if (conversationUser?.userId == "?") {
credentials = null credentials = null
} else { } else {
credentials = ApiUtils.getCredentials(conversationUser.username, conversationUser.token) credentials = ApiUtils.getCredentials(conversationUser.username, conversationUser.token)
@ -200,15 +213,16 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun getRoomInfo() { private fun getRoomInfo() {
val shouldRepeat = conversationUser!!.hasSpreedFeatureCapability("webinary-lobby") val shouldRepeat = conversationUser?.hasSpreedFeatureCapability("webinary-lobby") ?: false
if (shouldRepeat) { if (shouldRepeat) {
checkingLobbyStatus = true checkingLobbyStatus = true
} }
ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.baseUrl, roomToken))
.subscribeOn(Schedulers.io()) if (conversationUser != null) {
.observeOn(AndroidSchedulers.mainThread()) ncApi?.getRoom(credentials, ApiUtils.getRoom(conversationUser.baseUrl, roomToken))?.subscribeOn(Schedulers.io())
.subscribe(object : Observer<RoomOverall> { ?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -239,17 +253,16 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
lobbyTimerHandler = Handler() lobbyTimerHandler = Handler()
} }
lobbyTimerHandler!!.postDelayed({ getRoomInfo() }, 5000) lobbyTimerHandler?.postDelayed({ getRoomInfo() }, 5000)
} }
} }
}) })
} }
}
private fun handleFromNotification() { private fun handleFromNotification() {
ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(conversationUser!!.baseUrl)) ncApi?.getRooms(credentials, ApiUtils.getUrlForGetRooms(conversationUser?.baseUrl))
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : Observer<RoomsOverall> {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<RoomsOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -281,13 +294,14 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun loadAvatarForStatusBar() { private fun loadAvatarForStatusBar() {
if (currentConversation != null && currentConversation!!.type != null && if (currentConversation != null && currentConversation?.type != null &&
currentConversation!!.type == Conversation.ConversationType currentConversation?.type == Conversation.ConversationType
.ROOM_TYPE_ONE_TO_ONE_CALL && activity != null && conversationVoiceCallMenuItem != null) { .ROOM_TYPE_ONE_TO_ONE_CALL && activity != null && conversationVoiceCallMenuItem != null) {
val avatarSize = DisplayUtils.convertDpToPixel(conversationVoiceCallMenuItem!!.icon.intrinsicWidth.toFloat(), activity!!).toInt() val avatarSize = DisplayUtils.convertDpToPixel(conversationVoiceCallMenuItem?.icon!!
.intrinsicWidth.toFloat(), activity).toInt()
val imageRequest = DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithNameAndPixels(conversationUser!!.baseUrl, val imageRequest = DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithNameAndPixels(conversationUser?.baseUrl,
currentConversation!!.name, avatarSize / 2), null) currentConversation?.name, avatarSize / 2), null)
val imagePipeline = Fresco.getImagePipeline() val imagePipeline = Fresco.getImagePipeline()
val dataSource = imagePipeline.fetchDecodedImage(imageRequest, null) val dataSource = imagePipeline.fetchDecodedImage(imageRequest, null)
@ -298,7 +312,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmap) val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmap)
roundedBitmapDrawable.isCircular = true roundedBitmapDrawable.isCircular = true
roundedBitmapDrawable.setAntiAlias(true) roundedBitmapDrawable.setAntiAlias(true)
actionBar!!.setIcon(roundedBitmapDrawable) actionBar?.setIcon(roundedBitmapDrawable)
} }
} }
@ -310,11 +324,11 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onViewBound(view: View) { override fun onViewBound(view: View) {
super.onViewBound(view) super.onViewBound(view)
actionBar!!.show() actionBar?.show()
var adapterWasNull = false var adapterWasNull = false
if (adapter == null) { if (adapter == null) {
loadingProgressBar!!.visibility = View.VISIBLE loadingProgressBar?.visibility = View.VISIBLE
adapterWasNull = true adapterWasNull = true
@ -333,7 +347,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
MagicUnreadNoticeMessageViewHolder::class.java, R.layout.item_date_header, MagicUnreadNoticeMessageViewHolder::class.java, R.layout.item_date_header,
MagicUnreadNoticeMessageViewHolder::class.java, R.layout.item_date_header, this) MagicUnreadNoticeMessageViewHolder::class.java, R.layout.item_date_header, this)
adapter = MessagesListAdapter(conversationUser!!.userId, messageHolders, ImageLoader { imageView, url, payload -> adapter = MessagesListAdapter(conversationUser?.userId, messageHolders, ImageLoader { imageView, url, payload ->
val draweeController = Fresco.newDraweeControllerBuilder() val draweeController = Fresco.newDraweeControllerBuilder()
.setImageRequest(DisplayUtils.getImageRequestForUrl(url, conversationUser)) .setImageRequest(DisplayUtils.getImageRequestForUrl(url, conversationUser))
.setControllerListener(DisplayUtils.getImageControllerListener(imageView)) .setControllerListener(DisplayUtils.getImageControllerListener(imageView))
@ -343,19 +357,19 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
imageView.controller = draweeController imageView.controller = draweeController
}) })
} else { } else {
messagesListView.visibility = View.VISIBLE messagesListView?.visibility = View.VISIBLE
} }
messagesListView.setAdapter(adapter) messagesListView?.setAdapter(adapter)
adapter!!.setLoadMoreListener(this) adapter?.setLoadMoreListener(this)
adapter!!.setDateHeadersFormatter { format(it) } adapter?.setDateHeadersFormatter { format(it) }
adapter!!.setOnMessageLongClickListener { onMessageLongClick(it) } adapter?.setOnMessageLongClickListener { onMessageLongClick(it) }
layoutManager = messagesListView.layoutManager as LinearLayoutManager? layoutManager = messagesListView?.layoutManager as LinearLayoutManager?
popupBubble.setRecyclerView(messagesListView) popupBubble?.setRecyclerView(messagesListView)
popupBubble.setPopupBubbleListener { context -> popupBubble?.setPopupBubbleListener { context ->
if (newMessagesCount != 0) { if (newMessagesCount != 0) {
val scrollPosition: Int val scrollPosition: Int
if (newMessagesCount - 1 < 0) { if (newMessagesCount - 1 < 0) {
@ -363,21 +377,22 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} else { } else {
scrollPosition = newMessagesCount - 1 scrollPosition = newMessagesCount - 1
} }
Handler().postDelayed({ messagesListView.smoothScrollToPosition(scrollPosition) }, 200) Handler().postDelayed({ messagesListView?.smoothScrollToPosition(scrollPosition) }, 200)
} }
} }
messagesListView.addOnScrollListener(object : RecyclerView.OnScrollListener() { messagesListView?.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
if (newMessagesCount != 0) { if (newMessagesCount != 0 && layoutManager != null) {
if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) { if (layoutManager!!.findFirstCompletelyVisibleItemPosition() <
newMessagesCount) {
newMessagesCount = 0 newMessagesCount = 0
if (popupBubble.isShown) { if (popupBubble != null && popupBubble!!.isShown) {
popupBubble.hide() popupBubble?.hide()
} }
} }
} }
@ -387,26 +402,28 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
val filters = arrayOfNulls<InputFilter>(1) val filters = arrayOfNulls<InputFilter>(1)
val lengthFilter = conversationUser!!.messageMaxLength val lengthFilter = conversationUser?.messageMaxLength ?: 1000
filters[0] = InputFilter.LengthFilter(lengthFilter) filters[0] = InputFilter.LengthFilter(lengthFilter)
messageInput.filters = filters messageInput?.filters = filters
messageInput.addTextChangedListener(object : TextWatcher { messageInput?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
} }
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.length >= lengthFilter) { if (s.length >= lengthFilter) {
messageInput.error = String.format(Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit), Integer.toString(lengthFilter)) messageInput?.error = String.format(Objects.requireNonNull<Resources>
(resources).getString(R.string.nc_limit_hit), Integer.toString(lengthFilter))
} else { } else {
messageInput.error = null messageInput?.error = null
} }
val editable = messageInput.editableText val editable = messageInput?.editableText
val mentionSpans = editable.getSpans(0, messageInput.length(), if (editable != null && messageInput != null) {
val mentionSpans = editable.getSpans(0, messageInput!!.length(),
Spans.MentionChipSpan::class.java) Spans.MentionChipSpan::class.java)
var mentionSpan: Spans.MentionChipSpan var mentionSpan: Spans.MentionChipSpan
for (i in mentionSpans.indices) { for (i in mentionSpans.indices) {
@ -419,19 +436,24 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
} }
} }
}
override fun afterTextChanged(s: Editable) { override fun afterTextChanged(s: Editable) {
} }
}) })
messageInputView.setAttachmentsListener { showBrowserScreen(BrowserController.BrowserType.DAV_BROWSER) } messageInputView?.setAttachmentsListener {
showBrowserScreen(BrowserController
.BrowserType.DAV_BROWSER)
}
messageInputView.button.setOnClickListener { v -> submitMessage() } messageInputView?.button?.setOnClickListener { v -> submitMessage() }
messageInputView.button.contentDescription = resources!!
.getString(R.string.nc_description_send_message_button)
if (currentConversation != null && currentConversation!!.roomId != null) { messageInputView?.button?.contentDescription = resources?.getString(R.string
.nc_description_send_message_button)
if (currentConversation != null && currentConversation?.roomId != null) {
loadAvatarForStatusBar() loadAvatarForStatusBar()
checkLobbyState() checkLobbyState()
setTitle() setTitle()
@ -450,62 +472,60 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
private fun checkReadOnlyState() { private fun checkReadOnlyState() {
if (currentConversation != null) { if (currentConversation != null) {
if (currentConversation!!.shouldShowLobby(conversationUser) || currentConversation!! if (currentConversation?.shouldShowLobby(conversationUser)?: false || currentConversation?.conversationReadOnlyState != null && currentConversation?.conversationReadOnlyState == Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY) {
.conversationReadOnlyState != null && currentConversation!!.conversationReadOnlyState
== Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY) {
conversationVoiceCallMenuItem!!.icon.alpha = 99 conversationVoiceCallMenuItem?.icon?.alpha = 99
conversationVideoMenuItem!!.icon.alpha = 99 conversationVideoMenuItem?.icon?.alpha = 99
messageInputView.visibility = View.GONE messageInputView?.visibility = View.GONE
} else { } else {
if (conversationVoiceCallMenuItem != null) { if (conversationVoiceCallMenuItem != null) {
conversationVoiceCallMenuItem!!.icon.alpha = 255 conversationVoiceCallMenuItem?.icon?.alpha = 255
} }
if (conversationVideoMenuItem != null) { if (conversationVideoMenuItem != null) {
conversationVideoMenuItem!!.icon.alpha = 255 conversationVideoMenuItem?.icon?.alpha = 255
} }
if (currentConversation!!.shouldShowLobby(conversationUser)) { if (currentConversation != null && currentConversation!!.shouldShowLobby
messageInputView.visibility = View.GONE (conversationUser)) {
messageInputView?.visibility = View.GONE
} else { } else {
messageInputView.visibility = View.VISIBLE messageInputView?.visibility = View.VISIBLE
} }
} }
} }
} }
private fun checkLobbyState() { private fun checkLobbyState() {
if (currentConversation != null && currentConversation!!.isLobbyViewApplicable(conversationUser)) { if (currentConversation != null && currentConversation?.isLobbyViewApplicable(conversationUser) ?: false) {
if (!checkingLobbyStatus) { if (!checkingLobbyStatus) {
getRoomInfo() getRoomInfo()
} }
if (currentConversation!!.shouldShowLobby(conversationUser)) { if (currentConversation?.shouldShowLobby(conversationUser) ?: false) {
lobbyView.visibility = View.VISIBLE lobbyView?.visibility = View.VISIBLE
messagesListView.visibility = View.GONE messagesListView?.visibility = View.GONE
messageInputView.visibility = View.GONE messageInputView?.visibility = View.GONE
loadingProgressBar.visibility = View.GONE loadingProgressBar?.visibility = View.GONE
if (currentConversation!!.lobbyTimer != null && currentConversation!!.lobbyTimer != if (currentConversation?.lobbyTimer != null && currentConversation?.lobbyTimer !=
0L) { 0L) {
conversationLobbyText.text = String.format(resources!!.getString(R.string conversationLobbyText?.text = String.format(resources!!.getString(R.string.nc_lobby_waiting_with_date), DateUtils.getLocalDateStringFromTimestampForLobby(currentConversation?.lobbyTimer
.nc_lobby_waiting_with_date), DateUtils ?: 0))
.getLocalDateStringFromTimestampForLobby(currentConversation!!.lobbyTimer!!))
} else { } else {
conversationLobbyText.setText(R.string.nc_lobby_waiting) conversationLobbyText?.setText(R.string.nc_lobby_waiting)
} }
} else { } else {
lobbyView.visibility = View.GONE lobbyView?.visibility = View.GONE
messagesListView.visibility = View.VISIBLE messagesListView?.visibility = View.VISIBLE
messageInput.visibility = View.VISIBLE messageInput?.visibility = View.VISIBLE
} }
} else { } else {
lobbyView.visibility = View.GONE lobbyView?.visibility = View.GONE
messagesListView.visibility = View.VISIBLE messagesListView?.visibility = View.VISIBLE
messageInput.visibility = View.VISIBLE messageInput?.visibility = View.VISIBLE
} }
} }
@ -548,10 +568,12 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(view) super.onAttach(view)
eventBus!!.register(this) eventBus?.register(this)
if (conversationUser!!.userId != "?" && conversationUser.hasSpreedFeatureCapability("mention-flag") && activity != null) { if (conversationUser?.userId != "?" && conversationUser?.hasSpreedFeatureCapability("mention-flag") ?: false && activity != null) {
activity!!.findViewById<View>(R.id.toolbar).setOnClickListener { v -> showConversationInfoScreen() } activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener { v ->
showConversationInfoScreen()
}
} }
isLeavingForConversation = false isLeavingForConversation = false
@ -560,27 +582,28 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
ApplicationWideCurrentRoomHolder.getInstance().isInCall = false ApplicationWideCurrentRoomHolder.getInstance().isInCall = false
ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser
isLinkPreviewAllowed = appPreferences.areLinkPreviewsAllowed isLinkPreviewAllowed = appPreferences?.areLinkPreviewsAllowed ?: false
emojiPopup = EmojiPopup.Builder.fromRootView(view).setOnEmojiPopupShownListener { emojiPopup = messageInput?.let {
EmojiPopup.Builder.fromRootView(view).setOnEmojiPopupShownListener {
if (resources != null) { if (resources != null) {
smileyButton.setColorFilter(resources!!.getColor(R.color.colorPrimary), smileyButton?.setColorFilter(resources!!.getColor(R.color.colorPrimary), PorterDuff.Mode.SRC_IN)
PorterDuff.Mode.SRC_IN)
} }
}.setOnEmojiPopupDismissListener { }.setOnEmojiPopupDismissListener {
smileyButton.setColorFilter(resources!!.getColor(R.color.emoji_icons), smileyButton?.setColorFilter(resources!!.getColor(R.color.emoji_icons),
PorterDuff.Mode.SRC_IN) PorterDuff.Mode.SRC_IN)
}.setOnEmojiClickListener { emoji, imageView -> messageInput.editableText.append(" ") }.build(messageInput) }.setOnEmojiClickListener { emoji, imageView -> messageInput?.editableText?.append(" ") }.build(it)
}
if (activity != null) { if (activity != null) {
KeyboardUtils(activity!!, getView(), false) KeyboardUtils(activity, getView(), false)
} }
cancelNotificationsForCurrentConversation() cancelNotificationsForCurrentConversation()
if (inConversation) { if (inConversation) {
if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) { if (wasDetached && conversationUser?.hasSpreedFeatureCapability("no-ping") ?: false) {
currentConversation!!.sessionId = "0" currentConversation?.sessionId = "0"
wasDetached = false wasDetached = false
joinRoomWithPassword() joinRoomWithPassword()
} }
@ -588,35 +611,39 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun cancelNotificationsForCurrentConversation() { private fun cancelNotificationsForCurrentConversation() {
if (!conversationUser!!.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) { if (conversationUser != null) {
NotificationUtils.cancelExistingNotificationsForRoom(applicationContext, conversationUser, roomId) if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
NotificationUtils.cancelExistingNotificationsForRoom(applicationContext,
conversationUser, roomId)
} else if (!TextUtils.isEmpty(roomToken)) { } else if (!TextUtils.isEmpty(roomToken)) {
NotificationUtils.cancelExistingNotificationsForRoom(applicationContext, conversationUser, roomToken!!) NotificationUtils.cancelExistingNotificationsForRoom(applicationContext,
conversationUser, roomToken!!)
}
} }
} }
override fun onDetach(view: View) { override fun onDetach(view: View) {
super.onDetach(view) super.onDetach(view)
ApplicationWideCurrentRoomHolder.getInstance().clear() ApplicationWideCurrentRoomHolder.getInstance().clear()
eventBus.unregister(this) eventBus?.unregister(this)
if (activity != null) { if (activity != null) {
activity!!.findViewById<View>(R.id.toolbar).setOnClickListener(null) activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null)
} }
if (conversationUser!!.hasSpreedFeatureCapability("no-ping") if (conversationUser != null && conversationUser?.hasSpreedFeatureCapability("no-ping")
&& activity != null && !activity!!.isChangingConfigurations && !isLeavingForConversation) { && activity != null && !activity?.isChangingConfigurations!! && !isLeavingForConversation) {
wasDetached = true wasDetached = true
leaveRoom() leaveRoom()
} }
if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) { if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) {
mentionAutocomplete!!.dismissPopup() mentionAutocomplete?.dismissPopup()
} }
} }
override fun getTitle(): String? { override fun getTitle(): String? {
if (currentConversation != null && currentConversation!!.displayName != null) { if (currentConversation != null && currentConversation?.displayName != null) {
return EmojiCompat.get().process(currentConversation!!.displayName).toString() return EmojiCompat.get().process(currentConversation!!.displayName).toString()
} else { } else {
return "" return ""
@ -627,11 +654,11 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
super.onDestroy() super.onDestroy()
if (activity != null) { if (activity != null) {
activity!!.findViewById<View>(R.id.toolbar).setOnClickListener(null) activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null)
} }
if (actionBar != null) { if (actionBar != null) {
actionBar!!.setIcon(null) actionBar?.setIcon(null)
} }
adapter = null adapter = null
@ -647,14 +674,15 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun startPing() { private fun startPing() {
if (!conversationUser!!.hasSpreedFeatureCapability("no-ping")) { if (conversationUser != null && !conversationUser.hasSpreedFeatureCapability("no-ping")) {
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(conversationUser.baseUrl, roomToken)) ncApi?.pingCall(credentials, ApiUtils.getUrlForCallPing(conversationUser.baseUrl,
.subscribeOn(Schedulers.io()) roomToken))
.observeOn(AndroidSchedulers.mainThread()) ?.subscribeOn(Schedulers.io())
.repeatWhen { observable -> observable.delay(5000, TimeUnit.MILLISECONDS) } ?.observeOn(AndroidSchedulers.mainThread())
.takeWhile { observable -> inConversation } ?.repeatWhen { observable -> observable.delay(5000, TimeUnit.MILLISECONDS) }
.retry(3) { observable -> inConversation } ?.takeWhile { observable -> inConversation }
.subscribe(object : Observer<GenericOverall> { ?.retry(3) { observable -> inConversation }
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -672,29 +700,29 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
@OnClick(R.id.smileyButton) @OnClick(R.id.smileyButton)
internal fun onSmileyClick() { internal fun onSmileyClick() {
emojiPopup!!.toggle() emojiPopup?.toggle()
} }
private fun joinRoomWithPassword() { private fun joinRoomWithPassword() {
if (currentConversation == null || TextUtils.isEmpty(currentConversation!!.sessionId) || if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) ||
currentConversation!!.sessionId == "0") { currentConversation?.sessionId == "0") {
ncApi.joinRoom(credentials, ncApi?.joinRoom(credentials,
ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser!!.baseUrl, roomToken), roomPassword) ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser?.baseUrl, roomToken), roomPassword)
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.retry(3) ?.retry(3)
.subscribe(object : Observer<RoomOverall> { ?.subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
override fun onNext(roomOverall: RoomOverall) { override fun onNext(roomOverall: RoomOverall) {
inConversation = true inConversation = true
currentConversation!!.sessionId = roomOverall.ocs.data.sessionId currentConversation?.sessionId = roomOverall.ocs.data.sessionId
ApplicationWideCurrentRoomHolder.getInstance().session = ApplicationWideCurrentRoomHolder.getInstance().session =
currentConversation!!.sessionId currentConversation?.sessionId
startPing() startPing()
setupWebsocket() setupWebsocket()
@ -707,9 +735,9 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
if (magicWebSocketInstance != null) { if (magicWebSocketInstance != null) {
magicWebSocketInstance!!.joinRoomWithRoomTokenAndSession(roomToken, currentConversation!!.sessionId) magicWebSocketInstance?.joinRoomWithRoomTokenAndSession(roomToken, currentConversation?.sessionId)
} }
if (startCallFromNotification != null && startCallFromNotification!!) { if (startCallFromNotification != null && startCallFromNotification ?: false) {
startCallFromNotification = false startCallFromNotification = false
startACall(voiceOnly) startACall(voiceOnly)
} }
@ -725,10 +753,10 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
}) })
} else { } else {
inConversation = true inConversation = true
ApplicationWideCurrentRoomHolder.getInstance().session = currentConversation!!.sessionId ApplicationWideCurrentRoomHolder.getInstance().session = currentConversation?.sessionId
if (magicWebSocketInstance != null) { if (magicWebSocketInstance != null) {
magicWebSocketInstance!!.joinRoomWithRoomTokenAndSession(roomToken, magicWebSocketInstance?.joinRoomWithRoomTokenAndSession(roomToken,
currentConversation!!.sessionId) currentConversation?.sessionId)
} }
startPing() startPing()
if (isFirstMessagesProcessing) { if (isFirstMessagesProcessing) {
@ -740,12 +768,12 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun leaveRoom() { private fun leaveRoom() {
ncApi.leaveRoom(credentials, ncApi?.leaveRoom(credentials,
ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser!!.baseUrl, ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser?.baseUrl,
roomToken)) roomToken))
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { ?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -754,12 +782,12 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
checkingLobbyStatus = false checkingLobbyStatus = false
if (lobbyTimerHandler != null) { if (lobbyTimerHandler != null) {
lobbyTimerHandler!!.removeCallbacksAndMessages(null) lobbyTimerHandler?.removeCallbacksAndMessages(null)
} }
if (magicWebSocketInstance != null && currentConversation != null) { if (magicWebSocketInstance != null && currentConversation != null) {
magicWebSocketInstance!!.joinRoomWithRoomTokenAndSession("", magicWebSocketInstance?.joinRoomWithRoomTokenAndSession("",
currentConversation!!.sessionId) currentConversation?.sessionId)
} }
if (!isDestroyed && !isBeingDestroyed && !wasDetached) { if (!isDestroyed && !isBeingDestroyed && !wasDetached) {
@ -777,9 +805,9 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
private fun setSenderId() { private fun setSenderId() {
try { try {
val senderId = adapter!!.javaClass.getDeclaredField("senderId") val senderId = adapter?.javaClass?.getDeclaredField("senderId")
senderId.isAccessible = true senderId?.isAccessible = true
senderId.set(adapter, conversationUser!!.userId) senderId?.set(adapter, conversationUser?.userId)
} catch (e: NoSuchFieldException) { } catch (e: NoSuchFieldException) {
Log.w(TAG, "Failed to set sender id") Log.w(TAG, "Failed to set sender id")
} catch (e: IllegalAccessException) { } catch (e: IllegalAccessException) {
@ -789,7 +817,8 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
private fun submitMessage() { private fun submitMessage() {
val editable = messageInput.editableText if (messageInput != null) {
val editable = messageInput!!.editableText
val mentionSpans = editable.getSpans(0, editable.length, val mentionSpans = editable.getSpans(0, editable.length,
Spans.MentionChipSpan::class.java) Spans.MentionChipSpan::class.java)
var mentionSpan: Spans.MentionChipSpan var mentionSpan: Spans.MentionChipSpan
@ -802,17 +831,20 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@$mentionId") editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@$mentionId")
} }
messageInput.setText("") messageInput?.setText("")
sendMessage(editable) sendMessage(editable)
} }
}
private fun sendMessage(message: CharSequence) { private fun sendMessage(message: CharSequence) {
ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(conversationUser!!.baseUrl, roomToken), if (conversationUser != null) {
ncApi?.sendChatMessage(credentials, ApiUtils.getUrlForChat(conversationUser?.baseUrl,
roomToken),
message, conversationUser.displayName) message, conversationUser.displayName)
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { ?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
} }
@ -820,11 +852,11 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onNext(genericOverall: GenericOverall) { override fun onNext(genericOverall: GenericOverall) {
myFirstMessage = message myFirstMessage = message
if (popupBubble.isShown) { if (popupBubble?.isShown ?: false) {
popupBubble.hide() popupBubble?.hide()
} }
messagesListView.smoothScrollToPosition(0) messagesListView?.smoothScrollToPosition(0)
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
@ -833,11 +865,11 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
if (Integer.toString(code).startsWith("2")) { if (Integer.toString(code).startsWith("2")) {
myFirstMessage = message myFirstMessage = message
if (popupBubble.isShown) { if (popupBubble?.isShown ?: false) {
popupBubble.hide() popupBubble?.hide()
} }
messagesListView.smoothScrollToPosition(0) messagesListView?.smoothScrollToPosition(0)
} }
} }
} }
@ -847,21 +879,24 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
}) })
} }
}
private fun setupWebsocket() { private fun setupWebsocket() {
if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser!!.id) != null) { if (conversationUser != null) {
if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id) != null) {
magicWebSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id) magicWebSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id)
} else { } else {
magicWebSocketInstance = null magicWebSocketInstance = null
} }
} }
}
private fun pullChatMessages(lookIntoFuture: Int) { private fun pullChatMessages(lookIntoFuture: Int) {
if (!inConversation) { if (!inConversation) {
return return
} }
if (currentConversation!!.shouldShowLobby(conversationUser)) { if (currentConversation != null && currentConversation!!.shouldShowLobby(conversationUser)) {
return return
} }
@ -878,9 +913,13 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
if (lookIntoFuture > 0) { if (lookIntoFuture > 0) {
lookingIntoFuture = true lookingIntoFuture = true
} else if (isFirstMessagesProcessing) { } else if (isFirstMessagesProcessing) {
if (currentConversation != null) {
globalLastKnownFutureMessageId = currentConversation!!.lastReadMessage globalLastKnownFutureMessageId = currentConversation!!.lastReadMessage
globalLastKnownPastMessageId = currentConversation!!.lastReadMessage globalLastKnownPastMessageId = currentConversation!!.lastReadMessage
fieldMap["includeLastKnown"] = 1 fieldMap["includeLastKnown"] = 1
} else {
return;
}
} }
fieldMap["lookIntoFuture"] = lookIntoFuture fieldMap["lookIntoFuture"] = lookIntoFuture
@ -899,13 +938,13 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
if (!wasDetached) { if (!wasDetached) {
if (lookIntoFuture > 0) { if (lookIntoFuture > 0) {
val finalTimeout = timeout val finalTimeout = timeout
ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser!!.baseUrl, ncApi?.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser?.baseUrl,
roomToken), roomToken),
fieldMap) fieldMap)
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.takeWhile { observable -> inConversation && !wasDetached } ?.takeWhile { observable -> inConversation && !wasDetached }
.subscribe(object : Observer<Response<*>> { ?.subscribe(object : Observer<Response<*>> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -924,13 +963,13 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
}) })
} else { } else {
ncApi.pullChatMessages(credentials, ncApi?.pullChatMessages(credentials,
ApiUtils.getUrlForChat(conversationUser!!.baseUrl, roomToken), fieldMap) ApiUtils.getUrlForChat(conversationUser?.baseUrl, roomToken), fieldMap)
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.retry(3) { observable -> inConversation && !wasDetached } ?.retry(3) { observable -> inConversation && !wasDetached }
.takeWhile { observable -> inConversation && !wasDetached } ?.takeWhile { observable -> inConversation && !wasDetached }
.subscribe(object : Observer<Response<*>> { ?.subscribe(object : Observer<Response<*>> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
disposableList.add(d) disposableList.add(d)
} }
@ -968,7 +1007,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
if (response.code() == 200) { if (response.code() == 200) {
val chatOverall = response.body() as ChatOverall? val chatOverall = response.body() as ChatOverall?
val chatMessageList = chatOverall!!.ocs.data val chatMessageList = chatOverall?.ocs!!.data
val wasFirstMessageProcessing = isFirstMessagesProcessing val wasFirstMessageProcessing = isFirstMessagesProcessing
@ -976,9 +1015,9 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
cancelNotificationsForCurrentConversation() cancelNotificationsForCurrentConversation()
isFirstMessagesProcessing = false isFirstMessagesProcessing = false
loadingProgressBar.visibility = View.GONE loadingProgressBar?.visibility = View.GONE
messagesListView.visibility = View.VISIBLE messagesListView?.visibility = View.VISIBLE
} }
@ -1000,7 +1039,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
val chatMessage = chatMessageList[i] val chatMessage = chatMessageList[i]
chatMessage.isOneToOneConversation = currentConversation!!.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL chatMessage.isOneToOneConversation = currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed
chatMessage.activeUser = conversationUser chatMessage.activeUser = conversationUser
@ -1011,25 +1050,25 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
if (adapter != null) { if (adapter != null) {
adapter!!.addToEnd(chatMessageList, false) adapter?.addToEnd(chatMessageList, false)
} }
} else { } else {
var chatMessage: ChatMessage var chatMessage: ChatMessage
val shouldAddNewMessagesNotice = timeout == 0 && adapter!!.itemCount > 0 && chatMessageList.size > 0 val shouldAddNewMessagesNotice = timeout == 0 && adapter?.itemCount ?: 0 > 0 && chatMessageList.size > 0
if (shouldAddNewMessagesNotice) { if (shouldAddNewMessagesNotice) {
val unreadChatMessage = ChatMessage() val unreadChatMessage = ChatMessage()
unreadChatMessage.jsonMessageId = -1 unreadChatMessage.jsonMessageId = -1
unreadChatMessage.actorId = "-1" unreadChatMessage.actorId = "-1"
unreadChatMessage.timestamp = chatMessageList[0].timestamp unreadChatMessage.timestamp = chatMessageList[0].timestamp
unreadChatMessage.message = context!!.getString(R.string.nc_new_messages) unreadChatMessage.message = context?.getString(R.string.nc_new_messages)
adapter!!.addToStart(unreadChatMessage, false) adapter?.addToStart(unreadChatMessage, false)
} }
val isThereANewNotice = shouldAddNewMessagesNotice || adapter!!.getMessagePositionByIdInReverse("-1") != -1 val isThereANewNotice = shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1
for (i in chatMessageList.indices) { for (i in chatMessageList.indices) {
chatMessage = chatMessageList[i] chatMessage = chatMessageList[i]
@ -1038,20 +1077,20 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed
// if credentials are empty, we're acting as a guest // if credentials are empty, we're acting as a guest
if (TextUtils.isEmpty(credentials) && myFirstMessage != null && !TextUtils.isEmpty(myFirstMessage!!.toString())) { if (TextUtils.isEmpty(credentials) && myFirstMessage != null && !TextUtils.isEmpty(myFirstMessage?.toString())) {
if (chatMessage.actorType == "guests") { if (chatMessage.actorType == "guests") {
conversationUser!!.userId = chatMessage.actorId conversationUser?.userId = chatMessage.actorId
setSenderId() setSenderId()
} }
} }
val shouldScroll = !isThereANewNotice && !shouldAddNewMessagesNotice && layoutManager!!.findFirstVisibleItemPosition() == 0 || adapter != null && adapter!!.itemCount == 0 val shouldScroll = !isThereANewNotice && !shouldAddNewMessagesNotice && layoutManager?.findFirstVisibleItemPosition() == 0 || adapter != null && adapter?.itemCount == 0
if (!shouldAddNewMessagesNotice && !shouldScroll) { if (!shouldAddNewMessagesNotice && !shouldScroll && popupBubble != null) {
if (!popupBubble.isShown) { if (!popupBubble!!.isShown) {
newMessagesCount = 1 newMessagesCount = 1
popupBubble.show() popupBubble?.show()
} else if (popupBubble.isShown) { } else if (popupBubble!!.isShown) {
newMessagesCount++ newMessagesCount++
} }
} else { } else {
@ -1059,15 +1098,16 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
} }
if (adapter != null) { if (adapter != null) {
chatMessage.isGrouped = (adapter!!.isPreviousSameAuthor(chatMessage.actorId, -1) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) % 5 > 0) chatMessage.isGrouped = (adapter!!.isPreviousSameAuthor(chatMessage
chatMessage.isOneToOneConversation = (currentConversation!!.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) .actorId, -1) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) % 5 > 0)
adapter!!.addToStart(chatMessage, shouldScroll) chatMessage.isOneToOneConversation = (currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
adapter?.addToStart(chatMessage, shouldScroll)
} }
} }
if (shouldAddNewMessagesNotice && adapter != null) { if (shouldAddNewMessagesNotice && adapter != null && messagesListView != null) {
layoutManager!!.scrollToPositionWithOffset(adapter!!.getMessagePositionByIdInReverse("-1"), messagesListView.height / 2) layoutManager?.scrollToPositionWithOffset(adapter!!.getMessagePositionByIdInReverse("-1"), messagesListView!!.height / 2)
} }
} }
@ -1080,7 +1120,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
cancelNotificationsForCurrentConversation() cancelNotificationsForCurrentConversation()
isFirstMessagesProcessing = false isFirstMessagesProcessing = false
loadingProgressBar.visibility = View.GONE loadingProgressBar?.visibility = View.GONE
} }
historyRead = true historyRead = true
@ -1111,7 +1151,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_conversation, menu) inflater.inflate(R.menu.menu_conversation, menu)
if (conversationUser!!.userId == "?") { if (conversationUser?.userId == "?") {
menu.removeItem(R.id.conversation_info) menu.removeItem(R.id.conversation_info)
} else { } else {
conversationInfoMenuItem = menu.findItem(R.id.conversation_info) conversationInfoMenuItem = menu.findItem(R.id.conversation_info)
@ -1124,10 +1164,12 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onPrepareOptionsMenu(menu: Menu) { override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu) super.onPrepareOptionsMenu(menu)
if (conversationUser!!.hasSpreedFeatureCapability("read-only-rooms")) { conversationUser?.let {
if (it.hasSpreedFeatureCapability("read-only-rooms")) {
checkReadOnlyState() checkReadOnlyState()
} }
} }
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -1137,14 +1179,14 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
return true return true
} }
R.id.conversation_video_call -> { R.id.conversation_video_call -> {
if (conversationVideoMenuItem!!.icon.alpha == 255) { if (conversationVideoMenuItem?.icon?.alpha == 255) {
startACall(false) startACall(false)
return true return true
} }
return false return false
} }
R.id.conversation_voice_call -> { R.id.conversation_voice_call -> {
if (conversationVoiceCallMenuItem!!.icon.alpha == 255) { if (conversationVoiceCallMenuItem?.icon?.alpha == 255) {
startACall(true) startACall(true)
return true return true
} }
@ -1180,7 +1222,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
bundle.putString(BundleKeys.KEY_ROOM_ID, roomId) bundle.putString(BundleKeys.KEY_ROOM_ID, roomId)
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser) bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser)
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword) bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword)
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser!!.baseUrl) bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser?.baseUrl)
if (isVoiceOnlyCall) { if (isVoiceOnlyCall) {
bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true) bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true)
@ -1201,9 +1243,9 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
override fun onMessageLongClick(message: IMessage) { override fun onMessageLongClick(message: IMessage) {
if (activity != null) { if (activity != null) {
val clipboardManager = activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager val clipboardManager = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
val clipData = android.content.ClipData.newPlainText( val clipData = android.content.ClipData.newPlainText(
resources!!.getString(R.string.nc_app_name), message.text) resources?.getString(R.string.nc_app_name), message.text)
clipboardManager.primaryClip = clipData clipboardManager.primaryClip = clipData
} }
} }
@ -1235,17 +1277,17 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
@Subscribe(threadMode = ThreadMode.BACKGROUND) @Subscribe(threadMode = ThreadMode.BACKGROUND)
fun onMessageEvent(userMentionClickEvent: UserMentionClickEvent) { fun onMessageEvent(userMentionClickEvent: UserMentionClickEvent) {
if (currentConversation!!.type != Conversation.ConversationType if (currentConversation?.type != Conversation.ConversationType
.ROOM_TYPE_ONE_TO_ONE_CALL || currentConversation!!.name != .ROOM_TYPE_ONE_TO_ONE_CALL || currentConversation?.name !=
userMentionClickEvent.userId) { userMentionClickEvent.userId) {
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(conversationUser!!.baseUrl, "1", val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(conversationUser?.baseUrl, "1",
userMentionClickEvent.userId, null) userMentionClickEvent.userId, null)
ncApi.createRoom(credentials, ncApi?.createRoom(credentials,
retrofitBucket.url, retrofitBucket.queryMap) retrofitBucket.url, retrofitBucket.queryMap)
.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<RoomOverall> { ?.subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
} }
@ -1257,6 +1299,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.ocs.data.token) bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.ocs.data.token)
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.ocs.data.roomId) bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.ocs.data.roomId)
if (conversationUser != null) {
if (conversationUser.hasSpreedFeatureCapability("chat-v2")) { if (conversationUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.ocs.data)) Parcels.wrap(roomOverall.ocs.data))
@ -1264,6 +1307,7 @@ class ChatController(args: Bundle) : BaseController(args), MessagesListAdapter
ConductorRemapping.remapChatController(router, conversationUser.id, ConductorRemapping.remapChatController(router, conversationUser.id,
roomOverall.ocs.data.token, bundle, false) roomOverall.ocs.data.token, bundle, false)
}
} else { } else {
conversationIntent.putExtras(bundle) conversationIntent.putExtras(bundle)