diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt index 5d7d3f17d..1170b30de 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt @@ -47,7 +47,6 @@ import com.glia.widgets.core.engagement.domain.UpdateOperatorDefaultImageUrlUseC import com.glia.widgets.core.fileupload.domain.AddFileAttachmentsObserverUseCase import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase import com.glia.widgets.core.fileupload.domain.GetFileAttachmentsUseCase -import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentObserverUseCase import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentUseCase import com.glia.widgets.core.fileupload.domain.SupportedFileCountCheckUseCase import com.glia.widgets.core.fileupload.model.LocalAttachment @@ -89,8 +88,8 @@ import com.glia.widgets.view.MinimizeHandler import com.glia.widgets.webbrowser.domain.GetUrlFromLinkUseCase import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.disposables.CompositeDisposable +import io.reactivex.rxjava3.functions.Consumer import io.reactivex.rxjava3.schedulers.Schedulers -import java.util.Observer internal class ChatController( private val callTimer: TimeCounter, @@ -104,7 +103,6 @@ internal class ChatController( private val endEngagementUseCase: EndEngagementUseCase, private val addFileToAttachmentAndUploadUseCase: AddFileToAttachmentAndUploadUseCase, private val addFileAttachmentsObserverUseCase: AddFileAttachmentsObserverUseCase, - private val removeFileAttachmentObserverUseCase: RemoveFileAttachmentObserverUseCase, private val getFileAttachmentsUseCase: GetFileAttachmentsUseCase, private val removeFileAttachmentUseCase: RemoveFileAttachmentUseCase, private val supportedFileCountCheckUseCase: SupportedFileCountCheckUseCase, @@ -183,10 +181,10 @@ internal class ChatController( @Volatile private var isChatViewPaused = false - private val fileAttachmentObserver = Observer { _, _ -> + private val fileAttachmentCallback = Consumer> { attachments -> view?.apply { - emitUploadAttachments(getFileAttachmentsUseCase()) emitViewState { + emitUploadAttachments(attachments) chatState.setShowSendButton(isShowSendButtonUseCase(chatState.lastTypedText)) .setIsAttachmentButtonEnabled(supportedFileCountCheckUseCase()) } @@ -313,7 +311,9 @@ internal class ChatController( } private fun prepareChatComponents() { - addFileAttachmentsObserverUseCase.execute(fileAttachmentObserver) + disposable.add( + addFileAttachmentsObserverUseCase().subscribe(fileAttachmentCallback) + ) minimizeHandler.addListener { minimizeView() } timerStatusListener?.also { callTimer.removeFormattedValueListener(it) } val newTimerListener = createNewTimerCallback() @@ -376,7 +376,6 @@ internal class ChatController( timerStatusListener = null callTimer.clear() minimizeHandler.clear() - removeFileAttachmentObserverUseCase(fileAttachmentObserver) chatManager.reset() } } @@ -855,7 +854,7 @@ internal class ChatController( } private fun onAttachmentReceived(file: LocalAttachment) { - addFileToAttachmentAndUploadUseCase.execute(file, object : AddFileToAttachmentAndUploadUseCase.Listener { + addFileToAttachmentAndUploadUseCase(file, object : AddFileToAttachmentAndUploadUseCase.Listener { override fun onFinished() { Logger.d(TAG, "fileUploadFinished") //We need this file locally, so clearing only file uri reference diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt index 292cb9111..fc5356238 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt @@ -44,7 +44,7 @@ internal class GliaSendMessageUseCase( fun execute(message: String, listener: Listener) { val localAttachments: List? = fileAttachmentRepository - .readyToSendLocalAttachments + .getReadyToSendFileAttachments() .filter { it.engagementFile != null } .takeIf { it.isNotEmpty() } diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt index 2df144b77..c5601db0e 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt @@ -21,7 +21,7 @@ internal class IsShowSendButtonUseCase( } private fun hadReadyToSendUnsentAttachments(): Boolean { - return fileAttachmentRepository.readyToSendLocalAttachments.isNotEmpty() + return fileAttachmentRepository.getReadyToSendFileAttachments().isNotEmpty() } private fun hasEngagementOngoingAndReadyToSendUnsentAttachments(): Boolean { diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/FileAttachmentRepository.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/FileAttachmentRepository.kt index bcda54985..3613b1e2a 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/FileAttachmentRepository.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/FileAttachmentRepository.kt @@ -9,46 +9,75 @@ import com.glia.widgets.core.engagement.exception.EngagementMissingException import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.di.GliaCore -import java.util.Observable -import java.util.Observer +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.subjects.BehaviorSubject import kotlin.jvm.optionals.getOrNull -internal class FileAttachmentRepository(private val gliaCore: GliaCore) { +internal interface FileAttachmentRepository { + val observable: Observable> + + fun getFileAttachments(): List + fun getReadyToSendFileAttachments(): List + fun getAttachedFilesCount(): Int + fun isFileAttached(uri: Uri): Boolean + fun attachFile(file: LocalAttachment) + fun uploadFile(shouldUseSecureMessagingEndpoints: Boolean, file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) + fun detachFile(attachment: LocalAttachment) + fun detachFiles(attachments: List) + fun detachAllFiles() + fun setFileAttachmentTooLarge(uri: Uri) + fun setSupportedFileAttachmentCountExceeded(uri: Uri) + fun setFileAttachmentEngagementMissing(uri: Uri) +} + +internal class FileAttachmentRepositoryImpl( + private val gliaCore: GliaCore +) : FileAttachmentRepository { private val secureConversations: SecureConversations by lazy { gliaCore.secureConversations } - private val observable = ObservableFileAttachmentList() + private val _observable = BehaviorSubject.createDefault(emptyList()) + + override val observable: Observable> = _observable - val localAttachments: List - get() = observable.localAttachments + override fun getFileAttachments(): List { + return _observable.value ?: emptyList() + } - val readyToSendLocalAttachments: List - get() = observable.localAttachments + override fun getReadyToSendFileAttachments(): List { + return getFileAttachments() .filter { obj: LocalAttachment -> obj.isReadyToSend } + } - val attachedFilesCount: Long - get() = observable.localAttachments.size.toLong() + override fun getAttachedFilesCount(): Int { + return getFileAttachments().size + } - fun isFileAttached(uri: Uri): Boolean { - return observable.localAttachments + override fun isFileAttached(uri: Uri): Boolean { + return getFileAttachments() .any { it.uri == uri } } - fun attachFile(file: LocalAttachment) { - observable.notifyUpdate( - observable.localAttachments + file - ) + override fun attachFile(file: LocalAttachment) { + _observable.onNext(getFileAttachments() + file) } - fun uploadFile(shouldUseSecureMessagingEndpoints: Boolean, file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { - val engagement = gliaCore.currentEngagement.getOrNull() - when { + override fun uploadFile(shouldUseSecureMessagingEndpoints: Boolean, file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { + if (shouldUseSecureMessagingEndpoints) { + uploadFileForSecureConversation(file, listener) + } else { + uploadFileForLiveEngagement(file, listener) + } + } - shouldUseSecureMessagingEndpoints -> { - secureConversations.uploadFile(file.uri, handleFileUpload(file, listener)) - } + private fun uploadFileForSecureConversation(file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { + secureConversations.uploadFile(file.uri, handleFileUpload(file, listener)) + } + private fun uploadFileForLiveEngagement(file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { + val engagement = gliaCore.currentEngagement.getOrNull() + when { engagement != null -> { engagement.uploadFile(file.uri, handleFileUpload(file, listener)) } @@ -76,51 +105,26 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { } } - fun setFileAttachmentTooLarge(uri: Uri) { - setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_FILE_TOO_LARGE) - } - - fun setSupportedFileAttachmentCountExceeded(uri: Uri) { - setFileAttachmentStatus( - uri, - LocalAttachment.Status.ERROR_SUPPORTED_FILE_ATTACHMENT_COUNT_EXCEEDED - ) - } - - fun setFileAttachmentEngagementMissing(uri: Uri) { - setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING) - } - - fun detachFile(attachment: LocalAttachment?) { - observable.notifyUpdate( - observable.localAttachments - .filter { it.uri !== attachment?.uri } + override fun detachFile(attachment: LocalAttachment) { + _observable.onNext( + getFileAttachments() + .filter { it.uri !== attachment.uri } ) } - fun detachFiles(attachments: List) { - observable.notifyUpdate( - observable.localAttachments + override fun detachFiles(attachments: List) { + _observable.onNext( + getFileAttachments() .filter { attachment: LocalAttachment? -> - !attachments.contains(attachment) + !attachments.contains( + attachment + ) } ) } - fun detachAllFiles() { - observable.notifyUpdate(ArrayList()) - } - - fun addObserver(observer: Observer?) { - observable.addObserver(observer) - } - - fun removeObserver(observer: Observer?) { - observable.deleteObserver(observer) - } - - fun clearObservers() { - observable.deleteObservers() + override fun detachAllFiles() { + _observable.onNext(emptyList()) } private fun onUploadFileSecurityScanRequired( @@ -130,7 +134,7 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { ) { setFileAttachmentStatus(uri, LocalAttachment.Status.SECURITY_SCAN) listener.onSecurityCheckStarted() - engagementFile.on(EngagementFile.Events.SCAN_RESULT) { scanResult: EngagementFile.ScanResult -> + engagementFile.on(EngagementFile.Events.SCAN_RESULT) { scanResult: EngagementFile.ScanResult? -> engagementFile.off(EngagementFile.Events.SCAN_RESULT) listener.onSecurityCheckFinished(scanResult) onUploadFileSecurityScanReceived(uri, engagementFile, scanResult, listener) @@ -140,7 +144,7 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { private fun onUploadFileSecurityScanReceived( uri: Uri, engagementFile: EngagementFile?, - scanResult: EngagementFile.ScanResult, + scanResult: EngagementFile.ScanResult?, listener: AddFileToAttachmentAndUploadUseCase.Listener ) { if (scanResult == EngagementFile.ScanResult.CLEAN && engagementFile != null) { @@ -161,8 +165,8 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { } private fun setFileAttachmentStatus(uri: Uri, status: LocalAttachment.Status) { - observable.notifyUpdate( - observable.localAttachments + _observable.onNext( + getFileAttachments() .map { localAttachment: LocalAttachment -> if (localAttachment.uri === uri) { localAttachment.copy(attachmentStatus = status) @@ -174,11 +178,11 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { } private fun onEngagementFileReceived(uri: Uri, engagementFile: EngagementFile) { - observable.notifyUpdate( - observable.localAttachments + _observable.onNext( + getFileAttachments() .map { attachment: LocalAttachment -> if (attachment.uri == uri) { - attachment.copy(attachmentStatus = LocalAttachment.Status.READY_TO_SEND, engagementFile = engagementFile) + attachment.copy(engagementFile = engagementFile, attachmentStatus = LocalAttachment.Status.READY_TO_SEND) } else { attachment } @@ -186,6 +190,18 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { ) } + override fun setFileAttachmentTooLarge(uri: Uri) { + setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_FILE_TOO_LARGE) + } + + override fun setSupportedFileAttachmentCountExceeded(uri: Uri) { + setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_SUPPORTED_FILE_ATTACHMENT_COUNT_EXCEEDED) + } + + override fun setFileAttachmentEngagementMissing(uri: Uri) { + setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING) + } + private fun getAttachmentStatus(exception: GliaException): LocalAttachment.Status { return when (exception.cause) { GliaException.Cause.FILE_UPLOAD_FORBIDDEN -> LocalAttachment.Status.ERROR_FILE_UPLOAD_FORBIDDEN @@ -198,14 +214,4 @@ internal class FileAttachmentRepository(private val gliaCore: GliaCore) { else -> LocalAttachment.Status.ERROR_UNKNOWN } } - - class ObservableFileAttachmentList : Observable() { - var localAttachments: List = ArrayList() - - fun notifyUpdate(newObject: List) { - localAttachments = newObject - setChanged() - notifyObservers() - } - } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/SecureFileAttachmentRepository.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/SecureFileAttachmentRepository.kt deleted file mode 100644 index a76e2bc47..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/SecureFileAttachmentRepository.kt +++ /dev/null @@ -1,178 +0,0 @@ -package com.glia.widgets.core.fileupload - -import android.net.Uri -import com.glia.androidsdk.GliaException -import com.glia.androidsdk.RequestCallback -import com.glia.androidsdk.engagement.EngagementFile -import com.glia.androidsdk.secureconversations.SecureConversations -import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase -import com.glia.widgets.core.fileupload.model.LocalAttachment -import com.glia.widgets.di.GliaCore -import io.reactivex.rxjava3.core.Observable -import io.reactivex.rxjava3.subjects.BehaviorSubject -import kotlin.jvm.optionals.getOrNull - -internal class SecureFileAttachmentRepository(private val gliaCore: GliaCore) { - private val secureConversations: SecureConversations by lazy { - gliaCore.secureConversations - } - - private val _observable = BehaviorSubject.createDefault(emptyList()) - - val observable: Observable> = _observable - - fun getFileAttachments(): List { - return _observable.value ?: emptyList() - } - - fun getReadyToSendFileAttachments(): List { - return getFileAttachments() - .filter { obj: LocalAttachment -> obj.isReadyToSend } - } - - fun getAttachedFilesCount(): Int { - return getFileAttachments().size - } - - fun isFileAttached(uri: Uri): Boolean { - return getFileAttachments() - .any { it.uri == uri } - } - - fun attachFile(file: LocalAttachment) { - _observable.onNext(getFileAttachments() + file) - } - - fun uploadFile(file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { - val engagement = gliaCore.currentEngagement.getOrNull() - if (engagement != null) { - engagement.uploadFile(file.uri, handleFileUpload(file, listener)) - } else { - secureConversations.uploadFile(file.uri, handleFileUpload(file, listener)) - } - } - - private fun handleFileUpload( - file: LocalAttachment, - listener: AddFileToAttachmentAndUploadUseCase.Listener - ) = RequestCallback { engagementFile: EngagementFile?, e: GliaException? -> - if (engagementFile != null) { - if (!engagementFile.isSecurityScanRequired) { - onUploadFileSuccess(file.uri, engagementFile, listener) - } else { - onUploadFileSecurityScanRequired(file.uri, engagementFile, listener) - } - } else if (e != null) { - setFileAttachmentStatus(file.uri, getAttachmentStatus(e)) - listener.onError(e) - } - } - - fun detachFile(attachment: LocalAttachment) { - _observable.onNext( - getFileAttachments() - .filter { it.uri !== attachment.uri } - ) - } - - fun detachFiles(attachments: List) { - _observable.onNext( - getFileAttachments() - .filter { attachment: LocalAttachment? -> - !attachments.contains( - attachment - ) - } - ) - } - - fun detachAllFiles() { - _observable.onNext(emptyList()) - } - - private fun onUploadFileSecurityScanRequired( - uri: Uri, - engagementFile: EngagementFile, - listener: AddFileToAttachmentAndUploadUseCase.Listener - ) { - setFileAttachmentStatus(uri, LocalAttachment.Status.SECURITY_SCAN) - listener.onSecurityCheckStarted() - engagementFile.on( - EngagementFile.Events.SCAN_RESULT - ) { scanResult: EngagementFile.ScanResult? -> - engagementFile.off(EngagementFile.Events.SCAN_RESULT) - listener.onSecurityCheckFinished(scanResult) - onUploadFileSecurityScanReceived(uri, engagementFile, scanResult, listener) - } - } - - private fun onUploadFileSecurityScanReceived( - uri: Uri, - engagementFile: EngagementFile?, - scanResult: EngagementFile.ScanResult?, - listener: AddFileToAttachmentAndUploadUseCase.Listener - ) { - if (scanResult == EngagementFile.ScanResult.CLEAN && engagementFile != null) { - onUploadFileSuccess(uri, engagementFile, listener) - } else { - setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_SECURITY_SCAN_FAILED) - listener.onFinished() - } - } - - private fun onUploadFileSuccess( - uri: Uri, - engagementFile: EngagementFile, - listener: AddFileToAttachmentAndUploadUseCase.Listener - ) { - onEngagementFileReceived(uri, engagementFile) - listener.onFinished() - } - - private fun onEngagementFileReceived(uri: Uri, engagementFile: EngagementFile) { - _observable.onNext( - getFileAttachments() - .map { attachment: LocalAttachment -> - if (attachment.uri == uri) { - attachment.copy(engagementFile = engagementFile, attachmentStatus = LocalAttachment.Status.READY_TO_SEND) - } else { - attachment - } - } - ) - } - - fun setFileAttachmentTooLarge(uri: Uri) { - setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_FILE_TOO_LARGE) - } - - fun setSupportedFileAttachmentCountExceeded(uri: Uri) { - setFileAttachmentStatus(uri, LocalAttachment.Status.ERROR_SUPPORTED_FILE_ATTACHMENT_COUNT_EXCEEDED) - } - - private fun setFileAttachmentStatus(uri: Uri, status: LocalAttachment.Status) { - _observable.onNext( - getFileAttachments() - .map { localAttachment: LocalAttachment -> - if (localAttachment.uri === uri) { - localAttachment.copy(attachmentStatus = status) - } else { - localAttachment - } - } - ) - } - - private fun getAttachmentStatus(exception: GliaException): LocalAttachment.Status { - return when (exception.cause) { - GliaException.Cause.FILE_UPLOAD_FORBIDDEN -> LocalAttachment.Status.ERROR_FILE_UPLOAD_FORBIDDEN - GliaException.Cause.INVALID_INPUT -> LocalAttachment.Status.ERROR_INVALID_INPUT - GliaException.Cause.NETWORK_TIMEOUT -> LocalAttachment.Status.ERROR_NETWORK_TIMEOUT - GliaException.Cause.INTERNAL_ERROR -> LocalAttachment.Status.ERROR_INTERNAL - GliaException.Cause.PERMISSIONS_DENIED -> LocalAttachment.Status.ERROR_PERMISSIONS_DENIED - GliaException.Cause.FILE_FORMAT_UNSUPPORTED -> LocalAttachment.Status.ERROR_FORMAT_UNSUPPORTED - GliaException.Cause.FILE_TOO_LARGE -> LocalAttachment.Status.ERROR_FILE_TOO_LARGE - else -> LocalAttachment.Status.ERROR_UNKNOWN - } - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.java b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.java deleted file mode 100644 index f4fe078df..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.glia.widgets.core.fileupload.domain; - -import com.glia.widgets.core.fileupload.FileAttachmentRepository; - -import java.util.Observer; - -/** - * @hide - */ -public class AddFileAttachmentsObserverUseCase { - private final FileAttachmentRepository repository; - - public AddFileAttachmentsObserverUseCase(FileAttachmentRepository repository) { - this.repository = repository; - } - - public void execute(Observer observer) { - this.repository.addObserver(observer); - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileAttachmentsObserverUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.kt similarity index 61% rename from widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileAttachmentsObserverUseCase.kt rename to widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.kt index 2342d7443..08f6ec40c 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileAttachmentsObserverUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileAttachmentsObserverUseCase.kt @@ -1,12 +1,15 @@ -package com.glia.widgets.core.secureconversations.domain +package com.glia.widgets.core.fileupload.domain -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.helper.rx.Schedulers import io.reactivex.rxjava3.core.Observable -internal class AddSecureFileAttachmentsObserverUseCase( - private val repository: SecureFileAttachmentRepository, +/** + * @hide + */ +internal class AddFileAttachmentsObserverUseCase( + private val repository: FileAttachmentRepository, private val schedulers: Schedulers ) { operator fun invoke(): Observable> = repository.observable diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt index 6b09cec3c..4e2976446 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt @@ -16,9 +16,9 @@ internal class AddFileToAttachmentAndUploadUseCase( private val manageSecureMessagingStatusUseCase: ManageSecureMessagingStatusUseCase ) { private val isSupportedFileCountExceeded: Boolean - get() = fileAttachmentRepository.attachedFilesCount > SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT + get() = fileAttachmentRepository.getAttachedFilesCount() > SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT - fun execute(file: LocalAttachment, listener: Listener) { + operator fun invoke(file: LocalAttachment, listener: Listener) { if (fileAttachmentRepository.isFileAttached(file.uri)) { listener.onError(RemoveBeforeReUploadingException()) } else { diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/GetFileAttachmentsUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/GetFileAttachmentsUseCase.kt index 20687a3f2..ebc7b729f 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/GetFileAttachmentsUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/GetFileAttachmentsUseCase.kt @@ -5,6 +5,6 @@ import com.glia.widgets.core.fileupload.model.LocalAttachment internal class GetFileAttachmentsUseCase(private val repository: FileAttachmentRepository) { operator fun invoke(): List { - return repository.localAttachments + return repository.getFileAttachments() } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentObserverUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentObserverUseCase.kt deleted file mode 100644 index e758c064a..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentObserverUseCase.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.glia.widgets.core.fileupload.domain - -import com.glia.widgets.core.fileupload.FileAttachmentRepository -import java.util.Observer - -internal class RemoveFileAttachmentObserverUseCase(private val repository: FileAttachmentRepository) { - operator fun invoke(observer: Observer?) { - repository.removeObserver(observer) - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentUseCase.kt index 733bf3fb2..14b83efdf 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/RemoveFileAttachmentUseCase.kt @@ -4,7 +4,7 @@ import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.fileupload.model.LocalAttachment internal class RemoveFileAttachmentUseCase(private val repository: FileAttachmentRepository) { - operator fun invoke(attachment: LocalAttachment?) { + operator fun invoke(attachment: LocalAttachment) { repository.detachFile(attachment) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCase.kt index ede900353..e8a001396 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCase.kt @@ -4,10 +4,10 @@ import com.glia.widgets.core.fileupload.FileAttachmentRepository internal class SupportedFileCountCheckUseCase(private val repository: FileAttachmentRepository) { operator fun invoke(): Boolean { - return repository.localAttachments.size <= SUPPORTED_FILE_COUNT + return repository.getAttachedFilesCount() <= SUPPORTED_FILE_COUNT } companion object { - const val SUPPORTED_FILE_COUNT: Long = 25 + const val SUPPORTED_FILE_COUNT: Int = 25 } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileToAttachmentAndUploadUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileToAttachmentAndUploadUseCase.kt index eec73c2ae..fc242e39d 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileToAttachmentAndUploadUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/AddSecureFileToAttachmentAndUploadUseCase.kt @@ -1,16 +1,17 @@ package com.glia.widgets.core.secureconversations.domain -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase +import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase.Listener import com.glia.widgets.core.fileupload.domain.SupportedFileCountCheckUseCase import com.glia.widgets.core.fileupload.exception.RemoveBeforeReUploadingException import com.glia.widgets.core.fileupload.exception.SupportedFileCountExceededException import com.glia.widgets.core.fileupload.exception.SupportedFileSizeExceededException import com.glia.widgets.core.fileupload.model.LocalAttachment -internal class AddSecureFileToAttachmentAndUploadUseCase(private val fileAttachmentRepository: SecureFileAttachmentRepository) { +internal class AddSecureFileToAttachmentAndUploadUseCase(private val fileAttachmentRepository: FileAttachmentRepository) { - fun execute(file: LocalAttachment, listener: AddFileToAttachmentAndUploadUseCase.Listener) { + operator fun invoke(file: LocalAttachment, listener: Listener) { if (fileAttachmentRepository.isFileAttached(file.uri)) { listener.onError(RemoveBeforeReUploadingException()) } else { @@ -31,7 +32,7 @@ internal class AddSecureFileToAttachmentAndUploadUseCase(private val fileAttachm listener.onError(SupportedFileSizeExceededException()) } else { listener.onStarted() - fileAttachmentRepository.uploadFile(file, listener) + fileAttachmentRepository.uploadFile(true, file, listener) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/GetSecureFileAttachmentsUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/GetSecureFileAttachmentsUseCase.kt deleted file mode 100644 index 8ffb74fa9..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/GetSecureFileAttachmentsUseCase.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.glia.widgets.core.secureconversations.domain - -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository -import com.glia.widgets.core.fileupload.model.LocalAttachment - -internal class GetSecureFileAttachmentsUseCase(private val repository: SecureFileAttachmentRepository) { - operator fun invoke(): List { - return repository.getFileAttachments() - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/RemoveSecureFileAttachmentUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/RemoveSecureFileAttachmentUseCase.kt deleted file mode 100644 index b1671fe7d..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/RemoveSecureFileAttachmentUseCase.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.glia.widgets.core.secureconversations.domain - -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository -import com.glia.widgets.core.fileupload.model.LocalAttachment - -internal class RemoveSecureFileAttachmentUseCase(private val repository: SecureFileAttachmentRepository) { - fun execute(attachment: LocalAttachment) { - repository.detachFile(attachment) - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ResetMessageCenterUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ResetMessageCenterUseCase.kt index 2e4f2296b..055bd83de 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ResetMessageCenterUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ResetMessageCenterUseCase.kt @@ -1,10 +1,10 @@ package com.glia.widgets.core.secureconversations.domain -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.secureconversations.SendMessageRepository internal class ResetMessageCenterUseCase( - private val fileAttachmentRepository: SecureFileAttachmentRepository, + private val fileAttachmentRepository: FileAttachmentRepository, private val sendMessageRepository: SendMessageRepository ) { operator fun invoke() { diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonStateUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonStateUseCase.kt index 91a6e7856..def2b7927 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonStateUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonStateUseCase.kt @@ -1,6 +1,6 @@ package com.glia.widgets.core.secureconversations.domain -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.secureconversations.SecureConversationsRepository import com.glia.widgets.core.secureconversations.SendMessageRepository import com.glia.widgets.helper.rx.Schedulers @@ -9,7 +9,7 @@ import io.reactivex.rxjava3.core.Observable internal class SendMessageButtonStateUseCase( private val sendMessageRepository: SendMessageRepository, - private val fileAttachmentRepository: SecureFileAttachmentRepository, + private val fileAttachmentRepository: FileAttachmentRepository, private val secureConversationsRepository: SecureConversationsRepository, private val showMessageLimitErrorUseCase: ShowMessageLimitErrorUseCase, private val schedulers: Schedulers diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt index 1d03760d3..c6197b488 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt @@ -5,7 +5,7 @@ import com.glia.androidsdk.chat.FilesAttachment import com.glia.androidsdk.chat.SendMessagePayload import com.glia.androidsdk.chat.VisitorMessage import com.glia.widgets.chat.data.GliaChatRepository -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.secureconversations.SecureConversationsRepository import com.glia.widgets.core.secureconversations.SendMessageRepository @@ -14,7 +14,7 @@ import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase internal class SendSecureMessageUseCase( private val sendMessageRepository: SendMessageRepository, private val secureConversationsRepository: SecureConversationsRepository, - private val fileAttachmentRepository: SecureFileAttachmentRepository, + private val fileAttachmentRepository: FileAttachmentRepository, private val chatRepository: GliaChatRepository, private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase ) { diff --git a/widgetssdk/src/main/java/com/glia/widgets/di/ControllerFactory.java b/widgetssdk/src/main/java/com/glia/widgets/di/ControllerFactory.java index 1dd23220e..9987244d9 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/di/ControllerFactory.java +++ b/widgetssdk/src/main/java/com/glia/widgets/di/ControllerFactory.java @@ -106,7 +106,6 @@ public ChatContract.Controller getChatController() { useCaseFactory.getEndEngagementUseCase(), useCaseFactory.createAddFileToAttachmentAndUploadUseCase(), useCaseFactory.createAddFileAttachmentsObserverUseCase(), - useCaseFactory.createRemoveFileAttachmentObserverUseCase(), useCaseFactory.createGetFileAttachmentsUseCase(), useCaseFactory.createRemoveFileAttachmentUseCase(), useCaseFactory.createSupportedFileCountCheckUseCase(), @@ -293,10 +292,10 @@ public CallVisualizerContract.Controller getCallVisualizerController() { public MessageCenterContract.Controller getMessageCenterController() { return new MessageCenterController( useCaseFactory.createSendSecureMessageUseCase(), - useCaseFactory.createAddSecureFileAttachmentsObserverUseCase(), + useCaseFactory.createAddFileAttachmentsObserverUseCase(), useCaseFactory.createAddSecureFileToAttachmentAndUploadUseCase(), - useCaseFactory.createGetSecureFileAttachmentsUseCase(), - useCaseFactory.createRemoveSecureFileAttachmentUseCase(), + useCaseFactory.createGetFileAttachmentsUseCase(), + useCaseFactory.createRemoveFileAttachmentUseCase(), useCaseFactory.createIsAuthenticatedUseCase(), useCaseFactory.createSiteInfoUseCase(), useCaseFactory.createOnNextMessageUseCase(), diff --git a/widgetssdk/src/main/java/com/glia/widgets/di/RepositoryFactory.java b/widgetssdk/src/main/java/com/glia/widgets/di/RepositoryFactory.java index 41edebc3c..e1bd407df 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/di/RepositoryFactory.java +++ b/widgetssdk/src/main/java/com/glia/widgets/di/RepositoryFactory.java @@ -7,7 +7,7 @@ import com.glia.widgets.core.engagement.GliaOperatorRepository; import com.glia.widgets.core.engagement.GliaOperatorRepositoryImpl; import com.glia.widgets.core.fileupload.FileAttachmentRepository; -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository; +import com.glia.widgets.core.fileupload.FileAttachmentRepositoryImpl; import com.glia.widgets.core.queue.QueueRepository; import com.glia.widgets.core.queue.QueueRepositoryImpl; import com.glia.widgets.core.secureconversations.SecureConversationsRepository; @@ -27,7 +27,6 @@ */ public class RepositoryFactory { private static SecureConversationsRepository secureConversationsRepository; - private static SecureFileAttachmentRepository secureFileAttachmentRepository; private static QueueRepository queueRepository; private static GliaFileRepository gliaFileRepository; private static FileAttachmentRepository fileAttachmentRepository; @@ -70,7 +69,7 @@ public QueueRepository getQueueRepository() { public FileAttachmentRepository getGliaFileAttachmentRepository() { if (fileAttachmentRepository == null) { - fileAttachmentRepository = new FileAttachmentRepository(gliaCore); + fileAttachmentRepository = new FileAttachmentRepositoryImpl(gliaCore); } return fileAttachmentRepository; } @@ -115,13 +114,6 @@ public SecureConversationsRepository getSecureConversationsRepository() { return secureConversationsRepository; } - public SecureFileAttachmentRepository getSecureFileAttachmentRepository() { - if (secureFileAttachmentRepository == null) { - secureFileAttachmentRepository = new SecureFileAttachmentRepository(gliaCore); - } - return secureFileAttachmentRepository; - } - public SendMessageRepository getSendMessageRepository() { if (sendMessageRepository == null) { sendMessageRepository = new SendMessageRepository(); diff --git a/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java b/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java index 3e3eee83d..f2656ea00 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java +++ b/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java @@ -83,7 +83,6 @@ import com.glia.widgets.core.fileupload.domain.AddFileAttachmentsObserverUseCase; import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase; import com.glia.widgets.core.fileupload.domain.GetFileAttachmentsUseCase; -import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentObserverUseCase; import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentUseCase; import com.glia.widgets.core.fileupload.domain.SupportedFileCountCheckUseCase; import com.glia.widgets.core.notification.device.INotificationManager; @@ -101,15 +100,12 @@ import com.glia.widgets.core.permissions.domain.WithNotificationPermissionUseCaseImpl; import com.glia.widgets.core.permissions.domain.WithReadWritePermissionsUseCase; import com.glia.widgets.core.permissions.domain.WithReadWritePermissionsUseCaseImpl; -import com.glia.widgets.core.secureconversations.domain.AddSecureFileAttachmentsObserverUseCase; import com.glia.widgets.core.secureconversations.domain.AddSecureFileToAttachmentAndUploadUseCase; -import com.glia.widgets.core.secureconversations.domain.GetSecureFileAttachmentsUseCase; import com.glia.widgets.core.secureconversations.domain.HasOngoingSecureConversationUseCase; import com.glia.widgets.core.secureconversations.domain.IsMessagingAvailableUseCase; import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase; import com.glia.widgets.core.secureconversations.domain.MarkMessagesReadWithDelayUseCase; import com.glia.widgets.core.secureconversations.domain.OnNextMessageUseCase; -import com.glia.widgets.core.secureconversations.domain.RemoveSecureFileAttachmentUseCase; import com.glia.widgets.core.secureconversations.domain.ResetMessageCenterUseCase; import com.glia.widgets.core.secureconversations.domain.SecureConversationTopBannerVisibilityUseCase; import com.glia.widgets.core.secureconversations.domain.SendMessageButtonStateUseCase; @@ -389,7 +385,10 @@ public ShouldShowMediaEngagementViewUseCase createShouldShowMediaEngagementViewU @NonNull public AddFileAttachmentsObserverUseCase createAddFileAttachmentsObserverUseCase() { - return new AddFileAttachmentsObserverUseCase(repositoryFactory.getGliaFileAttachmentRepository()); + return new AddFileAttachmentsObserverUseCase( + repositoryFactory.getGliaFileAttachmentRepository(), + schedulers + ); } @NonNull @@ -406,11 +405,6 @@ public GetFileAttachmentsUseCase createGetFileAttachmentsUseCase() { return new GetFileAttachmentsUseCase(repositoryFactory.getGliaFileAttachmentRepository()); } - @NonNull - public RemoveFileAttachmentObserverUseCase createRemoveFileAttachmentObserverUseCase() { - return new RemoveFileAttachmentObserverUseCase(repositoryFactory.getGliaFileAttachmentRepository()); - } - @NonNull public RemoveFileAttachmentUseCase createRemoveFileAttachmentUseCase() { return new RemoveFileAttachmentUseCase(repositoryFactory.getGliaFileAttachmentRepository()); @@ -478,7 +472,7 @@ public OnNextMessageUseCase createOnNextMessageUseCase() { public SendMessageButtonStateUseCase createEnableSendMessageButtonUseCase() { return new SendMessageButtonStateUseCase( repositoryFactory.getSendMessageRepository(), - repositoryFactory.getSecureFileAttachmentRepository(), + repositoryFactory.getGliaFileAttachmentRepository(), repositoryFactory.getSecureConversationsRepository(), createShowMessageLimitErrorUseCase(), schedulers @@ -496,7 +490,7 @@ public ShowMessageLimitErrorUseCase createShowMessageLimitErrorUseCase() { @NonNull public ResetMessageCenterUseCase createResetMessageCenterUseCase() { return new ResetMessageCenterUseCase( - repositoryFactory.getSecureFileAttachmentRepository(), + repositoryFactory.getGliaFileAttachmentRepository(), repositoryFactory.getSendMessageRepository() ); } @@ -551,7 +545,7 @@ public SendSecureMessageUseCase createSendSecureMessageUseCase() { return new SendSecureMessageUseCase( repositoryFactory.getSendMessageRepository(), repositoryFactory.getSecureConversationsRepository(), - repositoryFactory.getSecureFileAttachmentRepository(), + repositoryFactory.getGliaFileAttachmentRepository(), repositoryFactory.getGliaMessageRepository(), getIsQueueingOrEngagementUseCase() ); @@ -559,25 +553,7 @@ public SendSecureMessageUseCase createSendSecureMessageUseCase() { @NonNull public AddSecureFileToAttachmentAndUploadUseCase createAddSecureFileToAttachmentAndUploadUseCase() { - return new AddSecureFileToAttachmentAndUploadUseCase(repositoryFactory.getSecureFileAttachmentRepository()); - } - - @NonNull - public AddSecureFileAttachmentsObserverUseCase createAddSecureFileAttachmentsObserverUseCase() { - return new AddSecureFileAttachmentsObserverUseCase( - repositoryFactory.getSecureFileAttachmentRepository(), - schedulers - ); - } - - @NonNull - public GetSecureFileAttachmentsUseCase createGetSecureFileAttachmentsUseCase() { - return new GetSecureFileAttachmentsUseCase(repositoryFactory.getSecureFileAttachmentRepository()); - } - - @NonNull - public RemoveSecureFileAttachmentUseCase createRemoveSecureFileAttachmentUseCase() { - return new RemoveSecureFileAttachmentUseCase(repositoryFactory.getSecureFileAttachmentRepository()); + return new AddSecureFileToAttachmentAndUploadUseCase(repositoryFactory.getGliaFileAttachmentRepository()); } @NonNull diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/completion/EngagementCompletionController.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/completion/EngagementCompletionController.kt index 30441bccb..452cbf701 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/completion/EngagementCompletionController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/completion/EngagementCompletionController.kt @@ -1,6 +1,9 @@ package com.glia.widgets.engagement.completion import com.glia.widgets.engagement.State +import com.glia.widgets.engagement.State.StartedCallVisualizer +import com.glia.widgets.engagement.State.StartedOmniCore +import com.glia.widgets.engagement.State.Update import com.glia.widgets.engagement.SurveyState import com.glia.widgets.engagement.domain.EngagementStateUseCase import com.glia.widgets.engagement.domain.ReleaseResourcesUseCase diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/ReleaseResourcesUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/ReleaseResourcesUseCase.kt index 9c4569f59..f6857f343 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/ReleaseResourcesUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/ReleaseResourcesUseCase.kt @@ -19,7 +19,6 @@ internal class ReleaseResourcesUseCaseImpl( ) : ReleaseResourcesUseCase { override fun invoke() { dialogController.dismissDialogs() - fileAttachmentRepository.clearObservers() fileAttachmentRepository.detachAllFiles() releaseScreenSharingResourcesUseCase() callNotificationUseCase.removeAllNotifications() diff --git a/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageCenterController.kt b/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageCenterController.kt index 74b148d86..fc0639af4 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageCenterController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageCenterController.kt @@ -12,15 +12,15 @@ import com.glia.widgets.chat.domain.SiteInfoUseCase import com.glia.widgets.chat.domain.TakePictureUseCase import com.glia.widgets.chat.domain.UriToFileAttachmentUseCase import com.glia.widgets.core.dialog.DialogContract +import com.glia.widgets.core.fileupload.domain.AddFileAttachmentsObserverUseCase import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase +import com.glia.widgets.core.fileupload.domain.GetFileAttachmentsUseCase +import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentUseCase import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.permissions.domain.RequestNotificationPermissionIfPushNotificationsSetUpUseCase -import com.glia.widgets.core.secureconversations.domain.AddSecureFileAttachmentsObserverUseCase import com.glia.widgets.core.secureconversations.domain.AddSecureFileToAttachmentAndUploadUseCase -import com.glia.widgets.core.secureconversations.domain.GetSecureFileAttachmentsUseCase import com.glia.widgets.core.secureconversations.domain.IsMessagingAvailableUseCase import com.glia.widgets.core.secureconversations.domain.OnNextMessageUseCase -import com.glia.widgets.core.secureconversations.domain.RemoveSecureFileAttachmentUseCase import com.glia.widgets.core.secureconversations.domain.ResetMessageCenterUseCase import com.glia.widgets.core.secureconversations.domain.SendMessageButtonStateUseCase import com.glia.widgets.core.secureconversations.domain.SendSecureMessageUseCase @@ -31,10 +31,10 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable internal class MessageCenterController( private val sendSecureMessageUseCase: SendSecureMessageUseCase, - private val addFileAttachmentsObserverUseCase: AddSecureFileAttachmentsObserverUseCase, + private val addFileAttachmentsObserverUseCase: AddFileAttachmentsObserverUseCase, private val addFileToAttachmentAndUploadUseCase: AddSecureFileToAttachmentAndUploadUseCase, - private val getFileAttachmentsUseCase: GetSecureFileAttachmentsUseCase, - private val removeFileAttachmentUseCase: RemoveSecureFileAttachmentUseCase, + private val getFileAttachmentsUseCase: GetFileAttachmentsUseCase, + private val removeFileAttachmentUseCase: RemoveFileAttachmentUseCase, private val isAuthenticatedUseCase: IsAuthenticatedUseCase, private val siteInfoUseCase: SiteInfoUseCase, private val onNextMessageUseCase: OnNextMessageUseCase, @@ -200,7 +200,7 @@ internal class MessageCenterController( } fun onAttachmentReceived(file: LocalAttachment) { - addFileToAttachmentAndUploadUseCase.execute( + addFileToAttachmentAndUploadUseCase( file, object : AddFileToAttachmentAndUploadUseCase.Listener { override fun onFinished() { @@ -229,7 +229,7 @@ internal class MessageCenterController( } override fun onRemoveAttachment(file: LocalAttachment) { - removeFileAttachmentUseCase.execute(file) + removeFileAttachmentUseCase(file) } override fun onDestroy() { diff --git a/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt b/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt index 90d8bc979..833b21c8f 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt @@ -30,7 +30,6 @@ import com.glia.widgets.core.engagement.domain.UpdateOperatorDefaultImageUrlUseC import com.glia.widgets.core.fileupload.domain.AddFileAttachmentsObserverUseCase import com.glia.widgets.core.fileupload.domain.AddFileToAttachmentAndUploadUseCase import com.glia.widgets.core.fileupload.domain.GetFileAttachmentsUseCase -import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentObserverUseCase import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentUseCase import com.glia.widgets.core.fileupload.domain.SupportedFileCountCheckUseCase import com.glia.widgets.core.notification.domain.CallNotificationUseCase @@ -91,7 +90,6 @@ class ChatControllerTest { private lateinit var sendMessageUseCase: GliaSendMessageUseCase private lateinit var addFileToAttachmentAndUploadUseCase: AddFileToAttachmentAndUploadUseCase private lateinit var addFileAttachmentsObserverUseCase: AddFileAttachmentsObserverUseCase - private lateinit var removeFileAttachmentObserverUseCase: RemoveFileAttachmentObserverUseCase private lateinit var getFileAttachmentsUseCase: GetFileAttachmentsUseCase private lateinit var removeFileAttachmentUseCase: RemoveFileAttachmentUseCase private lateinit var supportedFileCountCheckUseCase: SupportedFileCountCheckUseCase @@ -147,7 +145,6 @@ class ChatControllerTest { sendMessageUseCase = mock() addFileToAttachmentAndUploadUseCase = mock() addFileAttachmentsObserverUseCase = mock() - removeFileAttachmentObserverUseCase = mock() getFileAttachmentsUseCase = mock() removeFileAttachmentUseCase = mock() supportedFileCountCheckUseCase = mock() @@ -212,7 +209,6 @@ class ChatControllerTest { sendMessageUseCase = sendMessageUseCase, addFileToAttachmentAndUploadUseCase = addFileToAttachmentAndUploadUseCase, addFileAttachmentsObserverUseCase = addFileAttachmentsObserverUseCase, - removeFileAttachmentObserverUseCase = removeFileAttachmentObserverUseCase, getFileAttachmentsUseCase = getFileAttachmentsUseCase, removeFileAttachmentUseCase = removeFileAttachmentUseCase, supportedFileCountCheckUseCase = supportedFileCountCheckUseCase, diff --git a/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt index 1e660c9f0..8e4c02eb7 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt @@ -34,7 +34,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if ongoing engagement and the message empty and files are not ready to send`() { whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn emptyList() val result = useCase("") @@ -44,7 +44,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is not empty and files are not ready to send`() { whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn emptyList() val result = useCase("test") @@ -54,7 +54,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is empty and files are ready to send`() { whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn listOf(mock()) val result = useCase("") @@ -64,7 +64,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is not empty and files are ready to send`() { whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn listOf(mock()) val result = useCase("test") @@ -74,7 +74,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if no ongoing engagement and files are ready to send`() { whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn false - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn listOf(mock()) val result = useCase("") @@ -84,7 +84,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if secure engagement and the message empty and files are not ready to send`() { whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn emptyList() val result = useCase("") @@ -94,7 +94,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is not empty and files are not ready to send`() { whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn emptyList() val result = useCase("test") @@ -104,7 +104,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is empty and files are ready to send`() { whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn listOf(mock()) val result = useCase("") @@ -114,7 +114,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is not empty and files are ready to send`() { whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true - whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) + whenever(fileAttachmentRepository.getReadyToSendFileAttachments()) doReturn listOf(mock()) val result = useCase("test") diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/FileAttachmentRepositoryTest.kt b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/FileAttachmentRepositoryTest.kt index acd6972da..087c124f5 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/FileAttachmentRepositoryTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/FileAttachmentRepositoryTest.kt @@ -58,13 +58,13 @@ class LocalAttachmentRepositoryTest { observer2 = mockk(relaxUnitFun = true) every { gliaCore.secureConversations } returns secureConversations - subjectUnderTest = FileAttachmentRepository(gliaCore) + subjectUnderTest = FileAttachmentRepositoryImpl(gliaCore) } @Test fun `getAttachedFilesCount returns zero when no file attachments attached`() { subjectUnderTest.detachAllFiles() - val result = subjectUnderTest.attachedFilesCount + val result = subjectUnderTest.getAttachedFilesCount() assertEquals(0, result) } @@ -72,7 +72,7 @@ class LocalAttachmentRepositoryTest { fun `getAttachedFilesCount returns one when one file attachment attached`() { subjectUnderTest.detachAllFiles() subjectUnderTest.attachFile(fileAttachment1) - val result = subjectUnderTest.attachedFilesCount + val result = subjectUnderTest.getAttachedFilesCount() assertEquals(1, result) } @@ -95,7 +95,7 @@ class LocalAttachmentRepositoryTest { fun `attachFile attaches file attachment when valid argument`() { subjectUnderTest.detachAllFiles() subjectUnderTest.attachFile(fileAttachment1) - val result = subjectUnderTest.localAttachments + val result = subjectUnderTest.getFileAttachments() assertTrue(result.contains(fileAttachment1)) } @@ -115,7 +115,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.uploadFile(false, fileAttachment1, listener) verify { listener.onFinished() } - assertEquals(LocalAttachment.Status.READY_TO_SEND, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.READY_TO_SEND, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -134,14 +134,14 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.attachFile(fileAttachment1) subjectUnderTest.uploadFile(false, fileAttachment1, listener) - assertEquals(LocalAttachment.Status.SECURITY_SCAN, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.SECURITY_SCAN, subjectUnderTest.getFileAttachments().first().attachmentStatus) verify { engagementFile.on(eq(EngagementFile.Events.SCAN_RESULT), capture(fileScanCallbackSlot)) } verify { listener.onSecurityCheckStarted() } fileScanCallbackSlot.captured.accept(EngagementFile.ScanResult.CLEAN) verify { listener.onSecurityCheckFinished(EngagementFile.ScanResult.CLEAN) } verify { listener.onFinished() } - assertEquals(LocalAttachment.Status.READY_TO_SEND, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.READY_TO_SEND, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -154,7 +154,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.uploadFile(false, fileAttachment1, listener) verify { listener.onError(any()) } - assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -171,7 +171,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.uploadFile(false, fileAttachment1, listener) verify { listener.onError(gliaException) } - assertEquals(LocalAttachment.Status.ERROR_INTERNAL, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.ERROR_INTERNAL, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -198,7 +198,7 @@ class LocalAttachmentRepositoryTest { verify { listener.onSecurityCheckFinished(EngagementFile.ScanResult.INFECTED) } verify { listener.onFinished() } - assertEquals(LocalAttachment.Status.ERROR_SECURITY_SCAN_FAILED, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.ERROR_SECURITY_SCAN_FAILED, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -209,7 +209,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.attachFile(fileAttachment1) subjectUnderTest.uploadFile(false, fileAttachment1, listener) - assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.getFileAttachments().first().attachmentStatus) verify { listener.onError(any()) } } @@ -231,7 +231,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.setFileAttachmentTooLarge(uri1) - subjectUnderTest.localAttachments.forEach { + subjectUnderTest.getFileAttachments().forEach { if (it.uri == uri1) { assertEquals(LocalAttachment.Status.ERROR_FILE_TOO_LARGE, it.attachmentStatus) } else { @@ -249,7 +249,7 @@ class LocalAttachmentRepositoryTest { assertEquals( LocalAttachment.Status.ERROR_SUPPORTED_FILE_ATTACHMENT_COUNT_EXCEEDED, - subjectUnderTest.localAttachments.first().attachmentStatus + subjectUnderTest.getFileAttachments().first().attachmentStatus ) } @@ -260,7 +260,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.setFileAttachmentEngagementMissing(uri1) - assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.localAttachments.first().attachmentStatus) + assertEquals(LocalAttachment.Status.ERROR_ENGAGEMENT_MISSING, subjectUnderTest.getFileAttachments().first().attachmentStatus) } @Test @@ -268,7 +268,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachAllFiles() subjectUnderTest.attachFile(fileAttachment1) subjectUnderTest.attachFile(fileAttachment2) - val result = subjectUnderTest.localAttachments + val result = subjectUnderTest.getFileAttachments() assertTrue(result.containsAll(listOf(fileAttachment1, fileAttachment2))) } @@ -277,7 +277,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachAllFiles() subjectUnderTest.attachFile(fileAttachment1) subjectUnderTest.attachFile(fileAttachment1) - val result = subjectUnderTest.localAttachments + val result = subjectUnderTest.getFileAttachments() assertTrue(result.indexOf(fileAttachment1) != result.lastIndexOf(fileAttachment1)) } @@ -289,7 +289,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachFile(fileAttachment1) - val result = subjectUnderTest.localAttachments + val result = subjectUnderTest.getFileAttachments() assertFalse(result.contains(fileAttachment1)) assertTrue(result.contains(fileAttachment2)) @@ -303,7 +303,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachFile(fileAttachment1) - assertTrue(subjectUnderTest.localAttachments.isEmpty()) + assertTrue(subjectUnderTest.getFileAttachments().isEmpty()) } @Test @@ -312,7 +312,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachFile(fileAttachment1) - assertFalse(subjectUnderTest.localAttachments.contains(fileAttachment1)) + assertFalse(subjectUnderTest.getFileAttachments().contains(fileAttachment1)) } @Test @@ -324,79 +324,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachAllFiles() - assertTrue(subjectUnderTest.localAttachments.isEmpty()) - } - - @Test - fun `addObserver successful when valid argument`() { - clearMocks(observer1) - subjectUnderTest.clearObservers() - - subjectUnderTest.addObserver(observer1) - - subjectUnderTest.detachAllFiles() - verify { observer1.update(any(), any()) } - } - - @Test - fun `addObserver calls update once when same observer added twice`() { - clearMocks(observer1) - subjectUnderTest.clearObservers() - - subjectUnderTest.addObserver(observer1) - subjectUnderTest.addObserver(observer1) - - subjectUnderTest.detachAllFiles() - verify(exactly = 1) { observer1.update(any(), any()) } - } - - @Test(expected = NullPointerException::class) - fun `addObserver throws when null argument`() { - subjectUnderTest.addObserver(null) - } - - @Test - fun `removeObserver removes when valid argument`() { - clearMocks(observer1) - subjectUnderTest.clearObservers() - subjectUnderTest.addObserver(observer1) - - subjectUnderTest.removeObserver(observer1) - - subjectUnderTest.detachAllFiles() - verify(exactly = 0) { observer1.update(any(), any()) } - } - - @Test - fun `removeObserver does nothing when observer not added`() { - subjectUnderTest.clearObservers() - - subjectUnderTest.removeObserver(observer1) - } - - @Test - fun `removeObserver not throwing when null argument`() { - subjectUnderTest.removeObserver(null) - } - - @Test - fun `clearObservers clears when observers added`() { - clearMocks(observer1, observer2) - subjectUnderTest.clearObservers() - subjectUnderTest.addObserver(observer1) - subjectUnderTest.addObserver(observer2) - - subjectUnderTest.clearObservers() - - subjectUnderTest.detachAllFiles() - verify(exactly = 0) { observer1.update(any(), any()) } - verify(exactly = 0) { observer2.update(any(), any()) } - } - - @Test - fun `clearObservers does nothing when no observers added`() { - subjectUnderTest.clearObservers() - subjectUnderTest.clearObservers() + assertTrue(subjectUnderTest.getFileAttachments().isEmpty()) } @Test @@ -404,7 +332,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.detachAllFiles() subjectUnderTest.detachAllFiles() - assertTrue(subjectUnderTest.localAttachments.isEmpty()) + assertTrue(subjectUnderTest.getFileAttachments().isEmpty()) } @Test @@ -415,7 +343,7 @@ class LocalAttachmentRepositoryTest { subjectUnderTest.attachFile(attachment1) subjectUnderTest.attachFile(attachment2) - val result = subjectUnderTest.readyToSendLocalAttachments + val result = subjectUnderTest.getReadyToSendFileAttachments() assertTrue(result.contains(attachment1)) assertFalse(result.contains(attachment2)) diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt index fe2478910..b65d6bef4 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt @@ -34,85 +34,85 @@ class AddFileToAttachmentAndUploadUseCaseTest { } @Test - fun `execute calls onError with RemoveBeforeReUploadingException when file is already attached`() { + fun `invoke calls onError with RemoveBeforeReUploadingException when file is already attached`() { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns true - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { listener.onError(any()) } } @Test - fun `execute calls onError with EngagementMissingException when engagement is missing`() { + fun `invoke calls onError with EngagementMissingException when engagement is missing`() { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns false every { manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging } returns false - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { listener.onError(any()) } } @Test - fun `execute calls onError with SupportedFileCountExceededException when too many files are attached`() { + fun `invoke calls onError with SupportedFileCountExceededException when too many files are attached`() { val localAttachment = mockk() every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - 1 val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false - every { fileAttachmentRepository.attachedFilesCount } returns SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT + 1 + every { fileAttachmentRepository.getAttachedFilesCount() } returns SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT + 1 every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns false - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { listener.onError(any()) } } @Test - fun `execute calls onError with SupportedFileSizeExceededException when file size is too large`() { + fun `invoke calls onError with SupportedFileSizeExceededException when file size is too large`() { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false - every { fileAttachmentRepository.attachedFilesCount } returns 1L + every { fileAttachmentRepository.getAttachedFilesCount() } returns 1 every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { listener.onError(any()) } } @Test - fun `execute calls onStarted when valid argument`() { + fun `invoke calls onStarted when valid argument`() { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false - every { fileAttachmentRepository.attachedFilesCount } returns 1L + every { fileAttachmentRepository.getAttachedFilesCount() } returns 1 every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - 1 every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns false - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { listener.onStarted() } } @Test - fun `execute uploads file when is secure engagement`() { + fun `invoke uploads file when is secure engagement`() { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns false - every { fileAttachmentRepository.attachedFilesCount } returns 1L + every { fileAttachmentRepository.getAttachedFilesCount() } returns 1 every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - 1 every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns true every { manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging } returns true - subjectUnderTest.execute(localAttachment, listener) + subjectUnderTest.invoke(localAttachment, listener) verify { fileAttachmentRepository.uploadFile(true, localAttachment, listener) } } diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddSecureLocalAttachmentsObserverUseCaseTest.java b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddSecureLocalAttachmentsObserverUseCaseTest.java index a975a14b3..5734a769b 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddSecureLocalAttachmentsObserverUseCaseTest.java +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddSecureLocalAttachmentsObserverUseCaseTest.java @@ -2,13 +2,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.glia.widgets.core.fileupload.FileAttachmentRepository; +import com.glia.widgets.helper.rx.Schedulers; import org.junit.Before; import org.junit.Test; -import java.util.Observer; +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.Scheduler; public class AddSecureLocalAttachmentsObserverUseCaseTest { @@ -18,19 +21,17 @@ public class AddSecureLocalAttachmentsObserverUseCaseTest { @Before public void setUp() { repository = mock(FileAttachmentRepository.class); - subjectUnderTest = new AddFileAttachmentsObserverUseCase(repository); + Schedulers schedulers = mock(); + Scheduler scheduler = mock(); + when(schedulers.getMainScheduler()).thenReturn(scheduler); + when(schedulers.getComputationScheduler()).thenReturn(scheduler); + subjectUnderTest = new AddFileAttachmentsObserverUseCase(repository, schedulers); } @Test - public void execute_callsRepositoryAddObserver_whenValidArgument() { - Observer observer = mock(Observer.class); - subjectUnderTest.execute(observer); - verify(repository).addObserver(observer); - } - - @Test - public void execute_callsRepositoryAddObserver_whenNullArgument() { - subjectUnderTest.execute(null); - verify(repository).addObserver(null); + public void execute_callsRepositoryObserver_whenTriggered() { + when(repository.getObservable()).thenReturn(Observable.empty()); + subjectUnderTest.invoke(); + verify(repository).getObservable(); } } diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/GetLocalAttachmentsUseCaseTest.java b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/GetLocalAttachmentsUseCaseTest.java index d64783e54..27402f14f 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/GetLocalAttachmentsUseCaseTest.java +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/GetLocalAttachmentsUseCaseTest.java @@ -28,7 +28,7 @@ public void setUp() { public void execute_returnsFileAttachments_whenSingleFileAttachment() { List localAttachments = Collections.singletonList(mock(LocalAttachment.class)); - when(repository.getLocalAttachments()).thenReturn(localAttachments); + when(repository.getFileAttachments()).thenReturn(localAttachments); List result = subjectUnderTest.invoke(); diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentObserverUseCaseTest.java b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentObserverUseCaseTest.java deleted file mode 100644 index 2fb084177..000000000 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentObserverUseCaseTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.glia.widgets.core.fileupload.domain; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import com.glia.widgets.core.fileupload.FileAttachmentRepository; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Observer; - -public class RemoveLocalAttachmentObserverUseCaseTest { - - private FileAttachmentRepository repository; - private RemoveFileAttachmentObserverUseCase subjectUnderTest; - - @Before - public void setUp() { - repository = mock(FileAttachmentRepository.class); - subjectUnderTest = new RemoveFileAttachmentObserverUseCase(repository); - } - - @Test - public void execute_callsRepositoryRemoveObserver_whenValidArgument() { - Observer observer = mock(Observer.class); - subjectUnderTest.invoke(observer); - verify(repository).removeObserver(observer); - } - - @Test - public void execute_callsRepositoryRemoveObserver_whenNullArgument() { - subjectUnderTest.invoke(null); - verify(repository).removeObserver(null); - } -} diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentUseCaseTest.java b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentUseCaseTest.java index 362e6b4de..c6b010f66 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentUseCaseTest.java +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/RemoveLocalAttachmentUseCaseTest.java @@ -28,11 +28,4 @@ public void execute_callsRepositoryDetachFile_whenValidArgument() { verify(repository).detachFile(localAttachment); } - - @Test - public void execute_callsRepositoryDetachFile_whenNullArgument() { - subjectUnderTest.invoke(null); - - verify(repository).detachFile(null); - } } diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCaseTest.java b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCaseTest.java index a497f0f80..1ab6a6e5a 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCaseTest.java +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/SupportedFileCountCheckUseCaseTest.java @@ -7,15 +7,10 @@ import static org.mockito.Mockito.when; import com.glia.widgets.core.fileupload.FileAttachmentRepository; -import com.glia.widgets.core.fileupload.model.LocalAttachment; import org.junit.Before; import org.junit.Test; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class SupportedFileCountCheckUseCaseTest { private FileAttachmentRepository repository; @@ -27,42 +22,30 @@ public void setUp() { subjectUnderTest = new SupportedFileCountCheckUseCase(repository); } - private static final LocalAttachment FILE_ATTACHMENT = mock(LocalAttachment.class); - @Test public void execute_returnsTrue_whenSingleFileAttachment() { - when(repository.getLocalAttachments()) - .thenReturn(Collections.singletonList(FILE_ATTACHMENT)); + when(repository.getAttachedFilesCount()).thenReturn(1); assertTrue(subjectUnderTest.invoke()); } @Test public void execute_returnsTrue_whenNoFileAttachment() { - when(repository.getLocalAttachments()) - .thenReturn(Collections.emptyList()); + when(repository.getAttachedFilesCount()).thenReturn(0); assertTrue(subjectUnderTest.invoke()); } @Test public void execute_returnsTrue_whenSupportedFileAttachmentsCount() { - List localAttachmentList = new ArrayList<>(); - for (int i = 0; i < SUPPORTED_FILE_COUNT; i++) { - localAttachmentList.add(FILE_ATTACHMENT); - } - when(repository.getLocalAttachments()).thenReturn(localAttachmentList); + when(repository.getAttachedFilesCount()).thenReturn(SUPPORTED_FILE_COUNT); assertTrue(subjectUnderTest.invoke()); } @Test public void execute_returnsFalse_whenMoreThanSupportedFileAttachments() { - List localAttachmentList = new ArrayList<>(); - for (int i = 0; i < SUPPORTED_FILE_COUNT + 1; i++) { - localAttachmentList.add(FILE_ATTACHMENT); - } - when(repository.getLocalAttachments()).thenReturn(localAttachmentList); + when(repository.getAttachedFilesCount()).thenReturn(SUPPORTED_FILE_COUNT + 1); assertFalse(subjectUnderTest.invoke()); } diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonDialogStateUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonDialogStateUseCaseTest.kt index cc8218de9..3eb9777ab 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonDialogStateUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/SendMessageButtonDialogStateUseCaseTest.kt @@ -1,6 +1,6 @@ package com.glia.widgets.core.secureconversations.domain -import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository +import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.secureconversations.SecureConversationsRepository import com.glia.widgets.core.secureconversations.SendMessageRepository @@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit class SendMessageButtonDialogStateUseCaseTest { private lateinit var sendMessageRepository: SendMessageRepository - private lateinit var fileAttachmentRepository: SecureFileAttachmentRepository + private lateinit var fileAttachmentRepository: FileAttachmentRepository private lateinit var secureConversationsRepository: SecureConversationsRepository private lateinit var showMessageLimitErrorUseCase: ShowMessageLimitErrorUseCase private lateinit var testScheduler: TestScheduler diff --git a/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt b/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt index dedce5011..5be0bc723 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt @@ -492,7 +492,6 @@ class EngagementDomainTest { verifyOrder { dialogController.dismissDialogs() - fileAttachmentRepository.clearObservers() fileAttachmentRepository.detachAllFiles() releaseScreenSharingResourcesUseCase() callNotificationUseCase.removeAllNotifications() diff --git a/widgetssdk/src/test/java/com/glia/widgets/messagecenter/MessageCenterControllerTest.kt b/widgetssdk/src/test/java/com/glia/widgets/messagecenter/MessageCenterControllerTest.kt index a8e6d8d65..46fe7f3ba 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/messagecenter/MessageCenterControllerTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/messagecenter/MessageCenterControllerTest.kt @@ -6,14 +6,14 @@ import com.glia.widgets.chat.domain.SiteInfoUseCase import com.glia.widgets.chat.domain.TakePictureUseCase import com.glia.widgets.chat.domain.UriToFileAttachmentUseCase import com.glia.widgets.core.dialog.DialogContract +import com.glia.widgets.core.fileupload.domain.AddFileAttachmentsObserverUseCase +import com.glia.widgets.core.fileupload.domain.GetFileAttachmentsUseCase +import com.glia.widgets.core.fileupload.domain.RemoveFileAttachmentUseCase import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.permissions.domain.RequestNotificationPermissionIfPushNotificationsSetUpUseCase -import com.glia.widgets.core.secureconversations.domain.AddSecureFileAttachmentsObserverUseCase import com.glia.widgets.core.secureconversations.domain.AddSecureFileToAttachmentAndUploadUseCase -import com.glia.widgets.core.secureconversations.domain.GetSecureFileAttachmentsUseCase import com.glia.widgets.core.secureconversations.domain.IsMessagingAvailableUseCase import com.glia.widgets.core.secureconversations.domain.OnNextMessageUseCase -import com.glia.widgets.core.secureconversations.domain.RemoveSecureFileAttachmentUseCase import com.glia.widgets.core.secureconversations.domain.ResetMessageCenterUseCase import com.glia.widgets.core.secureconversations.domain.SendMessageButtonStateUseCase import com.glia.widgets.core.secureconversations.domain.SendSecureMessageUseCase @@ -35,10 +35,10 @@ import org.mockito.kotlin.whenever internal class MessageCenterControllerTest { private lateinit var messageCenterController: MessageCenterController private lateinit var sendSecureMessageUseCase: SendSecureMessageUseCase - private lateinit var addFileAttachmentsObserverUseCase: AddSecureFileAttachmentsObserverUseCase + private lateinit var addFileAttachmentsObserverUseCase: AddFileAttachmentsObserverUseCase private lateinit var addFileToAttachmentAndUploadUseCase: AddSecureFileToAttachmentAndUploadUseCase - private lateinit var getFileAttachmentsUseCase: GetSecureFileAttachmentsUseCase - private lateinit var removeFileAttachmentUseCase: RemoveSecureFileAttachmentUseCase + private lateinit var getFileAttachmentsUseCase: GetFileAttachmentsUseCase + private lateinit var removeFileAttachmentUseCase: RemoveFileAttachmentUseCase private lateinit var siteInfoUseCase: SiteInfoUseCase private lateinit var isAuthenticatedUseCase: IsAuthenticatedUseCase private lateinit var viewContract: MessageCenterContract.View @@ -201,14 +201,14 @@ internal class MessageCenterControllerTest { fun onAttachmentReceived_ExecutesAddSecureFileToAttachmentAndUploadUseCase_onTrigger() { val localAttachment = mock() messageCenterController.onAttachmentReceived(localAttachment) - verify(addFileToAttachmentAndUploadUseCase, times(1)).execute(eq(localAttachment), any()) + verify(addFileToAttachmentAndUploadUseCase, times(1)).invoke(eq(localAttachment), any()) } @Test fun onRemoveAttachment() { val localAttachment = mock() messageCenterController.onRemoveAttachment(localAttachment) - verify(removeFileAttachmentUseCase, times(1)).execute(eq(localAttachment)) + verify(removeFileAttachmentUseCase, times(1)).invoke(eq(localAttachment)) } @Test