Skip to content

Contact Object

David Barnett edited this page Oct 28, 2016 · 3 revisions

The contact object is defined here

Life Cycle of Contact Object

A contact object is built from a "raw Contact" which is what is exactly what is stored in the database.

It is generally created by the Database as it moves through the data layer to the UI.

After changes have been made and it is being written back into the database the toJSON() converts the object back into a database-friendly JSON object.

Features

The main feature for this translation between Database layer and Data layer is to filter out any unknown values that might of been added to the object and to give the convenance of translating the jCard's into ICAL.Components for you.

Example

Example raw contact:

{name: "Simon Perreault", email: "[email protected]" , jcards: [
      ["vcard", [
        ["version", {}, "text", "4.0"],
        ["fn", {}, "text", "Simon Perreault"],
        ["n", {}, "text", ["Perreault", "Simon", "", "", ["ing. jr", "M.Sc."]] ],
        ["bday", {}, "date-and-or-time", "--02-03"],
        ["anniversary", {}, "date-and-or-time", "2009-08-08T14:30:00-05:00" ],
        ["gender", {}, "text", "M"],
        ["lang", { "pref": "1" }, "language-tag", "fr"],
        ["lang", { "pref": "2" }, "language-tag", "en"],
        ["org", { "type": "work" }, "text", "Viagenie"],
        ["adr", { "type": "work" }, "text", [ "", "Suite D2-630", "2875 Laurier", "Quebec", "QC", "G1V 2M2", "Canada" ] ],
        ["tel", { "type": ["work", "voice"], "pref": "1" }, "uri", "tel:+1-418-656-9254;ext=102" ],
        ["tel", { "type": ["work", "cell", "voice", "video", "text"] }, "uri", "tel:+1-418-262-6501" ],
        ["email", { "type": "work" }, "text", "[email protected]" ],
        ["geo", { "type": "work" }, "uri", "geo:46.772673,-71.282945"],
        ["key", { "type": "work" }, "uri", "http://www.viagenie.ca/simon.perreault/simon.asc" ],
        ["tz", {}, "utc-offset", "-05:00"],
        ["url", { "type": "home" }, "uri", "http://nomis80.org"]
      ]]
]}

API

Methods

Constructor

The constructor for the contact object takes a raw contact.

var contact = new Contact(rawContact);

toJSON() -> Object

Converts the contact into a database-friendly JSON object.

contact.toJSON();

Fields

The publicly available fields of a Contact Object

uuid - Number

The UUID number of the contact object in the database, can be undefined if the entry is new.

If the UUID already exists in the database when update'ing will overwrite the older entry as per a IndexedDB Transaction put describes.

name - String

The display name for the contact.

Is chosen at import stage and has a priority to grab the name from following vCard properties in order:

  • fn - Formatted Name
  • n - Full name
  • email - The email address, more specifically the 1st email address.

photo - Blob

A blob that contains the contact's profile picture.

Can be undefined if the contact has no profile picture.

Note: During an import if the vCard has an embedded photo property with a base64 encoding image, it will be automatically added to the contact.

jcards - ICAL.Compoents[]

A list of ICAL.Components which are from the jCards from the database.

This is a list of jCards to allow for merging multiple provider's vCards about a person into one contact.