Commit e605713a authored by Leonardo Aramaki's avatar Leonardo Aramaki

Do schedule resend of failed messages whenever connection state is set to...

Do schedule resend of failed messages whenever connection state is set to connected; also fix some typos
parent c83fedd2
...@@ -220,6 +220,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -220,6 +220,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
} }
if (state is State.Connected) { if (state is State.Connected) {
jobSchedulerInteractor.scheduleSendingMessages()
loadMissingMessages() loadMissingMessages()
} }
} }
......
...@@ -59,6 +59,7 @@ class MessageService : JobService() { ...@@ -59,6 +59,7 @@ class MessageService : JobService() {
alias = message.senderAlias alias = message.senderAlias
) )
messageRepository.save(message.copy(isTemporary = false)) messageRepository.save(message.copy(isTemporary = false))
Timber.d("Sent scheduled message given by id: ${message.id}")
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
Timber.e(ex) Timber.e(ex)
if (ex.message?.contains("E11000", true) == true) { if (ex.message?.contains("E11000", true) == true) {
...@@ -72,7 +73,6 @@ class MessageService : JobService() { ...@@ -72,7 +73,6 @@ class MessageService : JobService() {
} }
companion object { companion object {
const val EXTRA_MESSAGE_ID = "extra_message_id"
const val RETRY_SEND_MESSAGE_ID = 1 const val RETRY_SEND_MESSAGE_ID = 1
} }
} }
\ No newline at end of file
...@@ -40,6 +40,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -40,6 +40,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
private val saveChatRoomsInteractor: SaveChatRoomsInteractor, private val saveChatRoomsInteractor: SaveChatRoomsInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor, private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val viewModelMapper: ViewModelMapper, private val viewModelMapper: ViewModelMapper,
private val jobSchedulerInteractor: JobSchedulerInteractor,
settingsRepository: SettingsRepository, settingsRepository: SettingsRepository,
factory: ConnectionManagerFactory) { factory: ConnectionManagerFactory) {
private val manager: ConnectionManager = factory.create(serverInteractor.get()!!) private val manager: ConnectionManager = factory.create(serverInteractor.get()!!)
...@@ -72,17 +73,17 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -72,17 +73,17 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
fun loadChatRoom(chatRoom: ChatRoom) { fun loadChatRoom(chatRoom: ChatRoom) {
val roomName = if (chatRoom.type is RoomType.DirectMessage val roomName = if (chatRoom.type is RoomType.DirectMessage
&& chatRoom.fullName != null && chatRoom.fullName != null
&& settings.useRealName()) { && settings.useRealName()) {
chatRoom.fullName!! chatRoom.fullName!!
} else { } else {
chatRoom.name chatRoom.name
} }
navigator.toChatRoom(chatRoom.id, roomName, navigator.toChatRoom(chatRoom.id, roomName,
chatRoom.type.toString(), chatRoom.readonly ?: false, chatRoom.type.toString(), chatRoom.readonly ?: false,
chatRoom.lastSeen ?: -1, chatRoom.lastSeen ?: -1,
chatRoom.open) chatRoom.open)
} }
/** /**
...@@ -114,25 +115,25 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -114,25 +115,25 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
private suspend fun usersToChatRooms(users: List<User>): List<ChatRoom> { private suspend fun usersToChatRooms(users: List<User>): List<ChatRoom> {
return users.map { return users.map {
ChatRoom(id = it.id, ChatRoom(id = it.id,
type = RoomType.DIRECT_MESSAGE, type = RoomType.DIRECT_MESSAGE,
user = SimpleUser(username = it.username, name = it.name, id = null), user = SimpleUser(username = it.username, name = it.name, id = null),
name = it.name ?: "", name = it.name ?: "",
fullName = it.name, fullName = it.name,
readonly = false, readonly = false,
updatedAt = null, updatedAt = null,
timestamp = null, timestamp = null,
lastSeen = null, lastSeen = null,
topic = null, topic = null,
description = null, description = null,
announcement = null, announcement = null,
default = false, default = false,
open = false, open = false,
alert = false, alert = false,
unread = 0L, unread = 0L,
userMenstions = null, userMenstions = null,
groupMentions = 0L, groupMentions = 0L,
lastMessage = null, lastMessage = null,
client = client client = client
) )
} }
} }
...@@ -140,25 +141,25 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -140,25 +141,25 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
private suspend fun roomsToChatRooms(rooms: List<Room>): List<ChatRoom> { private suspend fun roomsToChatRooms(rooms: List<Room>): List<ChatRoom> {
return rooms.map { return rooms.map {
ChatRoom(id = it.id, ChatRoom(id = it.id,
type = it.type, type = it.type,
user = it.user, user = it.user,
name = it.name ?: "", name = it.name ?: "",
fullName = it.fullName, fullName = it.fullName,
readonly = it.readonly, readonly = it.readonly,
updatedAt = it.updatedAt, updatedAt = it.updatedAt,
timestamp = null, timestamp = null,
lastSeen = null, lastSeen = null,
topic = it.topic, topic = it.topic,
description = it.description, description = it.description,
announcement = it.announcement, announcement = it.announcement,
default = false, default = false,
open = false, open = false,
alert = false, alert = false,
unread = 0L, unread = 0L,
userMenstions = null, userMenstions = null,
groupMentions = 0L, groupMentions = 0L,
lastMessage = it.lastMessage, lastMessage = it.lastMessage,
client = client client = client
) )
} }
} }
...@@ -258,6 +259,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -258,6 +259,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
} }
if (state is State.Connected) { if (state is State.Connected) {
jobSchedulerInteractor.scheduleSendingMessages()
reloadRooms() reloadRooms()
updateRooms() updateRooms()
} }
...@@ -344,26 +346,26 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -344,26 +346,26 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
val chatRoom = chatRooms.find { chatRoom -> chatRoom.id == room.id } val chatRoom = chatRooms.find { chatRoom -> chatRoom.id == room.id }
chatRoom?.apply { chatRoom?.apply {
val newRoom = ChatRoom(id = room.id, val newRoom = ChatRoom(id = room.id,
type = room.type, type = room.type,
user = room.user ?: user, user = room.user ?: user,
name = room.name ?: name, name = room.name ?: name,
fullName = room.fullName ?: fullName, fullName = room.fullName ?: fullName,
readonly = room.readonly, readonly = room.readonly,
updatedAt = room.updatedAt ?: updatedAt, updatedAt = room.updatedAt ?: updatedAt,
timestamp = timestamp, timestamp = timestamp,
lastSeen = lastSeen, lastSeen = lastSeen,
topic = room.topic, topic = room.topic,
description = room.description, description = room.description,
announcement = room.announcement, announcement = room.announcement,
default = default, default = default,
favorite = favorite, favorite = favorite,
open = open, open = open,
alert = alert, alert = alert,
unread = unread, unread = unread,
userMenstions = userMenstions, userMenstions = userMenstions,
groupMentions = groupMentions, groupMentions = groupMentions,
lastMessage = room.lastMessage, lastMessage = room.lastMessage,
client = client) client = client)
removeRoom(room.id, chatRooms) removeRoom(room.id, chatRooms)
chatRooms.add(newRoom) chatRooms.add(newRoom)
saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms)) saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms))
...@@ -377,26 +379,26 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -377,26 +379,26 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
val chatRoom = chatRooms.find { chatRoom -> chatRoom.id == subscription.roomId } val chatRoom = chatRooms.find { chatRoom -> chatRoom.id == subscription.roomId }
chatRoom?.apply { chatRoom?.apply {
val newRoom = ChatRoom(id = subscription.roomId, val newRoom = ChatRoom(id = subscription.roomId,
type = subscription.type, type = subscription.type,
user = subscription.user ?: user, user = subscription.user ?: user,
name = subscription.name, name = subscription.name,
fullName = subscription.fullName ?: fullName, fullName = subscription.fullName ?: fullName,
readonly = subscription.readonly ?: readonly, readonly = subscription.readonly ?: readonly,
updatedAt = subscription.updatedAt ?: updatedAt, updatedAt = subscription.updatedAt ?: updatedAt,
timestamp = subscription.timestamp ?: timestamp, timestamp = subscription.timestamp ?: timestamp,
lastSeen = subscription.lastSeen ?: lastSeen, lastSeen = subscription.lastSeen ?: lastSeen,
topic = topic, topic = topic,
description = description, description = description,
announcement = announcement, announcement = announcement,
default = subscription.isDefault, default = subscription.isDefault,
favorite = subscription.isFavorite, favorite = subscription.isFavorite,
open = subscription.open, open = subscription.open,
alert = subscription.alert, alert = subscription.alert,
unread = subscription.unread, unread = subscription.unread,
userMenstions = subscription.userMentions, userMenstions = subscription.userMentions,
groupMentions = subscription.groupMentions, groupMentions = subscription.groupMentions,
lastMessage = lastMessage, lastMessage = lastMessage,
client = client) client = client)
removeRoom(subscription.roomId, chatRooms) removeRoom(subscription.roomId, chatRooms)
chatRooms.add(newRoom) chatRooms.add(newRoom)
saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms)) saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms))
......
...@@ -23,26 +23,24 @@ import chat.rocket.core.internal.rest.logout ...@@ -23,26 +23,24 @@ import chat.rocket.core.internal.rest.logout
import chat.rocket.core.internal.rest.me import chat.rocket.core.internal.rest.me
import chat.rocket.core.internal.rest.unregisterPushToken import chat.rocket.core.internal.rest.unregisterPushToken
import chat.rocket.core.model.Myself import chat.rocket.core.model.Myself
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class MainPresenter @Inject constructor( class MainPresenter @Inject constructor(
private val view: MainView, private val view: MainView,
private val strategy: CancelStrategy, private val strategy: CancelStrategy,
private val navigator: MainNavigator, private val navigator: MainNavigator,
private val tokenRepository: TokenRepository, private val tokenRepository: TokenRepository,
private val serverInteractor: GetCurrentServerInteractor, private val serverInteractor: GetCurrentServerInteractor,
private val localRepository: LocalRepository, private val localRepository: LocalRepository,
private val navHeaderMapper: NavHeaderViewModelMapper, private val navHeaderMapper: NavHeaderViewModelMapper,
private val saveAccountInteractor: SaveAccountInteractor, private val saveAccountInteractor: SaveAccountInteractor,
private val getAccountsInteractor: GetAccountsInteractor, private val getAccountsInteractor: GetAccountsInteractor,
private val removeAccountInterector: RemoveAccountInterector, private val removeAccountInteractor: RemoveAccountInteractor,
private val factory: RocketChatClientFactory, private val factory: RocketChatClientFactory,
getSettingsInteractor: GetSettingsInteractor, getSettingsInteractor: GetSettingsInteractor,
managerFactory: ConnectionManagerFactory managerFactory: ConnectionManagerFactory
) : CheckServerPresenter(strategy, client = factory.create(serverInteractor.get()!!), view = view) { ) : CheckServerPresenter(strategy, client = factory.create(serverInteractor.get()!!), view = view) {
private val currentServer = serverInteractor.get()!! private val currentServer = serverInteractor.get()!!
private val manager = managerFactory.create(currentServer) private val manager = managerFactory.create(currentServer)
...@@ -105,7 +103,7 @@ class MainPresenter @Inject constructor( ...@@ -105,7 +103,7 @@ class MainPresenter @Inject constructor(
try { try {
disconnect() disconnect()
removeAccountInterector.remove(currentServer) removeAccountInteractor.remove(currentServer)
tokenRepository.remove(currentServer) tokenRepository.remove(currentServer)
navigator.toNewServer() navigator.toNewServer()
} catch (ex: Exception) { } catch (ex: Exception) {
......
...@@ -2,7 +2,7 @@ package chat.rocket.android.server.domain ...@@ -2,7 +2,7 @@ package chat.rocket.android.server.domain
import javax.inject.Inject import javax.inject.Inject
class RemoveAccountInterector @Inject constructor(val repository: AccountsRepository) { class RemoveAccountInteractor @Inject constructor(val repository: AccountsRepository) {
suspend fun remove(serverUrl: String) { suspend fun remove(serverUrl: String) {
repository.remove(serverUrl) repository.remove(serverUrl)
} }
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.server.infraestructure ...@@ -3,6 +3,7 @@ package chat.rocket.android.server.infraestructure
import android.app.job.JobInfo import android.app.job.JobInfo
import android.app.job.JobScheduler import android.app.job.JobScheduler
import chat.rocket.android.server.domain.JobSchedulerInteractor import chat.rocket.android.server.domain.JobSchedulerInteractor
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -14,6 +15,7 @@ class JobSchedulerInteractorImpl @Inject constructor( ...@@ -14,6 +15,7 @@ class JobSchedulerInteractorImpl @Inject constructor(
) : JobSchedulerInteractor { ) : JobSchedulerInteractor {
override fun scheduleSendingMessages() { override fun scheduleSendingMessages() {
Timber.d("Scheduling unsent messages to send...")
jobScheduler.schedule(jobInfo) jobScheduler.schedule(jobInfo)
} }
} }
\ No newline at end of file
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