Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions extension/js/common/platform/store/contact-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ export class ContactStore extends AbstractStore {
}

/**
* Used to save a contact that does not yet exist
* Used to save a contact or an array of contacts.
* An underlying update operation is used for each of the provided contact.
* Properties `name` and `lastUse` are overwritten if the contact already exists,
* whereas `pubkey` and `pubkeyLastCheck` are added/updated as described in the `update` remarks.
*
* @param {IDBDatabase} db (optional) database to use
* @param {Contact | Contact[]} email a single contact or an array of contacts
* @returns {Promise<void>}
*
* @async
* @static
*/
public static save = async (db: IDBDatabase | undefined, contact: Contact | Contact[]): Promise<void> => {
if (!db) { // relay op through background process
Expand All @@ -156,7 +166,24 @@ export class ContactStore extends AbstractStore {
}

/**
* used to update existing contact
* Used to update certain fields of existing contacts or create new contacts using the provided data.
* If an array of emails is provided, the update operation will be performed independently on each of them.
* Missing properties from update object will not be overwritten in the database,
* e.g. `{name} as ContactUpdate` will retain the `lastUse` value of the existing record,
* whereas `{lastUse:null} as ContactUpdate` will reset `lastUse` to null.
* The `pubkey` property will be used only to add or update a pubkey record by the pubkey fingerprint.
* Null value of `pubkey` won't affect any pubkey records.
* The `pubkeyLastCheck` property can be set to a non-null value only when `pubkey` specified
* and will be applied only to that specific pubkey record. Missing or null `pubkeyLastCheck` will
Copy link
Contributor Author

@rrrooommmaaa rrrooommmaaa Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bit inconsistent behaviour. We can reset name and lastUse properties of the contact by providing null values in the update parameter, whereas pubkeyLastCheck will be ignored if null is provided. It's impossible to reset it. Should we do property existence check on it as with other properties or leave as it is, @tomholub ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name and lastUse should not be ever reset (no point setting name from something to null, and no point setting lastUse from something to null either). Thanks for noticing!

* leave the `pubkeyLastCheck` value of the existing pubkey unchanged.
*
* @param {IDBDatabase} db (optional) database to use
* @param {string | string[]} email a single email or an array of emails
* @param {ContactUpdate} update object containing fields to be updated
* @returns {Promise<void>}
*
* @async
* @static
*/
public static update = async (db: IDBDatabase | undefined, email: string | string[], update: ContactUpdate): Promise<void> => {
if (!db) { // relay op through background process
Expand Down