Preparing chat UI models

To be able to add messages to the MessagesListAdapter of a MessageList, we must implement ChatKit's IMessage interface in an appropriate Model. We will implement this model here. Create a com.example.messenger.utils.message package and add the following  Message class within it:

package com.example.messenger.utils.message

import com.stfalcon.chatkit.commons.models.IMessage
import com.stfalcon.chatkit.commons.models.IUser
import java.util.*

data class Message(private val authorId: Long, private val body: String,
private val createdAt: Date) : IMessage {

override fun getId(): String {
return authorId.toString()
}

override fun getCreatedAt(): Date {
return createdAt
}

override fun getUser(): IUser {
return Author(authorId, "")
}

override fun getText(): String {
return body
}

}

In addition to this, we need to create an Author class that implements ChatKit's IUser interface. The implementation of this class is as follows:

package com.example.messenger.utils.message

import com.stfalcon.chatkit.commons.models.IUser


data class Author(val id: Long, val username: String) : IUser {

override fun getAvatar(): String? {
return null
}

override fun getName(): String {
return username
}

override fun getId(): String {
return id.toString()
}

}

The Author class models the user details of a message author, such as the name of the author, their ID, and an avatar (if they have one).

We have done enough with views and layouts for now. Let's go ahead and implement a ChatInteractor and ChatPresenter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.72.212