Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
main.com.sceyt.chatuikit.persistence.differs.MessageDiffer.kt Maven / Gradle / Ivy
package com.sceyt.chatuikit.persistence.differs
import com.sceyt.chatuikit.data.models.messages.SceytMessage
import com.sceyt.chatuikit.persistence.extensions.equalsIgnoreNull
data class MessageDiff(
val edited: Boolean,
val bodyChanged: Boolean,
val statusChanged: Boolean,
val avatarChanged: Boolean,
val nameChanged: Boolean,
val replyCountChanged: Boolean,
val replyContainerChanged: Boolean,
val reactionsChanged: Boolean,
val showAvatarAndNameChanged: Boolean,
val filesChanged: Boolean,
val selectionChanged: Boolean
) {
fun hasDifference(): Boolean {
return edited || bodyChanged || statusChanged || avatarChanged || nameChanged || replyCountChanged
|| replyContainerChanged || reactionsChanged || showAvatarAndNameChanged || filesChanged || selectionChanged
}
companion object {
val DEFAULT = MessageDiff(
edited = true,
bodyChanged = true,
statusChanged = true,
avatarChanged = true,
nameChanged = true,
replyCountChanged = true,
replyContainerChanged = true,
reactionsChanged = true,
showAvatarAndNameChanged = true,
filesChanged = true,
selectionChanged = true
)
val DEFAULT_FALSE = MessageDiff(
edited = false,
bodyChanged = false,
statusChanged = false,
avatarChanged = false,
nameChanged = false,
replyCountChanged = false,
replyContainerChanged = false,
reactionsChanged = false,
showAvatarAndNameChanged = false,
filesChanged = false,
selectionChanged = false
)
}
override fun toString(): String {
return "edited: $edited, bodyChanged: $bodyChanged, statusChanged: $statusChanged, avatarChanged: $avatarChanged, " +
"nameChanged: $nameChanged, replyCountChanged: $replyCountChanged, reactionsChanged: $reactionsChanged, " +
"showAvatarAndNameChanged: $showAvatarAndNameChanged, filesChanged: $filesChanged, selectionChanged: $selectionChanged"
}
}
fun SceytMessage.diff(other: SceytMessage): MessageDiff {
return MessageDiff(
edited = state != other.state,
bodyChanged = body != other.body || bodyAttributes != other.bodyAttributes,
statusChanged = !incoming && deliveryStatus != other.deliveryStatus,
avatarChanged = user?.avatarURL.equalsIgnoreNull(other.user?.avatarURL).not(),
nameChanged = user?.fullName.equalsIgnoreNull(other.user?.fullName).not(),
replyCountChanged = replyCount != other.replyCount,
replyContainerChanged = parentMessage != other.parentMessage || parentMessage?.user != other.parentMessage?.user
|| parentMessage?.state != other.parentMessage?.state || parentMessage?.body != other.parentMessage?.body,
reactionsChanged = messageReactions?.equalsIgnoreNull(other.messageReactions)?.not()
?: other.reactionTotals.isNullOrEmpty().not(),
showAvatarAndNameChanged = shouldShowAvatarAndName != other.shouldShowAvatarAndName
|| disabledShowAvatarAndName != other.disabledShowAvatarAndName,
filesChanged = attachments?.size != other.attachments?.size,
selectionChanged = isSelected != other.isSelected
)
}
fun SceytMessage.diffContent(other: SceytMessage): MessageDiff {
return MessageDiff(
edited = state != other.state,
bodyChanged = body != other.body || bodyAttributes != other.bodyAttributes,
statusChanged = !incoming && deliveryStatus != other.deliveryStatus,
avatarChanged = user?.avatarURL.equalsIgnoreNull(other.user?.avatarURL).not(),
nameChanged = user?.fullName.equalsIgnoreNull(other.user?.fullName).not(),
replyCountChanged = replyCount != other.replyCount,
replyContainerChanged = parentMessage != other.parentMessage || parentMessage?.user != other.parentMessage?.user
|| parentMessage?.state != other.parentMessage?.state || parentMessage?.body != other.parentMessage?.body,
reactionsChanged = reactionTotals?.equalsIgnoreNull(other.reactionTotals)?.not()
?: other.reactionTotals.isNullOrEmpty().not(),
showAvatarAndNameChanged = false,
filesChanged = attachments?.size != other.attachments?.size,
selectionChanged = isSelected != other.isSelected
)
}