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: save self-hosted server details on member info #943

Merged
merged 1 commit into from
Oct 28, 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
3 changes: 2 additions & 1 deletion src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export class MapeoProject extends TypedEmitter {
}

/**
* @param {Pick<import('@comapeo/schema').DeviceInfoValue, 'name' | 'deviceType'>} value
* @param {Pick<import('@comapeo/schema').DeviceInfoValue, 'name' | 'deviceType' | 'selfHostedServerDetails'>} value
* @returns {Promise<import('@comapeo/schema').DeviceInfo>}
*/
async [kSetOwnDeviceInfo](value) {
Expand All @@ -640,6 +640,7 @@ export class MapeoProject extends TypedEmitter {
const doc = {
name: value.name,
deviceType: value.deviceType,
selfHostedServerDetails: value.selfHostedServerDetails,
schemaName: /** @type {const} */ ('deviceInfo'),
}

Expand Down
4 changes: 4 additions & 0 deletions src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { ROLES, isRoleIdForNewInvite } from './roles.js'
* @prop {DeviceInfo['name']} [name]
* @prop {DeviceInfo['deviceType']} [deviceType]
* @prop {DeviceInfo['createdAt']} [joinedAt]
* @prop {object} [selfHostedServerDetails]
* @prop {string} selfHostedServerDetails.baseUrl
*/

export class MemberApi extends TypedEmitter {
Expand Down Expand Up @@ -304,6 +306,8 @@ export class MemberApi extends TypedEmitter {
memberInfo.name = deviceInfo?.name
memberInfo.deviceType = deviceInfo?.deviceType
memberInfo.joinedAt = deviceInfo?.createdAt
memberInfo.selfHostedServerDetails =
deviceInfo?.selfHostedServerDetails
} catch (err) {
// Attempting to get someone else may throw because sync hasn't occurred or completed
// Only throw if attempting to get themself since the relevant information should be available
Expand Down
18 changes: 12 additions & 6 deletions test-e2e/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
MEMBER_ROLE_ID,
NO_ROLE,
} from '../src/roles.js'
import { connectPeers, createManagers, invite, waitForSync } from './utils.js'
import {
connectPeers,
createManagers,
invite,
removeUndefinedFields,
waitForSync,
} from './utils.js'
import { kDataTypes } from '../src/mapeo-project.js'

test('getting yourself after creating project', async (t) => {
Expand All @@ -30,7 +36,7 @@ test('getting yourself after creating project', async (t) => {
'time of joined project is close to now'
)
assert.deepEqual(
me,
removeUndefinedFields(me),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand All @@ -45,7 +51,7 @@ test('getting yourself after creating project', async (t) => {

assert.equal(members.length, 1)
assert.deepEqual(
member,
removeUndefinedFields(member),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand Down Expand Up @@ -81,7 +87,7 @@ test('getting yourself after adding project (but not yet synced)', async (t) =>
)

assert.deepEqual(
me,
removeUndefinedFields(me),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand All @@ -96,7 +102,7 @@ test('getting yourself after adding project (but not yet synced)', async (t) =>

assert.equal(members.length, 1)
assert.deepEqual(
member,
removeUndefinedFields(member),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand Down Expand Up @@ -170,7 +176,7 @@ test('getting invited member after invite accepted', async (t) => {
)

assert.deepEqual(
invitedMemberWithoutJoinedAt,
removeUndefinedFields(invitedMemberWithoutJoinedAt),
{
deviceId: invitee.deviceId,
deviceType: 'device_type_unspecified',
Expand Down
Loading