All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.formatters.defaults.DefaultChannelLastMessageSenderNameFormatter.kt Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
package com.sceyt.chatuikit.formatters.defaults

import android.content.Context
import com.sceyt.chatuikit.R
import com.sceyt.chatuikit.SceytChatUIKit
import com.sceyt.chatuikit.data.models.channels.SceytChannel
import com.sceyt.chatuikit.formatters.Formatter
import com.sceyt.chatuikit.persistence.extensions.isSelf

data object DefaultChannelLastMessageSenderNameFormatter : Formatter {

    override fun format(context: Context, from: SceytChannel): CharSequence {
        val message = from.lastMessage ?: return ""
        return when {
            message.incoming -> {
                val sender = from.lastMessage.user
                val userFirstName = sender?.let {
                    SceytChatUIKit.formatters.userShortNameFormatter.format(context, it)
                }
                if (from.isGroup && !userFirstName.isNullOrBlank()) {
                    "${userFirstName}: "
                } else ""
            }

            from.isSelf() -> ""
            else -> "${context.getString(R.string.sceyt_your_last_message)}: "
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy