Unverified Commit 6a0c4051 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #1859 from RocketChat/feature/room-deep-link

[FEATURE] Notification deeplink to room
parents cfc98b08 2095a508
...@@ -137,7 +137,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -137,7 +137,7 @@ class ChatRoomPresenter @Inject constructor(
} finally { } finally {
// User has at least an 'owner' or 'moderator' role. // User has at least an 'owner' or 'moderator' role.
val userCanMod = isOwnerOrMod() val userCanMod = isOwnerOrMod()
val chatRoom = retryDB("getRoom($roomId)") { dbManager.getRoom(roomId) } val chatRoom = dbManager.getRoom(roomId)
val muted = chatRoom?.chatRoom?.muted ?: emptyList() val muted = chatRoom?.chatRoom?.muted ?: emptyList()
// Can post anyway if has the 'post-readonly' permission on server. // Can post anyway if has the 'post-readonly' permission on server.
val userCanPost = userCanMod || permissions.canPostToReadOnlyChannels() || val userCanPost = userCanMod || permissions.canPostToReadOnlyChannels() ||
......
...@@ -42,6 +42,26 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -42,6 +42,26 @@ class ChatRoomsPresenter @Inject constructor(
private val client = manager.client private val client = manager.client
private val settings = settingsRepository.get(currentServer) private val settings = settingsRepository.get(currentServer)
fun loadChatRoom(roomId: String) {
launchUI(strategy) {
view.showLoadingRoom("")
try {
val room = dbManager.getRoom(roomId)
if (room != null) {
loadChatRoom(room.chatRoom, true)
} else {
Timber.d("Error loading channel")
view.showGenericErrorMessage()
}
} catch (ex: Exception) {
Timber.d(ex, "Error loading channel")
view.showGenericErrorMessage()
} finally {
view.hideLoadingRoom()
}
}
}
fun loadChatRoom(chatRoom: RoomUiModel) { fun loadChatRoom(chatRoom: RoomUiModel) {
launchUI(strategy) { launchUI(strategy) {
view.showLoadingRoom(chatRoom.name) view.showLoadingRoom(chatRoom.name)
......
...@@ -84,8 +84,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -84,8 +84,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
if (bundle != null) { if (bundle != null) {
chatRoomId = bundle.getString(BUNDLE_CHAT_ROOM_ID) chatRoomId = bundle.getString(BUNDLE_CHAT_ROOM_ID)
chatRoomId?.let { chatRoomId?.let {
// TODO - bring back support to load a room from id. presenter.loadChatRoom(it)
//presenter.goToChatRoomWithId(it)
chatRoomId = null chatRoomId = null
} }
} }
......
...@@ -35,16 +35,14 @@ class FavoriteMessagesPresenter @Inject constructor( ...@@ -35,16 +35,14 @@ class FavoriteMessagesPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
try { try {
view.showLoading() view.showLoading()
retryDB("getRoom($roomId)") { dbManager.getRoom(roomId)?.let {
dbManager.getRoom(roomId)?.let { val favoriteMessages =
val favoriteMessages = client.getFavoriteMessages(roomId, roomTypeOf(it.chatRoom.type), offset)
client.getFavoriteMessages(roomId, roomTypeOf(it.chatRoom.type), offset) val messageList = mapper.map(favoriteMessages.result, asNotReversed = true)
val messageList = mapper.map(favoriteMessages.result, asNotReversed = true) view.showFavoriteMessages(messageList)
view.showFavoriteMessages(messageList) offset += 1 * 30
offset += 1 * 30 }.ifNull {
}.ifNull { Timber.e("Couldn't find a room with id: $roomId at current server.")
Timber.e("Couldn't find a room with id: $roomId at current server.")
}
} }
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
Timber.e(exception) Timber.e(exception)
......
...@@ -37,15 +37,13 @@ class FilesPresenter @Inject constructor( ...@@ -37,15 +37,13 @@ class FilesPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
try { try {
view.showLoading() view.showLoading()
retryDB("getRoom($roomId)") { dbManager.getRoom(roomId)?.let {
dbManager.getRoom(roomId)?.let { val files = client.getFiles(roomId, roomTypeOf(it.chatRoom.type), offset)
val files = client.getFiles(roomId, roomTypeOf(it.chatRoom.type), offset) val filesUiModel = mapper.mapToUiModelList(files.result)
val filesUiModel = mapper.mapToUiModelList(files.result) view.showFiles(filesUiModel, files.total)
view.showFiles(filesUiModel, files.total) offset += 1 * 30
offset += 1 * 30 }.ifNull {
}.ifNull { Timber.e("Couldn't find a room with id: $roomId at current server.")
Timber.e("Couldn't find a room with id: $roomId at current server.")
}
} }
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
exception.message?.let { exception.message?.let {
......
...@@ -37,16 +37,14 @@ class MembersPresenter @Inject constructor( ...@@ -37,16 +37,14 @@ class MembersPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
try { try {
view.showLoading() view.showLoading()
retryDB("getRoom($roomId)") { dbManager.getRoom(roomId)?.let {
dbManager.getRoom(roomId)?.let { val members =
val members = client.getMembers(roomId, roomTypeOf(it.chatRoom.type), offset, 60)
client.getMembers(roomId, roomTypeOf(it.chatRoom.type), offset, 60) val memberUiModels = mapper.mapToUiModelList(members.result)
val memberUiModels = mapper.mapToUiModelList(members.result) view.showMembers(memberUiModels, members.total)
view.showMembers(memberUiModels, members.total) offset += 1 * 60L
offset += 1 * 60L }.ifNull {
}.ifNull { Timber.e("Couldn't find a room with id: $roomId at current server.")
Timber.e("Couldn't find a room with id: $roomId at current server.")
}
} }
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
exception.message?.let { exception.message?.let {
......
...@@ -35,16 +35,14 @@ class PinnedMessagesPresenter @Inject constructor( ...@@ -35,16 +35,14 @@ class PinnedMessagesPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
try { try {
view.showLoading() view.showLoading()
retryDB("getRoom($roomId)") { dbManager.getRoom(roomId)?.let {
dbManager.getRoom(roomId)?.let { val pinnedMessages =
val pinnedMessages = client.getPinnedMessages(roomId, roomTypeOf(it.chatRoom.type), offset)
client.getPinnedMessages(roomId, roomTypeOf(it.chatRoom.type), offset) val messageList = mapper.map(pinnedMessages.result, asNotReversed = true)
val messageList = mapper.map(pinnedMessages.result, asNotReversed = true) view.showPinnedMessages(messageList)
view.showPinnedMessages(messageList) offset += 1 * 30
offset += 1 * 30 }.ifNull {
}.ifNull { Timber.e("Couldn't find a room with id: $roomId at current server.")
Timber.e("Couldn't find a room with id: $roomId at current server.")
}
} }
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
Timber.e(exception) Timber.e(exception)
......
...@@ -296,11 +296,8 @@ class PushManager @Inject constructor( ...@@ -296,11 +296,8 @@ class PushManager @Inject constructor(
} }
private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, grouped: Boolean = false): PendingIntent { private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, grouped: Boolean = false): PendingIntent {
val notificationIntent = context.changeServerIntent(pushMessage.info.host, chatRoomId = pushMessage.info.roomId) val roomId = if (!grouped) pushMessage.info.roomId else null
// TODO - add support to go directly to the chatroom val notificationIntent = context.changeServerIntent(pushMessage.info.host, chatRoomId = roomId)
/*if (!isGrouped) {
notificationIntent.putExtra(EXTRA_ROOM_ID, pushMessage.info.roomId)
}*/
return PendingIntent.getActivity(context, random.nextInt(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) return PendingIntent.getActivity(context, random.nextInt(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
......
package chat.rocket.android.push package chat.rocket.android.push
import android.os.Bundle
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.work.Constraints import androidx.work.Constraints
import androidx.work.NetworkType import androidx.work.NetworkType
...@@ -23,9 +24,12 @@ class FirebaseMessagingService : FirebaseMessagingService() { ...@@ -23,9 +24,12 @@ class FirebaseMessagingService : FirebaseMessagingService() {
} }
override fun onMessageReceived(message: RemoteMessage) { override fun onMessageReceived(message: RemoteMessage) {
// XXX - for now this is ok, if we start to do network calls, use a Worker instead message.data?.let { data ->
message.data?.let { val bundle = Bundle()
pushManager.handle(bundleOf(*(it.map { Pair(it.key, it.value) }).toTypedArray())) data.entries.forEach { entry ->
bundle.putString(entry.key, entry.value)
}
pushManager.handle(bundle)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment