Skip to content

Commit

Permalink
feat: Remove special case for "me" update
Browse files Browse the repository at this point in the history
I had to start with a special case for "me" update, because in Cozy
Contacts, relations were stored only in the contact who created the
relation.

So when "me" was updated, a relation of me could have been deleted,
and it was impossible to know which one easily, so it was impossible
to know if the contact should be removed from the extension.

With cozy/cozy-contacts#1020, relations are
propagated to the target contact.

So we will get a realtime event and we will be able to check if the
contact must be displayed or not without any special case.

And I can also check that a contact is related to me directly by checking
its relationships now.
  • Loading branch information
zatteo committed Nov 18, 2024
1 parent f6d4271 commit 2469e49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
10 changes: 0 additions & 10 deletions apps/browser/src/cozy/realtime/RealtimeNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ export class RealTimeNotifications {
}

async dispatchUpdateContact(data: IOCozyContact) {
if (data.me) {
// We need to do a fullSync here because we have no other way to know
// if a contact related to me was removed of the me relation
this.logService.info(`Starting full sync from realtime because me`);

this.messagingService.send("fullSync");

return;
}

const contactMustBeDisplayed = await shouldDisplayContact(this.client, data);

if (contactMustBeDisplayed) {
Expand Down
11 changes: 6 additions & 5 deletions libs/cozy/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data";

import { CozyClientService } from "../../apps/browser/src/popup/services/cozyClient.service";

import { CONTACTS_DOCTYPE } from "./constants";
import { convertAllContactsAsCiphers } from "./contactCipher";
import { convertAllPapersAsCiphers } from "./paperCipher";
import { fetchContactsAndPapers, fetchPapers, fetchMyself } from "./queries";
Expand All @@ -24,11 +25,11 @@ export const shouldDisplayContact = async (client: CozyClient, contact: IOCozyCo

const me = await fetchMyself(client);

const contactRelatedToMe = // @ts-expect-error related added manually with an hydration
me[0].relationships?.related?.data?.find(
// @ts-expect-error related added manually with an hydration
(relatedContact) => relatedContact._id === contact._id,
);
// @ts-expect-error related added manually with an hydration
const contactRelatedToMe = contact.relationships?.related?.data?.find(
// @ts-expect-error related added manually with an hydration
(relation) => relation._id === me[0]._id && relation._type === CONTACTS_DOCTYPE,
);

if (contactRelatedToMe) {
return true;
Expand Down

0 comments on commit 2469e49

Please sign in to comment.