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

feat: add "received at" timestamp to invites #529

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@
"ecmaVersion": 13,
"sourceType": "module"
},
"rules": {}
"rules": {
"no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use varsIgnorePattern in this PR, but not argsIgnorePattern. I added it for consistency.

}
]
}
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -90,7 +98,7 @@
"eslint": "^8.57.0",
"filter-obj": "^6.0.0",
"husky": "^8.0.0",
"iterpal": "^0.3.0",
"iterpal": "^0.4.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Necessary to pull in compact for tests.

"light-my-request": "^5.10.0",
"lint-staged": "^14.0.1",
"mapeo-offline-map": "^2.0.0",
Expand Down
24 changes: 17 additions & 7 deletions src/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import { assert, keyToId, noop } from './utils.js'
import HashMap from './lib/hashmap.js'
import timingSafeEqual from './lib/timing-safe-equal.js'

// There are three slightly different invite types:
//
// - InviteRpcMessage comes from the protobuf.
// - InviteInternal adds a locally-generated receive timestamp.
// - Invite is the externally-facing type.

/**
* @internal
* @typedef {import('./generated/rpc.js').Invite} InviteRpcMessage
*/

/**
* Internally, we typically use the `Invite` type from the protobuf. We also use
* an external type for public consumers.
*
* @internal
* @typedef {import('./generated/rpc.js').Invite} InviteInternal
* @typedef {InviteRpcMessage & { receivedAt: number }} InviteInternal
*/

/** @typedef {import('./types.js').MapBuffers<InviteInternal>} Invite */
Expand Down Expand Up @@ -153,7 +161,7 @@ export class InviteApi extends TypedEmitter {

this.rpc.on('invite', (...args) => {
try {
this.#handleInvite(...args)
this.#handleInviteRpcMessage(...args)
} catch (err) {
console.error('Error handling invite', err)
}
Expand All @@ -162,9 +170,11 @@ export class InviteApi extends TypedEmitter {

/**
* @param {string} peerId
* @param {InviteInternal} invite
* @param {InviteRpcMessage} inviteRpcMessage
*/
#handleInvite(peerId, invite) {
#handleInviteRpcMessage(peerId, inviteRpcMessage) {
const invite = { ...inviteRpcMessage, receivedAt: Date.now() }

const isAlreadyMember = this.#isMember(invite.projectPublicId)
if (isAlreadyMember) {
this.rpc
Expand Down
Loading
Loading