> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Contacts コレクション

`contacts` は、共有ダイアログが候補として提案できるように、ユーザーがどのユーザーと共同作業したかを記録します。ユーザーごとに 1 つのドキュメントです。`web` が管理しており、Mongoose スキーマはありません。コードは `services/web/app/src/Features/Contacts/ContactManager.mjs` です。

#### フィールド

| フィールド | 型 | 意味 | 出典 |
| - | - | - | - |
| `_id` | ObjectId | ドキュメント id。upsert によって作成されます。 | `ContactManager.mjs:5-12` |
| `user_id` | ObjectId | これらの連絡先の持ち主であるユーザー。ユーザーごとに 1 つのドキュメントです。 | `ContactManager.mjs:6` |
| `contacts` | Object | 連絡先のユーザー id（文字列）をキーとするマップ。 | `ContactManager.mjs:8-9` |
| `contacts.<userId>.n` | Number | 2 人のユーザーが結び付けられた回数。 | `ContactManager.mjs:8` |
| `contacts.<userId>.ts` | Date | 最後にそれが起きた日時。 | `ContactManager.mjs:9` |

#### 書き込むコード

| コード | 動作 |
| - | - |
| `ContactManager.mjs:4-13` (`touchContact`), `:23-28` (`addContact`) | 両方のユーザーのドキュメントを upsert します: `n` に `$inc`、`ts` に `$set`。 |
| `services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs:155-157` | `addUserIdToProject` は、追加したユーザーが渡された場合に `addContact` を呼び出します。招待の承諾時（招待者と被招待者、`services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs:199-205`）と所有権の移転時（新旧の所有者、`services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs:138-144`）です。共有リンクから参加した場合は追加したユーザーが渡されないため（`services/web/app/src/Features/TokenAccess/TokenAccessController.mjs:386-388`、`:632-634`）、連絡先は追加されません。 |

#### 読み取るコード

| コード | 動作 |
| - | - |
| `ContactManager.mjs:15-21`, `:30-42` | `getContactIds`: `n`、次に `ts` の順で、どちらも大きい順に並べます。 |
| `services/web/app/src/Features/Contacts/ContactController.mjs:19-59` | `GET /user/contacts` (`services/web/app/src/Features/Contacts/ContactRouter.mjs:22-26`): 上位 50 件をユーザーとして返し（仮アカウントは除く）、モジュールが `getContacts` フックで追加するものも含めます。 |

#### インデックス

| 名前 | キー | オプション | マイグレーション |
| - | - | - | - |
| `user_id_1` | `{ user_id: 1 }` | unique | `tools/migrations/20190912145001_create_contacts_indexes.mjs` |

#### 補足

* 連絡先は双方向です。B を A のプロジェクトに追加すると、B は A の連絡先になり、A も B の連絡先になります。
* 連絡先やドキュメントを削除する処理はなく、ユーザーが削除されても残ります。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.