diff --git a/jami-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.kt b/jami-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.kt index fa8eb7fd10c53a9b46ba3a82d1cf4461b07d6069..692199330abbca1012027e70d6210fd58ec22971 100644 --- a/jami-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.kt +++ b/jami-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.kt @@ -80,7 +80,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers import net.jami.conversation.ConversationPresenter import net.jami.model.* import net.jami.model.Account.ComposingStatus -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.utils.Log import net.jami.utils.StringUtils import org.commonmark.node.SoftLineBreak @@ -1068,9 +1068,9 @@ class ConversationAdapter( val timeString = TextUtils.timestampToTime(context, formatter, file.timestamp) viewHolder.mFileTime?.text = timeString viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe { - viewHolder.mFileSize?.text = when (val status = file.status) { - InteractionStatus.TRANSFER_FINISHED -> Formatter.formatFileSize(context, file.totalSize) - InteractionStatus.TRANSFER_ONGOING -> String.format("%s / %s - %s", + viewHolder.mFileSize?.text = when (val status = file.transferStatus) { + TransferStatus.TRANSFER_FINISHED -> Formatter.formatFileSize(context, file.totalSize) + TransferStatus.TRANSFER_ONGOING -> String.format("%s / %s - %s", Formatter.formatFileSize(context, file.bytesProgress), Formatter.formatFileSize(context, file.totalSize), TextUtils.getReadableFileTransferStatus(context, status) @@ -1180,7 +1180,7 @@ class ConversationAdapter( .getDimensionPixelSize(R.dimen.conversation_message_separation) } - val status = file.status + val status = file.transferStatus viewHolder.mIcon?.setPadding(res.getDimensionPixelSize(R.dimen.padding_large)) viewHolder.mIcon?.setClipToOutline(true) viewHolder.mIcon?.imageTintList = context.getColorStateList(R.color.file_icon_out) @@ -1195,7 +1195,7 @@ class ConversationAdapter( if (file.isOutgoing) viewHolder.mFileInfoLayout?.background?.setTint(convColor) // Show the download button when (status) { - InteractionStatus.TRANSFER_AWAITING_HOST, InteractionStatus.FILE_AVAILABLE -> { + TransferStatus.TRANSFER_AWAITING_HOST, TransferStatus.FILE_AVAILABLE -> { viewHolder.mFileDownloadButton?.let { it.visibility = View.VISIBLE it.setOnClickListener { presenter.acceptFile(file) } @@ -1204,7 +1204,7 @@ class ConversationAdapter( else -> { viewHolder.mFileDownloadButton?.visibility = View.GONE - if (status == InteractionStatus.TRANSFER_ONGOING) { + if (status == TransferStatus.TRANSFER_ONGOING) { viewHolder.progress?.max = (file.totalSize / 1024).toInt() viewHolder.progress?.setProgress((file.bytesProgress / 1024).toInt(), true) viewHolder.progress?.show() @@ -1590,7 +1590,7 @@ class ConversationAdapter( convViewHolder.mCallInfoLayout?.apply { background?.setTintList(null) // Remove the tint - TODO("define popup menu to invoke in onLongClickListener") + //TODO define popup menu to invoke in onLongClickListener // setOnLongClickListener { // background?.setTint(context.getColor(R.color.grey_500)) // false diff --git a/jami-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.kt b/jami-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.kt index d987332525a7d584eb4477e08e5e2d8946646e07..68bcc53664a03c7ba599e39afea91ee2075a1829 100644 --- a/jami-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.kt +++ b/jami-android/app/src/main/java/cx/ring/services/NotificationServiceImpl.kt @@ -64,7 +64,7 @@ import cx.ring.views.AvatarFactory.toBitmap import io.reactivex.rxjava3.schedulers.Schedulers import net.jami.call.CallPresenter import net.jami.model.* -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.services.* import net.jami.smartlist.ConversationItemViewModel import java.io.BufferedInputStream @@ -743,8 +743,8 @@ class NotificationServiceImpl( @SuppressLint("RestrictedApi") override fun showFileTransferNotification(conversation: Conversation, info: DataTransfer) { - val event = info.status - if (event == InteractionStatus.FILE_AVAILABLE) + val event = info.transferStatus + if (event == TransferStatus.FILE_AVAILABLE) return val path = ConversationPath.toUri(conversation) Log.d(TAG, "showFileTransferNotification $path") @@ -790,7 +790,7 @@ class NotificationServiceImpl( val messageNotificationBuilder = mNotificationBuilders[notificationId] ?: NotificationCompat.Builder(mContext, NOTIF_CHANNEL_FILE_TRANSFER).apply { mNotificationBuilders.put(notificationId, this) } - val ongoing = event == InteractionStatus.TRANSFER_ONGOING || event == InteractionStatus.TRANSFER_ACCEPTED + val ongoing = event == TransferStatus.TRANSFER_ONGOING || event == TransferStatus.TRANSFER_ACCEPTED messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_incoming_file_transfer_title, author.displayName)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) @@ -800,7 +800,7 @@ class NotificationServiceImpl( .setCategory(NotificationCompat.CATEGORY_PROGRESS) .setOnlyAlertOnce(true) .setContentText( - if (event == InteractionStatus.TRANSFER_ONGOING) + if (event == TransferStatus.TRANSFER_ONGOING) Formatter.formatFileSize(mContext, info.bytesProgress) + " / " + Formatter.formatFileSize(mContext, info.totalSize) else info.displayName + ": " + cx.ring.utils.TextUtils.getReadableFileTransferStatus(mContext, event) @@ -814,7 +814,7 @@ class NotificationServiceImpl( ongoing -> messageNotificationBuilder.setProgress(info.totalSize.toInt(), info.bytesProgress.toInt(), false) else -> messageNotificationBuilder.setProgress(0, 0, true) } - if (event == InteractionStatus.TRANSFER_CREATED) { + if (event == TransferStatus.TRANSFER_CREATED) { messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE) mNotificationBuilders.put(notificationId, messageNotificationBuilder) // updateNotification(messageNotificationBuilder.build(), notificationId); @@ -823,7 +823,7 @@ class NotificationServiceImpl( messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_LIGHTS) } messageNotificationBuilder.mActions.clear() - if (event == InteractionStatus.TRANSFER_AWAITING_HOST) { + if (event == TransferStatus.TRANSFER_AWAITING_HOST) { messageNotificationBuilder .addAction(R.drawable.baseline_call_received_24, mContext.getText(R.string.accept), PendingIntent.getService(mContext, random.nextInt(), diff --git a/jami-android/app/src/main/java/cx/ring/tv/conversation/TvConversationAdapter.kt b/jami-android/app/src/main/java/cx/ring/tv/conversation/TvConversationAdapter.kt index 3dab7b544713942dd45ee08f6965917e3bb9d6cb..078f6c2703dc7bf10663ba7917f2593ad6e84bf3 100644 --- a/jami-android/app/src/main/java/cx/ring/tv/conversation/TvConversationAdapter.kt +++ b/jami-android/app/src/main/java/cx/ring/tv/conversation/TvConversationAdapter.kt @@ -69,6 +69,7 @@ import net.jami.model.ContactEvent import net.jami.model.DataTransfer import net.jami.model.Interaction import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.model.TextMessage import net.jami.utils.StringUtils.isOnlyEmoji import java.io.File @@ -532,12 +533,12 @@ class TvConversationAdapter( val timeString = TextUtils.timestampToDetailString(context, formatter, file.timestamp) viewHolder.mFileTime?.text = timeString viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe { - viewHolder.mFileSize?.text = when (val status = file.status) { - InteractionStatus.TRANSFER_FINISHED -> String.format("%s - %s", + viewHolder.mFileSize?.text = when (val status = file.transferStatus) { + TransferStatus.TRANSFER_FINISHED -> String.format("%s - %s", Formatter.formatFileSize(context, file.totalSize), TextUtils.getReadableFileTransferStatus(context, status) ) - InteractionStatus.TRANSFER_ONGOING -> String.format("%s / %s - %s", + TransferStatus.TRANSFER_ONGOING -> String.format("%s / %s - %s", Formatter.formatFileSize(context, file.bytesProgress), Formatter.formatFileSize(context, file.totalSize), TextUtils.getReadableFileTransferStatus(context, status)) @@ -618,7 +619,7 @@ class TvConversationAdapter( ?.scaleY(if (hasFocus) 1.1f else 1f) ?.scaleX(if (hasFocus) 1.1f else 1f) } - val status = file.status + val status = file.transferStatus viewHolder.mIcon?.setImageResource( if (status.isError) R.drawable.baseline_warning_24 else R.drawable.baseline_attach_file_24 @@ -629,7 +630,7 @@ class TvConversationAdapter( if (file.isOutgoing) viewHolder.mFileInfoLayout?.background?.setTint(convColor) // Show the download button when (status) { - InteractionStatus.FILE_AVAILABLE, InteractionStatus.TRANSFER_AWAITING_HOST -> { + TransferStatus.FILE_AVAILABLE, TransferStatus.TRANSFER_AWAITING_HOST -> { viewHolder.mFileDownloadButton?.let { it.visibility = View.VISIBLE it.setOnClickListener { presenter.acceptFile(file) } @@ -637,7 +638,7 @@ class TvConversationAdapter( } else -> { viewHolder.mFileDownloadButton?.visibility = View.GONE - if (status == InteractionStatus.TRANSFER_ONGOING) { + if (status == TransferStatus.TRANSFER_ONGOING) { viewHolder.progress?.max = (file.totalSize / 1024).toInt() viewHolder.progress?.setProgress( (file.bytesProgress / 1024).toInt(), true diff --git a/jami-android/app/src/main/java/cx/ring/utils/TextUtils.kt b/jami-android/app/src/main/java/cx/ring/utils/TextUtils.kt index b9c3136704b16027ed69b3041f636691d53b54f8..c73eb6e39da95e21934a53e3bd33a8afd6b40cd6 100644 --- a/jami-android/app/src/main/java/cx/ring/utils/TextUtils.kt +++ b/jami-android/app/src/main/java/cx/ring/utils/TextUtils.kt @@ -22,7 +22,7 @@ import android.content.Context import android.text.TextUtils import android.text.format.DateUtils import cx.ring.R -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import java.util.* object TextUtils { @@ -105,17 +105,17 @@ object TextUtils { .out().toString().uppercase(Locale.getDefault()) } - fun getReadableFileTransferStatus(context: Context, transferStatus: InteractionStatus): String { + fun getReadableFileTransferStatus(context: Context, transferStatus: TransferStatus): String { return when (transferStatus) { - InteractionStatus.TRANSFER_CREATED -> context.getString(R.string.file_transfer_status_created) - InteractionStatus.TRANSFER_AWAITING_PEER -> context.getString(R.string.file_transfer_status_wait_peer_acceptance) - InteractionStatus.TRANSFER_AWAITING_HOST -> context.getString(R.string.file_transfer_status_wait_host_acceptance) - InteractionStatus.TRANSFER_ONGOING -> context.getString(R.string.file_transfer_status_ongoing) - InteractionStatus.TRANSFER_FINISHED -> context.getString(R.string.file_transfer_status_finished) - InteractionStatus.TRANSFER_CANCELED -> context.getString(R.string.file_transfer_status_cancelled) - InteractionStatus.TRANSFER_UNJOINABLE_PEER -> context.getString(R.string.file_transfer_status_unjoinable_peer) - InteractionStatus.TRANSFER_ERROR -> context.getString(R.string.file_transfer_status_error) - InteractionStatus.TRANSFER_TIMEOUT_EXPIRED -> context.getString(R.string.file_transfer_status_timed_out) + TransferStatus.TRANSFER_CREATED -> context.getString(R.string.file_transfer_status_created) + TransferStatus.TRANSFER_AWAITING_PEER -> context.getString(R.string.file_transfer_status_wait_peer_acceptance) + TransferStatus.TRANSFER_AWAITING_HOST -> context.getString(R.string.file_transfer_status_wait_host_acceptance) + TransferStatus.TRANSFER_ONGOING -> context.getString(R.string.file_transfer_status_ongoing) + TransferStatus.TRANSFER_FINISHED -> context.getString(R.string.file_transfer_status_finished) + TransferStatus.TRANSFER_CANCELED -> context.getString(R.string.file_transfer_status_cancelled) + TransferStatus.TRANSFER_UNJOINABLE_PEER -> context.getString(R.string.file_transfer_status_unjoinable_peer) + TransferStatus.TRANSFER_ERROR -> context.getString(R.string.file_transfer_status_error) + TransferStatus.TRANSFER_TIMEOUT_EXPIRED -> context.getString(R.string.file_transfer_status_timed_out) else -> "" } } diff --git a/jami-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt b/jami-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt index 1f05a4e4ef1c558574b9cc092598fed12d801234..1be6602565b6ca7da8c1ababfc3a97a501d4c4a9 100644 --- a/jami-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt +++ b/jami-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt @@ -159,13 +159,13 @@ class SmartListViewHolder : RecyclerView.ViewHolder { return "" } } else if (e.type == Interaction.InteractionType.DATA_TRANSFER) { - return if (e.status == Interaction.InteractionStatus.TRANSFER_FINISHED) { + return if (e.transferStatus == Interaction.TransferStatus.TRANSFER_FINISHED) { if (!e.isIncoming) { context.getString(R.string.hist_file_sent) } else { context.getString(R.string.hist_file_received) } - } else TextUtils.getReadableFileTransferStatus(context, e.status) + } else TextUtils.getReadableFileTransferStatus(context, e.transferStatus) } return null } diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt index ef10c314a8e032b12864a748bd4821e4a50ddf9d..9303c4fe8b5cb11b4af32c393b63f0c2f010726d 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt @@ -22,7 +22,7 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject import io.reactivex.rxjava3.subjects.CompletableSubject import io.reactivex.rxjava3.subjects.PublishSubject import io.reactivex.rxjava3.subjects.Subject -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.services.AccountService import net.jami.utils.Log import java.util.Collections @@ -349,9 +349,9 @@ class Account( fun onDataTransferEvent(transfer: DataTransfer): Conversation { Log.d(TAG, "Account onDataTransferEvent " + transfer.messageId) val conversation = transfer.conversation as Conversation - val transferEventCode = transfer.status + val transferEventCode = transfer.transferStatus synchronized(conversation) { - if (transferEventCode == InteractionStatus.TRANSFER_CREATED) { + if (transferEventCode == TransferStatus.TRANSFER_CREATED) { conversation.addFileTransfer(transfer) updated(conversation) } else { diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Call.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Call.kt index a58e560e67e48afd1bcbc0ddf3fd2f734472e0a3..e74116ebc0c02325e9a35f2895ca969630b1bc06 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Call.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Call.kt @@ -105,7 +105,7 @@ class Call : Interaction { this.conversation = conversation isIncoming = direction == Direction.INCOMING timestamp = System.currentTimeMillis() - mType = InteractionType.CALL.toString() + type = InteractionType.CALL this.contact = contact mIsRead = 1 //this.mediaList = mediaList @@ -117,8 +117,8 @@ class Call : Interaction { conversation = interaction.conversation isIncoming = author != null timestamp = interaction.timestamp - mType = InteractionType.CALL.toString() - mStatus = interaction.status.toString() + type = InteractionType.CALL + status = interaction.status daemonId = interaction.daemonId daemonIdString = super.daemonIdString mIsRead = if (interaction.isRead) 1 else 0 @@ -141,7 +141,7 @@ class Call : Interaction { author = if (direction == Direction.INCOMING) contactNumber else null this.contactNumber = contactNumber this.timestamp = timestamp - mType = InteractionType.CALL.toString() + type = InteractionType.CALL mIsRead = 1 } @@ -186,11 +186,11 @@ class Call : Interaction { this.callStatus = callStatus if (callStatus == CallStatus.CURRENT) { isMissed = false - mStatus = InteractionStatus.SUCCESS.toString() + status = InteractionStatus.SUCCESS } else if (isRinging || isOnGoing) { - mStatus = InteractionStatus.SUCCESS.toString() + status = InteractionStatus.SUCCESS } else if (this.callStatus == CallStatus.FAILURE) { - mStatus = InteractionStatus.FAILURE.toString() + status = InteractionStatus.FAILURE } } diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/ContactEvent.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/ContactEvent.kt index 754ca1ed64f7d61887ed0958e06bcd48593e2352..8de1e67a4c0b08d41e164df4c3fb9abcd968f4b5 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/ContactEvent.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/ContactEvent.kt @@ -24,9 +24,9 @@ class ContactEvent : Interaction { id = interaction.id conversation = interaction.conversation author = interaction.author - mType = InteractionType.CONTACT.toString() + type = InteractionType.CONTACT timestamp = interaction.timestamp - mStatus = interaction.status.toString() + status = interaction.status mIsRead = 1 contact = interaction.contact event = getEventFromStatus(interaction.status) @@ -35,9 +35,9 @@ class ContactEvent : Interaction { constructor() { author = null event = Event.ADDED - mType = InteractionType.CONTACT.toString() + type = InteractionType.CONTACT timestamp = System.currentTimeMillis() - mStatus = InteractionStatus.SUCCESS.toString() + status = InteractionStatus.SUCCESS mIsRead = 1 } @@ -45,9 +45,9 @@ class ContactEvent : Interaction { this.contact = contact account = accountId author = contact.uri.uri - mType = InteractionType.CONTACT.toString() + type = InteractionType.CONTACT event = Event.ADDED - mStatus = InteractionStatus.SUCCESS.toString() + status = InteractionStatus.SUCCESS timestamp = contact.addedDate!!.time mIsRead = 1 } @@ -58,9 +58,9 @@ class ContactEvent : Interaction { this.contact = contact author = contact.uri.uri timestamp = request.timestamp - mType = InteractionType.CONTACT.toString() + type = InteractionType.CONTACT event = Event.INCOMING_REQUEST - mStatus = InteractionStatus.UNKNOWN.toString() + status = InteractionStatus.UNKNOWN mIsRead = 1 } diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Conversation.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Conversation.kt index 6535460737fa3d000661b93808d6f11aa8b6cd62..d3797e5f066a0361f03d403f1dc6d1902473fc11 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Conversation.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Conversation.kt @@ -290,7 +290,7 @@ class Conversation : ConversationHistory { if (interaction.contact == null) { if (contacts.size == 1) interaction.contact = contacts[0] else { if (interaction.author == null) { - Log.e(TAG, "Can't set interaction properties: no author for type:" + interaction.type + " id:" + interaction.id + " status:" + interaction.mStatus) + Log.e(TAG, "Can't set interaction properties: no author for type:" + interaction.type + " id:" + interaction.id + " status:" + interaction.status) } else { interaction.contact = findContact(Uri.fromString(interaction.author!!)) } @@ -664,10 +664,10 @@ class Conversation : ConversationHistory { mPendingMessages.remove(id)?.onSuccess(interaction) } - fun updateFileTransfer(transfer: DataTransfer, eventCode: Interaction.InteractionStatus) { + fun updateFileTransfer(transfer: DataTransfer, eventCode: Interaction.TransferStatus) { val dataTransfer = (if (isSwarm) transfer else findConversationElement(transfer.id)) as? DataTransfer if (dataTransfer != null) { - dataTransfer.status = eventCode + dataTransfer.transferStatus = eventCode updatedElementSubject.onNext(Pair(dataTransfer, ElementStatus.UPDATE)) } } diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/DataTransfer.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/DataTransfer.kt index 4139e7b71c59322f3f4eefa267b091a6ac4bae58..e2b6305c04053894fc03a5b165ea3802495718e6 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/DataTransfer.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/DataTransfer.kt @@ -50,8 +50,8 @@ class DataTransfer : Interaction { this.totalSize = totalSize this.bytesProgress = bytesProgress body = displayName - mStatus = InteractionStatus.TRANSFER_CREATED.toString() - mType = InteractionType.DATA_TRANSFER.toString() + transferStatus = TransferStatus.TRANSFER_CREATED + type = InteractionType.DATA_TRANSFER timestamp = System.currentTimeMillis() mIsRead = 1 isIncoming = !isOutgoing @@ -69,15 +69,14 @@ class DataTransfer : Interaction { daemonId = interaction.daemonId author = interaction.author conversation = interaction.conversation - // mPeerId = interaction.getConversation().getParticipant(); body = interaction.body - mStatus = interaction.status.toString() - mType = interaction.type.toString() + transferStatus = interaction.transferStatus + type = interaction.type timestamp = interaction.timestamp account = interaction.account contact = interaction.contact mIsRead = 1 - isIncoming = interaction.isIncoming //mAuthor != null; + isIncoming = interaction.isIncoming } constructor( @@ -98,7 +97,7 @@ class DataTransfer : Interaction { this.totalSize = totalSize this.bytesProgress = bytesProgress this.timestamp = timestamp - mType = InteractionType.DATA_TRANSFER.toString() + type = InteractionType.DATA_TRANSFER } val extension: String? @@ -115,7 +114,7 @@ class DataTransfer : Interaction { val isVideo: Boolean get() = VIDEO_EXTENSIONS.contains(extension) val isComplete: Boolean - get() = InteractionStatus.TRANSFER_FINISHED.toString() == mStatus + get() = TransferStatus.TRANSFER_FINISHED == transferStatus fun showPicture(): Boolean = isPicture && isComplete @@ -132,7 +131,7 @@ class DataTransfer : Interaction { val isOutgoing: Boolean get() = !isIncoming val isError: Boolean - get() = status.isError + get() = transferStatus.isError fun canAutoAccept(maxSize: Int): Boolean { return maxSize == UNLIMITED_SIZE || totalSize <= maxSize @@ -149,7 +148,6 @@ class DataTransfer : Interaction { private val IMAGE_EXTENSIONS = setOf("jpg", "jpeg", "png", "gif", "webp", "svg", "bmp", "heic", "heif") private val AUDIO_EXTENSIONS = setOf("ogg", "mp3", "aac", "flac", "m4a") private val VIDEO_EXTENSIONS = setOf("webm", "mp4", "mkv") - private const val MAX_SIZE = 32 * 1024 * 1024 private const val UNLIMITED_SIZE = 256 * 1024 * 1024 } } \ No newline at end of file diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Interaction.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Interaction.kt index 74e597162e2b6d267124f33ed2372f6fb7b812c1..2f69865675af80a0ac0c55f0ca22fda5e9f6a87e 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Interaction.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/Interaction.kt @@ -63,10 +63,18 @@ open class Interaction { var body: String? = null @DatabaseField(columnName = COLUMN_TYPE) - var mType: String? = null + var type = InteractionType.INVALID - @DatabaseField(columnName = COLUMN_STATUS) - var mStatus = InteractionStatus.UNKNOWN.toString() + @DatabaseField(unknownEnumName = "INVALID", columnName = COLUMN_STATUS) + var status = InteractionStatus.INVALID + set(status) { + if (status == InteractionStatus.DISPLAYED) + mIsRead = 1 + field = status + } + + // should not be saved to the database ==> SIP does not support data transfers + var transferStatus = TransferStatus.INVALID @DatabaseField(columnName = COLUMN_DAEMON_ID) var daemonId: Long? = null @@ -95,10 +103,10 @@ open class Interaction { type = InteractionType.INVALID } - constructor(conversation: Conversation, type: InteractionType) { + constructor(conversation: Conversation, mType: InteractionType) { this.conversation = conversation account = conversation.accountId - mType = type.toString() + type = mType } constructor( @@ -107,8 +115,8 @@ open class Interaction { conversation: ConversationHistory?, timestamp: String, body: String?, - type: String?, - status: String, + mType: String, + st: String, daemonId: String?, isRead: String, extraFlag: String @@ -118,8 +126,8 @@ open class Interaction { this.conversation = conversation this.timestamp = timestamp.toLong() this.body = body - mType = type - mStatus = status + type = InteractionType.fromString(mType) + status = InteractionStatus.fromString(st) try { this.daemonId = daemonId?.toLong() } catch (e: NumberFormatException) { @@ -133,17 +141,6 @@ open class Interaction { mIsRead = 1 } - var type: InteractionType - get() = if (mType != null) InteractionType.fromString(mType!!) else InteractionType.INVALID - set(type) { - mType = type.toString() - } - var status: InteractionStatus - get() = InteractionStatus.fromString(mStatus) - set(status) { - if (status == InteractionStatus.DISPLAYED) mIsRead = 1 - mStatus = status.toString() - } val extraFlag: JsonObject get() = toJson(mExtraFlag) @@ -237,15 +234,7 @@ open class Interaction { } enum class InteractionStatus { - UNKNOWN, SENDING, SUCCESS, DISPLAYED, INVALID, FAILURE, TRANSFER_CREATED, - TRANSFER_ACCEPTED, TRANSFER_CANCELED, TRANSFER_ERROR, TRANSFER_UNJOINABLE_PEER, - TRANSFER_ONGOING, TRANSFER_AWAITING_PEER, TRANSFER_AWAITING_HOST, TRANSFER_TIMEOUT_EXPIRED, - TRANSFER_FINISHED, FILE_AVAILABLE; - - val isError: Boolean - get() = this == TRANSFER_ERROR || this == TRANSFER_UNJOINABLE_PEER || this == TRANSFER_CANCELED || this == TRANSFER_TIMEOUT_EXPIRED || this == FAILURE - val isOver: Boolean - get() = isError || this == TRANSFER_FINISHED + UNKNOWN, SENDING, SUCCESS, DISPLAYED, INVALID, FAILURE; companion object { fun fromString(str: String): InteractionStatus = entries.firstOrNull { it.name == str } ?: INVALID @@ -255,8 +244,21 @@ open class Interaction { } catch (e: ArrayIndexOutOfBoundsException) { INVALID } + } + } - fun fromIntFile(n: Int): InteractionStatus = when (n) { + enum class TransferStatus { + INVALID, FAILURE, TRANSFER_CREATED, TRANSFER_ACCEPTED, TRANSFER_CANCELED, TRANSFER_ERROR, TRANSFER_UNJOINABLE_PEER, + TRANSFER_ONGOING, TRANSFER_AWAITING_PEER, TRANSFER_AWAITING_HOST, TRANSFER_TIMEOUT_EXPIRED, + TRANSFER_FINISHED, FILE_AVAILABLE, FILE_REMOVED; + + val isError: Boolean + get() = this == TRANSFER_ERROR || this == TRANSFER_UNJOINABLE_PEER || this == TRANSFER_CANCELED || this == TRANSFER_TIMEOUT_EXPIRED || this == FAILURE + val isOver: Boolean + get() = isError || this == TRANSFER_FINISHED + + companion object { + fun fromIntFile(n: Int): TransferStatus = when (n) { 0 -> INVALID 1 -> TRANSFER_CREATED 2, 9 -> TRANSFER_ERROR @@ -266,7 +268,7 @@ open class Interaction { 6 -> TRANSFER_FINISHED 7, 8, 10 -> TRANSFER_UNJOINABLE_PEER 11 -> TRANSFER_TIMEOUT_EXPIRED - else -> UNKNOWN + else -> INVALID } } } diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/TextMessage.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/TextMessage.kt index f80cca0b956042cc61cc11dc528b0ad8172355a7..70b1a55f41fdac08106c0185662b3d135fe11467 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/model/TextMessage.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/model/TextMessage.kt @@ -34,7 +34,7 @@ class TextMessage : Interaction { } } timestamp = System.currentTimeMillis() - mType = InteractionType.TEXT.toString() + type = InteractionType.TEXT this.conversation = conversation isIncoming = author != null body = message @@ -44,7 +44,7 @@ class TextMessage : Interaction { this.author = author this.account = account this.timestamp = timestamp - mType = InteractionType.TEXT.toString() + type = InteractionType.TEXT this.conversation = conversation this.isIncoming = isIncoming body = message @@ -55,8 +55,8 @@ class TextMessage : Interaction { id = interaction.id author = interaction.author timestamp = interaction.timestamp - mType = interaction.type.toString() - mStatus = interaction.status.toString() + type = InteractionType.TEXT + status = interaction.status conversation = interaction.conversation isIncoming = author != null daemonId = interaction.daemonId diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/AccountService.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/AccountService.kt index 8f81638135d436a7e3cab15b57828feb1f44dbbb..6b84be99b24f709da85b4a512e13ae11ebf983a9 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/AccountService.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/AccountService.kt @@ -28,7 +28,7 @@ import io.reactivex.rxjava3.subjects.SingleSubject import io.reactivex.rxjava3.subjects.Subject import net.jami.daemon.* import net.jami.model.* -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.utils.Log import net.jami.utils.SwigNativeConverter import java.io.File @@ -312,7 +312,7 @@ class AccountService( requestData["received"]!!.toLong() * 1000L, Uri(Uri.SWARM_SCHEME, conversationId), mVCardService.loadConversationProfile(requestData), - requestData["mode"]?.let { m -> Conversation.Mode.values()[m.toInt()] } ?: Conversation.Mode.OneToOne)) + requestData["mode"]?.let { m -> Conversation.Mode.entries[m.toInt()] } ?: Conversation.Mode.OneToOne)) } catch (e: Exception) { Log.w(TAG, "Error loading request", e) } @@ -1024,7 +1024,7 @@ class AccountService( status: Int, ) { val account = getAccount(accountId) ?: return - val interactionStatus = InteractionStatus.fromIntTextMessage(status) + val interactionStatus = Interaction.InteractionStatus.fromIntTextMessage(status) val messageState = Interaction.MessageStates.fromInt(status) if (conversationId.isEmpty() && !account.isJami) { @@ -1240,7 +1240,7 @@ class AccountService( val isComplete = path.exists() && progressA[0] == totalA[0] DataTransfer(fileId, account.accountId, author, fileName, contact.isUser, timestamp, totalA[0], progressA[0]).apply { daemonPath = path - status = if (isComplete) InteractionStatus.TRANSFER_FINISHED else InteractionStatus.FILE_AVAILABLE + transferStatus = if (isComplete) TransferStatus.TRANSFER_FINISHED else TransferStatus.FILE_AVAILABLE } } catch (e: Exception) { Interaction(conversation, Interaction.InteractionType.INVALID) @@ -1365,7 +1365,7 @@ class AccountService( /*for (Map.Entry<String, String> i : info.entrySet()) { Log.w(TAG, "conversation info: " + i.getKey() + " " + i.getValue()); }*/ - val mode = Conversation.Mode.values()[info["mode"]!!.toInt()] + val mode = Conversation.Mode.entries[info["mode"]!!.toInt()] val uri = Uri(Uri.SWARM_SCHEME, conversationId) var c = account.getByUri(uri)//getSwarm(conversationId) ?: account.getByUri(Uri(Uri.SWARM_SCHEME, conversationId)) var setMode = false @@ -1427,7 +1427,7 @@ class AccountService( metadata["received"]!!.toLong() * 1000L, Uri(Uri.SWARM_SCHEME, conversationId), mVCardService.loadConversationProfile(metadata), - metadata["mode"]?.let { m -> Conversation.Mode.values()[m.toInt()] } ?: Conversation.Mode.OneToOne)) + metadata["mode"]?.let { m -> Conversation.Mode.entries[m.toInt()] } ?: Conversation.Mode.OneToOne)) } fun swarmMessageReceived(accountId: String, conversationId: String, message: SwarmMessage) { @@ -1512,7 +1512,7 @@ class AccountService( ) override fun run() { synchronized(toUpdate) { - if (toUpdate.status == InteractionStatus.TRANSFER_ONGOING) { + if (toUpdate.transferStatus == Interaction.TransferStatus.TRANSFER_ONGOING) { dataTransferEvent(account, conversation, toUpdate.messageId, toUpdate.fileId!!, 5) } else { scheduledTask.cancel(false) @@ -1530,7 +1530,7 @@ class AccountService( } fun dataTransferEvent(account: Account, conversation: Conversation, interactionId: String?, fileId: String, eventCode: Int) { - val transferStatus = InteractionStatus.fromIntFile(eventCode) + val transferStatus = TransferStatus.fromIntFile(eventCode) Log.d(TAG, "Data Transfer $interactionId $fileId $transferStatus") val transfer = account.getDataTransfer(fileId) ?: conversation.getMessage(interactionId!!) as DataTransfer? ?: return val paths = arrayOfNulls<String>(1) @@ -1540,13 +1540,13 @@ class AccountService( val progress = progressA[0] val total = totalA[0] synchronized(transfer) { - val oldState = transfer.status + val oldState = transfer.transferStatus transfer.conversation = conversation transfer.daemonPath = File(paths[0]!!) - transfer.status = transferStatus + transfer.transferStatus = transferStatus transfer.bytesProgress = progress if (oldState != transferStatus) { - if (transferStatus == InteractionStatus.TRANSFER_ONGOING) { + if (transferStatus == Interaction.TransferStatus.TRANSFER_ONGOING) { DataTransferRefreshTask(account, conversation, transfer) } else if (transferStatus.isError) { if (!transfer.isOutgoing) { @@ -1559,7 +1559,7 @@ class AccountService( } // Hack to prevent notifications from being sent for data transfer uploads done on // images which aren't owned by the local account - if (oldState == InteractionStatus.TRANSFER_FINISHED && oldState == transferStatus) + if (oldState == TransferStatus.TRANSFER_FINISHED && oldState == transferStatus) return } Log.d(TAG, "Data Transfer dataTransferSubject.onNext") @@ -1591,12 +1591,5 @@ class AccountService( const val ACCOUNT_SCHEME_NONE = "" const val ACCOUNT_SCHEME_PASSWORD = "password" const val ACCOUNT_SCHEME_KEY = "key" - - private fun getDataTransferError(errorCode: Long): DataTransferError = try { - DataTransferError.values()[errorCode.toInt()] - } catch (ignored: ArrayIndexOutOfBoundsException) { - Log.e(TAG, "getDataTransferError: invalid data transfer error from daemon") - DataTransferError.UNKNOWN - } } } \ No newline at end of file diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/ConversationFacade.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/ConversationFacade.kt index 6d8fe1ae959eab661ed4030dfa053495730976b0..c4e2a4e3580ec82a025ede6d24e47b2a21e51619 100644 --- a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/ConversationFacade.kt +++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/ConversationFacade.kt @@ -25,7 +25,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers import net.jami.model.* import net.jami.model.Account.ContactLocationEntry import net.jami.model.Call.CallStatus -import net.jami.model.Interaction.InteractionStatus +import net.jami.model.Interaction.TransferStatus import net.jami.services.AccountService.RegisteredName import net.jami.smartlist.ConversationItemViewModel import net.jami.utils.FileUtils.moveFile @@ -159,7 +159,7 @@ class ConversationFacade( } fun deleteConversationFile(conversation: Conversation, transfer: DataTransfer) { - if (transfer.status === InteractionStatus.TRANSFER_ONGOING) { + if (transfer.transferStatus === TransferStatus.TRANSFER_ONGOING) { mAccountService.cancelDataTransfer( conversation.accountId, conversation.uri.rawRingId, transfer.messageId, transfer.fileId!! ) @@ -171,7 +171,7 @@ class ConversationFacade( transfer.bytesProgress = 0 }.subscribeOn(Schedulers.io()) .subscribe({ - transfer.status = InteractionStatus.FILE_AVAILABLE + transfer.transferStatus = TransferStatus.FILE_AVAILABLE conversation.updateInteraction(transfer) }) { e: Throwable -> Log.e(TAG, "Can't delete file", e) }) } @@ -189,22 +189,18 @@ class ConversationFacade( } fun deleteConversationItem(conversation: Conversation, element: Interaction) { - if (element.type === Interaction.InteractionType.DATA_TRANSFER) { - deleteConversationFile(conversation, element as DataTransfer) + // handling is the same for calls, texts and files + if (conversation.isSwarm) { + if ((element as? DataTransfer)?.transferStatus === TransferStatus.TRANSFER_ONGOING) { + mAccountService.cancelDataTransfer(conversation.accountId, conversation.uri.rawRingId, element.messageId, element.fileId!!) + } + mAccountService.deleteConversationMessage(conversation.accountId, conversation.uri, element.messageId!!) } else { - // handling is the same for calls and texts - if (conversation.isSwarm) { - if ((element as? DataTransfer)?.status === InteractionStatus.TRANSFER_ONGOING) { - mAccountService.cancelDataTransfer(conversation.accountId, conversation.uri.rawRingId, element.messageId, element.fileId!!) - } - mAccountService.deleteConversationMessage(conversation.accountId, conversation.uri, element.messageId!!) - } else { - mDisposableBag.add(mHistoryService.deleteInteraction(element.id, element.account!!) + mDisposableBag.add(mHistoryService.deleteInteraction(element.id, element.account!!) .subscribeOn(Schedulers.io()) .subscribe({ conversation.removeInteraction(element) }) { e: Throwable -> Log.e(TAG, "Can't delete message", e) }) - } } } @@ -583,9 +579,9 @@ class ConversationFacade( private fun handleDataTransferEvent(transfer: DataTransfer) { val account = transfer.account!! val conversation = mAccountService.getAccount(account)!!.onDataTransferEvent(transfer) - val status = transfer.status + val status = transfer.transferStatus Log.d(TAG, "handleDataTransferEvent $status " + transfer.canAutoAccept(mPreferencesService.getMaxFileAutoAccept(account))) - if (status === InteractionStatus.TRANSFER_AWAITING_HOST || status === InteractionStatus.FILE_AVAILABLE) { + if (status === TransferStatus.TRANSFER_AWAITING_HOST || status === TransferStatus.FILE_AVAILABLE) { if (transfer.canAutoAccept(mPreferencesService.getMaxFileAutoAccept(account))) { mAccountService.acceptFileTransfer(conversation, transfer.fileId!!, transfer) return