Skip to content

Commit

Permalink
Add new fields to Contact
Browse files Browse the repository at this point in the history
This commit add new fields described in #6590 to the model and adapts
the ContactEditor and ContactViewer to handle the new fields.
  • Loading branch information
murilopereirame committed Mar 11, 2024
1 parent d0830fc commit eb9c06d
Show file tree
Hide file tree
Showing 64 changed files with 2,436 additions and 673 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package de.tutao.tutanota.contacts

import android.provider.ContactsContract
import de.tutao.tutanota.ipc.StructuredAddress
import de.tutao.tutanota.ipc.StructuredContact
import de.tutao.tutanota.ipc.StructuredMailAddress
import de.tutao.tutanota.ipc.StructuredPhoneNumber
import de.tutao.tutanota.ipc.*

data class AndroidEmailAddress(
val address: String,
Expand All @@ -24,22 +21,52 @@ data class AndroidPhoneNumber(
val customTypeName: String
)

data class AndroidWebsite(
val url: String,
val type: Int,
val customTypeName: String
)

data class AndroidRelationship(
val person: String,
val type: Int,
val customTypeName: String
)

data class AndroidCustomDate(
val dateIso: String,
val type: Int,
val customTypeName: String
)

/**
* Representation of RawContact + ContractsContract.Data from Android.
*/
data class AndroidContact(
val rawId: Long,
val sourceId: String?,
var givenName: String? = null,
var lastName: String? = null,
var company: String = "",
var nickname: String = "",
var birthday: String? = null,
val emailAddresses: MutableList<AndroidEmailAddress> = mutableListOf(),
val phoneNumbers: MutableList<AndroidPhoneNumber> = mutableListOf(),
val addresses: MutableList<AndroidAddress> = mutableListOf(),
var isDeleted: Boolean = false,
var isDirty: Boolean = false
val rawId: Long,
val sourceId: String?,
var givenName: String? = null,
var lastName: String? = null,
var company: String = "",
var nickname: String = "",
var birthday: String? = null,
val emailAddresses: MutableList<AndroidEmailAddress> = mutableListOf(),
val phoneNumbers: MutableList<AndroidPhoneNumber> = mutableListOf(),
val addresses: MutableList<AndroidAddress> = mutableListOf(),
var isDeleted: Boolean = false,
var isDirty: Boolean = false,
var department: String? = null,
var middleName: String? = null,
var nameSuffix: String? = null,
var phoneticFirst: String? = null,
var phoneticMiddle: String? = null,
var phoneticLast: String? = null,
val customDate: MutableList<AndroidCustomDate> = mutableListOf(),
val websites: MutableList<AndroidWebsite> = mutableListOf(),
val relationships: MutableList<AndroidRelationship> = mutableListOf(),
var notes: String = "",
var title: String = "",
var role: String = ""
) {
fun toStructured(): StructuredContact {
return StructuredContact(
Expand All @@ -53,6 +80,20 @@ data class AndroidContact(
phoneNumbers = phoneNumbers.map { it.toStructured() },
addresses = addresses.map { it.toStructured() },
rawId = rawId.toString(),
department = department,
middleName = middleName,
nameSuffix = nameSuffix,
phoneticFirst = phoneticFirst,
phoneticMiddle = phoneticMiddle,
phoneticLast = phoneticLast,
customDate = customDate.map { it.toStructured() },
messengerHandles = listOf(), // Will be deprecated on Android 15, not worth to implement now
websites = websites.map { it.toStructured() },
relationships = relationships.map { it.toStructured() },
pronouns = listOf(), // Not supported on Android
notes = notes,
title = title,
role = role
)
}
}
Expand All @@ -74,17 +115,91 @@ fun ContactPhoneNumberType.toAndroidType(): Int = when (this) {
}

fun AndroidEmailAddress.toStructured() = StructuredMailAddress(
address = address,
type = addressTypeFromAndroid(type),
customTypeName = customTypeName
address = address,
type = addressTypeFromAndroid(type),
customTypeName = customTypeName
)

fun AndroidPhoneNumber.toStructured() = StructuredPhoneNumber(
number = number,
type = phoneNumberTypeFromAndroid(type),
customTypeName = customTypeName
number = number,
type = phoneNumberTypeFromAndroid(type),
customTypeName = customTypeName
)

fun ContactRelationshipType.toAndroidType(): Int = when (this) {
ContactRelationshipType.PARENT -> ContactsContract.CommonDataKinds.Relation.TYPE_PARENT
ContactRelationshipType.BROTHER -> ContactsContract.CommonDataKinds.Relation.TYPE_BROTHER
ContactRelationshipType.SISTER -> ContactsContract.CommonDataKinds.Relation.TYPE_SISTER
ContactRelationshipType.CHILD -> ContactsContract.CommonDataKinds.Relation.TYPE_CHILD
ContactRelationshipType.FRIEND -> ContactsContract.CommonDataKinds.Relation.TYPE_FRIEND
ContactRelationshipType.RELATIVE -> ContactsContract.CommonDataKinds.Relation.TYPE_RELATIVE
ContactRelationshipType.SPOUSE -> ContactsContract.CommonDataKinds.Relation.TYPE_SPOUSE
ContactRelationshipType.PARTNER -> ContactsContract.CommonDataKinds.Relation.TYPE_PARTNER
ContactRelationshipType.ASSISTANT -> ContactsContract.CommonDataKinds.Relation.TYPE_ASSISTANT
ContactRelationshipType.MANAGER -> ContactsContract.CommonDataKinds.Relation.TYPE_MANAGER
ContactRelationshipType.CUSTOM -> ContactsContract.CommonDataKinds.Relation.TYPE_CUSTOM
else -> ContactsContract.CommonDataKinds.Relation.TYPE_CUSTOM
}

fun ContactWebsiteType.toAndroidType(): Int = when (this) {
ContactWebsiteType.PRIVATE -> ContactsContract.CommonDataKinds.Website.TYPE_HOME
ContactWebsiteType.WORK -> ContactsContract.CommonDataKinds.Website.TYPE_WORK
ContactWebsiteType.CUSTOM -> ContactsContract.CommonDataKinds.Website.TYPE_CUSTOM
else -> ContactsContract.CommonDataKinds.Website.TYPE_OTHER
}

fun ContactCustomDateType.toAndroidType(): Int = when (this) {
ContactCustomDateType.ANNIVERSARY -> ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY
ContactCustomDateType.CUSTOM -> ContactsContract.CommonDataKinds.Event.TYPE_CUSTOM
else -> ContactsContract.CommonDataKinds.Event.TYPE_OTHER
}

fun AndroidCustomDate.toStructured() = StructuredCustomDate(
dateIso = dateIso,
type = dateTypeFromAndroid(type),
customTypeName = customTypeName
)

fun AndroidWebsite.toStructured() = StructuredWebsite(
url = url,
type = websiteTypeFromAndroid(type),
customTypeName = customTypeName
)

fun AndroidRelationship.toStructured() = StructuredRelationship(
person = person,
type = relationshipTypeFromAndroid(type),
customTypeName = customTypeName
)

fun relationshipTypeFromAndroid(androidType: Int): ContactRelationshipType = when (androidType) {
ContactsContract.CommonDataKinds.Relation.TYPE_PARENT -> ContactRelationshipType.PARENT
ContactsContract.CommonDataKinds.Relation.TYPE_BROTHER -> ContactRelationshipType.BROTHER
ContactsContract.CommonDataKinds.Relation.TYPE_SISTER -> ContactRelationshipType.SISTER
ContactsContract.CommonDataKinds.Relation.TYPE_CHILD -> ContactRelationshipType.CHILD
ContactsContract.CommonDataKinds.Relation.TYPE_FRIEND -> ContactRelationshipType.FRIEND
ContactsContract.CommonDataKinds.Relation.TYPE_RELATIVE -> ContactRelationshipType.RELATIVE
ContactsContract.CommonDataKinds.Relation.TYPE_SPOUSE -> ContactRelationshipType.SPOUSE
ContactsContract.CommonDataKinds.Relation.TYPE_PARTNER -> ContactRelationshipType.PARTNER
ContactsContract.CommonDataKinds.Relation.TYPE_ASSISTANT -> ContactRelationshipType.ASSISTANT
ContactsContract.CommonDataKinds.Relation.TYPE_MANAGER -> ContactRelationshipType.MANAGER
ContactsContract.CommonDataKinds.Relation.TYPE_CUSTOM -> ContactRelationshipType.CUSTOM
else -> ContactRelationshipType.OTHER
}

fun websiteTypeFromAndroid(androidType: Int): ContactWebsiteType = when (androidType) {
ContactsContract.CommonDataKinds.Website.TYPE_HOME -> ContactWebsiteType.PRIVATE
ContactsContract.CommonDataKinds.Website.TYPE_WORK -> ContactWebsiteType.WORK
ContactsContract.CommonDataKinds.Website.TYPE_CUSTOM -> ContactWebsiteType.CUSTOM
else -> ContactWebsiteType.WORK
}

fun dateTypeFromAndroid(androidType: Int): ContactCustomDateType = when (androidType) {
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY -> ContactCustomDateType.ANNIVERSARY
ContactsContract.CommonDataKinds.Event.TYPE_CUSTOM -> ContactCustomDateType.CUSTOM
else -> ContactCustomDateType.OTHER
}

fun addressTypeFromAndroid(androidType: Int): ContactAddressType = when (androidType) {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> ContactAddressType.PRIVATE
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> ContactAddressType.WORK
Expand All @@ -104,7 +219,7 @@ fun phoneNumberTypeFromAndroid(androidType: Int): ContactPhoneNumberType = when
}

fun AndroidAddress.toStructured() = StructuredAddress(
address = address,
type = addressTypeFromAndroid(type),
customTypeName = customTypeName
address = address,
type = addressTypeFromAndroid(type),
customTypeName = customTypeName
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,95 @@ enum class ContactPhoneNumberType {

@SerialName("5")
CUSTOM,
}

/** Mirror of ContactCustomDateType from TutanotaConstants */
@Serializable
enum class ContactCustomDateType {
@SerialName("0")
ANNIVERSARY,

@SerialName("1")
OTHER,

@SerialName("2")
CUSTOM,
}

/** Mirror of ContactWebsiteType from TutanotaConstants */
@Serializable
enum class ContactWebsiteType {
@SerialName("0")
PRIVATE,

@SerialName("1")
WORK,

@SerialName("2")
OTHER,

@SerialName("3")
CUSTOM,
}

/** Mirror of ContactWebsiteType from TutanotaConstants */
@Serializable
enum class ContactMessengerHandleType {
@SerialName("0")
SIGNAL,

@SerialName("1")
WHATSAPP,

@SerialName("2")
TELEGRAM,

@SerialName("3")
DISCORD,

@SerialName("4")
OTHER,

@SerialName("5")
CUSTOM
}

/** Mirror of ContactWebsiteType from TutanotaConstants */
@Serializable
enum class ContactRelationshipType {
@SerialName("0")
PARENT,

@SerialName("1")
BROTHER,

@SerialName("2")
SISTER,

@SerialName("3")
CHILD,

@SerialName("4")
FRIEND,

@SerialName("5")
RELATIVE,

@SerialName("6")
SPOUSE,

@SerialName("7")
PARTNER,

@SerialName("8")
ASSISTANT,

@SerialName("9")
MANAGER,

@SerialName("10")
OTHER,

@SerialName("11")
CUSTOM,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc
typealias ContactCustomDateType = de.tutao.tutanota.contacts.ContactCustomDateType
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc
typealias ContactMessengerHandleType = de.tutao.tutanota.contacts.ContactMessengerHandleType
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc
typealias ContactRelationshipType = de.tutao.tutanota.contacts.ContactRelationshipType
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc
typealias ContactWebsiteType = de.tutao.tutanota.contacts.ContactWebsiteType
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MobileContactsFacadeReceiveDispatcher(
private val json: Json,
private val facade: MobileContactsFacade,
) {

suspend fun dispatch(method: String, arg: List<String>): String {
when (method) {
"findSuggestions" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ data class StructuredContact(
val phoneNumbers: List<StructuredPhoneNumber>,
val addresses: List<StructuredAddress>,
val rawId: String?,
val customDate: List<StructuredCustomDate>,
val department: String?,
val messengerHandles: List<StructuredMessengerHandle>,
val middleName: String?,
val nameSuffix: String?,
val phoneticFirst: String?,
val phoneticLast: String?,
val phoneticMiddle: String?,
val relationships: List<StructuredRelationship>,
val websites: List<StructuredWebsite>,
val notes: String,
val title: String,
val role: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc

import kotlinx.serialization.*
import kotlinx.serialization.json.*


@Serializable
data class StructuredCustomDate(
val dateIso: String,
val type: ContactCustomDateType,
val customTypeName: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated file, don't edit. */


package de.tutao.tutanota.ipc

import kotlinx.serialization.*
import kotlinx.serialization.json.*


@Serializable
data class StructuredMessengerHandle(
val handle: String,
val type: ContactMessengerHandleType,
val customTypeName: String,
)
Loading

0 comments on commit eb9c06d

Please sign in to comment.