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
No related branches found
No related tags found
No related merge requests found
Showing
with 155 additions and 52 deletions
package io.elixxir.dapp.bindings.data 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.NetworkFollowerStatus import io.elixxir.dapp.bindings.model.NetworkFollowerStatus
import io.elixxir.dapp.bindings.model.NodeRegistrationStatus
internal interface Cmix { internal interface Cmix {
fun connect(): Connection fun connect(
fun startNetworkFollower() e2eId: E2eId,
recipientContact: Contact,
e2eParams: E2eParams
): Connection
fun startNetworkFollower(timeoutMs: Long)
fun stopNetworkFollower() fun stopNetworkFollower()
fun isNetworkHealthy(): Boolean fun isNetworkHealthy(): Boolean
fun registerHealthCallback()
fun unregisterHealthCallback() fun registerHealthListener(listener: NetworkHealthListener): HealthListenerId
fun unregisterHealthListener(id: HealthListenerId)
fun getNodeRegistrationStatus(): NodeRegistrationStatus fun getNodeRegistrationStatus(): NodeRegistrationStatus
fun makeReceptionIdentity(): ReceptionIdentity fun makeReceptionIdentity(): ReceptionIdentity
fun getNetworkFollowerStatus(): NetworkFollowerStatus fun getNetworkFollowerStatus(): NetworkFollowerStatus
} }
package io.elixxir.dapp.bindings.data 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.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.NetworkFollowerStatus
import io.elixxir.dapp.bindings.model.NodeRegistrationStatus
import bindings.Cmix as CoreCmix import bindings.Cmix as CoreCmix
@JvmInline @JvmInline
internal value class CmixAdapter(private val cmix: CoreCmix) : Cmix { internal value class CmixAdapter(private val cmix: CoreCmix) : Cmix {
override fun connect(): Connection { override fun connect(
TODO("Not yet implemented") 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() { override fun startNetworkFollower(timeoutMs: Long) {
TODO("Not yet implemented") cmix.startNetworkFollower(timeoutMs)
} }
override fun stopNetworkFollower() { override fun stopNetworkFollower() {
TODO("Not yet implemented") cmix.stopNetworkFollower()
} }
override fun isNetworkHealthy(): Boolean { override fun isNetworkHealthy(): Boolean {
TODO("Not yet implemented") return cmix.isHealthy
} }
override fun registerHealthCallback() { override fun registerHealthListener(listener: NetworkHealthListener): HealthListenerId {
TODO("Not yet implemented") return HealthListenerId(
cmix.addHealthCallback(HealthCallbackAdapter.placeholder)
)
} }
override fun unregisterHealthCallback() { override fun unregisterHealthListener(id: HealthListenerId) {
TODO("Not yet implemented") cmix.removeHealthCallback(id.value)
} }
override fun getNodeRegistrationStatus(): NodeRegistrationStatus { override fun getNodeRegistrationStatus(): NodeRegistrationStatus {
TODO("Not yet implemented") return NodeRegistrationStatus(cmix.nodeRegistrationStatus)
} }
override fun makeReceptionIdentity(): ReceptionIdentity { override fun makeReceptionIdentity(): ReceptionIdentity {
TODO("Not yet implemented") return ReceptionIdentity(cmix.makeReceptionIdentity())
} }
override fun getNetworkFollowerStatus(): NetworkFollowerStatus { 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 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 import io.elixxir.dapp.group.model.GroupId
internal interface GroupChat { internal interface GroupChat {
fun getGroup(groupId: GroupId) fun getGroup(groupId: GroupId): Group
fun joinGroup() fun joinGroup(trackedGroupId: Long)
fun leaveGroup() fun leaveGroup(groupId: GroupId)
fun makeGroup() fun makeGroup(info: GroupInfo): GroupReport
fun resendInvitation() fun resendInvitations(group: Group): GroupReport
} }
\ No newline at end of file
package io.elixxir.dapp.bindings.data 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 io.elixxir.dapp.group.model.GroupId
import bindings.GroupChat as CoreGroupChat import bindings.GroupChat as CoreGroupChat
internal class GroupChatAdapter(private val groupChat: CoreGroupChat) : GroupChat { internal class GroupChatAdapter(private val groupChat: CoreGroupChat) : GroupChat {
override fun getGroup(groupId: GroupId) { override fun getGroup(groupId: GroupId): Group {
TODO("Not yet implemented") return GroupAdapter(groupChat.getGroup(groupId.value))
} }
override fun joinGroup() { override fun joinGroup(trackedGroupId: Long) {
TODO("Not yet implemented") groupChat.joinGroup(trackedGroupId)
} }
override fun leaveGroup() { override fun leaveGroup(groupId: GroupId) {
TODO("Not yet implemented") groupChat.leaveGroup(groupId.value)
} }
override fun makeGroup() { override fun makeGroup(info: GroupInfo): GroupReport {
TODO("Not yet implemented") return GroupReport(
groupChat.makeGroup(
info.membershipData.value,
info.description.toByteArray(),
info.name.toByteArray())
)
} }
override fun resendInvitation() { override fun resendInvitations(group: Group): GroupReport {
TODO("Not yet implemented") 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 package io.elixxir.dapp.bindings.model
class NodeRegistrationStatus { @JvmInline
} internal value class NodeRegistrationStatus(val value: ByteArray)
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,16 @@ package io.elixxir.dapp.user.model ...@@ -3,6 +3,16 @@ package io.elixxir.dapp.user.model
interface User { interface User {
val userId: Long val userId: Long
val username: String val username: String
val phone: String val phone: String?
val email: 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