Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better management of realtime with contacts #334

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

zatteo
Copy link

@zatteo zatteo commented Nov 14, 2024

No description provided.

@zatteo zatteo changed the title Fix/contacts displayed realtime Better management of realtime with contacts Nov 14, 2024
@zatteo zatteo force-pushed the fix/contacts-displayed-realtime branch 2 times, most recently from 606b7d8 to 202505e Compare November 15, 2024 12:51
definition: Q(CONTACTS_DOCTYPE).where({ me: true }),
options: {
as: `${CONTACTS_DOCTYPE}/myself`,
singleDocData: true,
Copy link
Member

Choose a reason for hiding this comment

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

Le singleDocData est inutile ici je pense, il ne marche qu'avec .getById

export const fetchMyself = async (client: CozyClient): Promise<IOCozyContact> => {
const myselfQuery = buildMyselfQuery();

const { data }: { data: IOCozyContact } = await client.query(
Copy link
Member

Choose a reason for hiding this comment

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

Du coup ici IOCozyContact[]


const contactRelatedToMe =
// @ts-expect-error related added manually with an hydration
me?.[0]?.relationships?.related?.data.find((relatedContact) => relatedContact._id === contact._id);
Copy link
Member

@Merkur39 Merkur39 Nov 15, 2024

Choose a reason for hiding this comment

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

me?.l'opérateur optionnel ne devrait pas être nécessaire ici, si ? Et il manque entre data.find

Comment on lines 78 to 86
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`)

await dispatchUpdate(this.client, "io.cozy.contacts", data as CouchDBDocument);
this.messagingService.send("fullSync");

return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Waiting new PR from cozy-contacts

New name more precisely show that we only fetch me and favorites.
It was possible to add a contact in the browser extension from
realtime even if we did not want it in the browser extension.
=> a paper with potential contact inside
me[0] should exist here because every one has me. But after we should use it until the end.
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.
@zatteo zatteo force-pushed the fix/contacts-displayed-realtime branch from 202505e to 3c915eb Compare November 15, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants