Skip to content
Snippets Groups Projects
Commit dcbfadbf authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Completed Cmix & GroupChat implementations

CmixAdapter and GroupChatAdapter
parent 4fb459d7
Branches
No related tags found
No related merge requests found
Showing
with 155 additions and 52 deletions
package io.elixxir.dapp.bindings.data
import bindings.ReceptionIdentity
import io.elixxir.dapp.bindings.model.Connection
import io.elixxir.dapp.bindings.model.*
import io.elixxir.dapp.bindings.model.Contact
import io.elixxir.dapp.bindings.model.E2eId
import io.elixxir.dapp.bindings.model.NetworkFollowerStatus
import io.elixxir.dapp.bindings.model.NodeRegistrationStatus
internal interface Cmix {
fun connect(): Connection
fun startNetworkFollower()
fun connect(
e2eId: E2eId,
recipientContact: Contact,
e2eParams: E2eParams
): Connection
fun startNetworkFollower(timeoutMs: Long)
fun stopNetworkFollower()
fun isNetworkHealthy(): Boolean
fun registerHealthCallback()
fun unregisterHealthCallback()
fun registerHealthListener(listener: NetworkHealthListener): HealthListenerId
fun unregisterHealthListener(id: HealthListenerId)
fun getNodeRegistrationStatus(): NodeRegistrationStatus
fun makeReceptionIdentity(): ReceptionIdentity
fun getNetworkFollowerStatus(): NetworkFollowerStatus
}
package io.elixxir.dapp.bindings.data
import bindings.ReceptionIdentity
import io.elixxir.dapp.bindings.model.*
import io.elixxir.dapp.bindings.model.Connection
import io.elixxir.dapp.bindings.model.Contact
import io.elixxir.dapp.bindings.model.E2eId
import io.elixxir.dapp.bindings.model.E2eParams
import io.elixxir.dapp.bindings.model.NetworkFollowerStatus
import io.elixxir.dapp.bindings.model.NodeRegistrationStatus
import bindings.Cmix as CoreCmix
@JvmInline
internal value class CmixAdapter(private val cmix: CoreCmix) : Cmix {
override fun connect(): Connection {
TODO("Not yet implemented")
override fun connect(
e2eId: E2eId,
recipientContact: Contact,
e2eParams: E2eParams
): Connection {
// TODO: Use factory method to get Connection implementation
return ConnectionAdapter(
cmix.connect(
e2eId.value,
recipientContact.value,
e2eParams.value
)
)
}
override fun startNetworkFollower() {
TODO("Not yet implemented")
override fun startNetworkFollower(timeoutMs: Long) {
cmix.startNetworkFollower(timeoutMs)
}
override fun stopNetworkFollower() {
TODO("Not yet implemented")
cmix.stopNetworkFollower()
}
override fun isNetworkHealthy(): Boolean {
TODO("Not yet implemented")
return cmix.isHealthy
}
override fun registerHealthCallback() {
TODO("Not yet implemented")
override fun registerHealthListener(listener: NetworkHealthListener): HealthListenerId {
return HealthListenerId(
cmix.addHealthCallback(HealthCallbackAdapter.placeholder)
)
}
override fun unregisterHealthCallback() {
TODO("Not yet implemented")
override fun unregisterHealthListener(id: HealthListenerId) {
cmix.removeHealthCallback(id.value)
}
override fun getNodeRegistrationStatus(): NodeRegistrationStatus {
TODO("Not yet implemented")
return NodeRegistrationStatus(cmix.nodeRegistrationStatus)
}
override fun makeReceptionIdentity(): ReceptionIdentity {
TODO("Not yet implemented")
return ReceptionIdentity(cmix.makeReceptionIdentity())
}
override fun getNetworkFollowerStatus(): NetworkFollowerStatus {
TODO("Not yet implemented")
return NetworkFollowerStatus.from(cmix.networkFollowerStatus())
}
}
\ No newline at end of file
package io.elixxir.dapp.bindings.data
import io.elixxir.dapp.bindings.model.GroupInfo
import io.elixxir.dapp.bindings.model.GroupReport
import io.elixxir.dapp.group.model.Group
import io.elixxir.dapp.group.model.GroupId
internal interface GroupChat {
fun getGroup(groupId: GroupId)
fun joinGroup()
fun leaveGroup()
fun makeGroup()
fun resendInvitation()
fun getGroup(groupId: GroupId): Group
fun joinGroup(trackedGroupId: Long)
fun leaveGroup(groupId: GroupId)
fun makeGroup(info: GroupInfo): GroupReport
fun resendInvitations(group: Group): GroupReport
}
\ No newline at end of file
package io.elixxir.dapp.bindings.data
import io.elixxir.dapp.bindings.model.GroupAdapter
import io.elixxir.dapp.bindings.model.GroupInfo
import io.elixxir.dapp.bindings.model.GroupReport
import io.elixxir.dapp.group.model.Group
import io.elixxir.dapp.group.model.GroupId
import bindings.GroupChat as CoreGroupChat
internal class GroupChatAdapter(private val groupChat: CoreGroupChat) : GroupChat {
override fun getGroup(groupId: GroupId) {
TODO("Not yet implemented")
override fun getGroup(groupId: GroupId): Group {
return GroupAdapter(groupChat.getGroup(groupId.value))
}
override fun joinGroup() {
TODO("Not yet implemented")
override fun joinGroup(trackedGroupId: Long) {
groupChat.joinGroup(trackedGroupId)
}
override fun leaveGroup() {
TODO("Not yet implemented")
override fun leaveGroup(groupId: GroupId) {
groupChat.leaveGroup(groupId.value)
}
override fun makeGroup() {
TODO("Not yet implemented")
override fun makeGroup(info: GroupInfo): GroupReport {
return GroupReport(
groupChat.makeGroup(
info.membershipData.value,
info.description.toByteArray(),
info.name.toByteArray())
)
}
override fun resendInvitation() {
TODO("Not yet implemented")
override fun resendInvitations(group: Group): GroupReport {
return GroupReport(
groupChat.resendRequest(group.groupId.value)
)
}
}
\ No newline at end of file
package io.elixxir.dapp.bindings.model
import io.elixxir.dapp.group.model.GroupId
internal interface Group {
val id: GroupId
val name: String
val initMessage: String
val members: List<String>
val creationTimeMs: Long
}
\ No newline at end of file
package io.elixxir.dapp.bindings.model
import io.elixxir.dapp.group.model.Group
import io.elixxir.dapp.group.model.GroupId
import io.elixxir.dapp.user.model.User
import bindings.Group as CoreGroup
@JvmInline
internal value class GroupAdapter(val value: CoreGroup): Group {
override val groupId: GroupId
get() = GroupId(value.id)
override val name: String
get() = String(value.name)
override val description: String
get() = String(value.initMessage)
override val members: List<User>
get() = listOf()
override val creator: User
get() = User.placeholder
}
\ No newline at end of file
package io.elixxir.dapp.bindings.model
internal data class GroupInfo(
val membershipData: GroupMembership,
val description: String,
val name: String
)
\ No newline at end of file
package io.elixxir.dapp.bindings.model
@JvmInline
internal value class GroupMembership(val value: ByteArray)
\ No newline at end of file
package io.elixxir.dapp.bindings.model
@JvmInline
internal value class GroupReport(val value: ByteArray)
\ No newline at end of file
package io.elixxir.dapp.bindings.model
internal interface NetworkHealthListener {
fun onHealthChanged(isHealthy: Boolean)
}
internal class HealthCallbackAdapter(
private val listener: NetworkHealthListener
) : NetworkHealthListener by listener,
bindings.NetworkHealthCallback
{
override fun callback(isHealthy: Boolean) {
onHealthChanged(isHealthy)
}
companion object {
val placeholder: HealthCallbackAdapter =
HealthCallbackAdapter(
object : NetworkHealthListener {
override fun onHealthChanged(isHealthy: Boolean) { }
}
)
}
}
\ No newline at end of file
package io.elixxir.dapp.bindings.model
@JvmInline
internal value class HealthListenerId(val value: Long)
\ No newline at end of file
package io.elixxir.dapp.bindings.model
class NodeRegistrationStatus {
}
\ No newline at end of file
@JvmInline
internal value class NodeRegistrationStatus(val value: ByteArray)
\ No newline at end of file
......@@ -3,6 +3,16 @@ package io.elixxir.dapp.user.model
interface User {
val userId: Long
val username: String
val phone: String
val email: String
val phone: String?
val email: String?
companion object {
val placeholder = object : User {
override val userId: Long = 0
override val username: String = ""
override val phone: String? = null
override val email: String? = null
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment