mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
fix(cloud): Follow and the Following section use the workspace's current owner, so after a hand-off the new owner gets no Follow (FOLLOW-OWN-AFTER-TRANSFER) (#725)
This commit is contained in:
@@ -16,10 +16,11 @@ import { useCloudWorkspacesAvailable } from './use-cloud-workspaces'
|
||||
|
||||
/**
|
||||
* Follow is offered on a teammate's team workspace; never on your own (it is yours already), and not
|
||||
* by a control plane that predates follows (`following` absent).
|
||||
* by a control plane that predates follows (`following` absent). "Your own" is the CURRENT owner:
|
||||
* after a hand-off the new owner gets no Follow and the creator does (FOLLOW-OWN-AFTER-TRANSFER).
|
||||
*/
|
||||
export function followOffer(workspace: CloudWorkspace, selfId: string | null): boolean | null {
|
||||
if (workspace.following === undefined || workspace.createdBy === selfId) {
|
||||
if (workspace.following === undefined || workspace.ownerUserId === selfId) {
|
||||
return null
|
||||
}
|
||||
return workspace.following
|
||||
|
||||
@@ -63,15 +63,18 @@ export function followedWorkspaces(
|
||||
workspaces: readonly CloudWorkspace[] | null,
|
||||
selfId: string | null
|
||||
): SidebarFollowedWorkspace[] {
|
||||
return (workspaces ?? [])
|
||||
.filter((w) => w.following === true && w.createdBy !== selfId)
|
||||
.sort((a, b) => b.lastActivityAt - a.lastActivityAt)
|
||||
.map((w) => ({
|
||||
sandboxId: w.id,
|
||||
title: workspaceDisplayLabel(w),
|
||||
numberLabel: w.number ? formatWorkspaceNumber(w.number) : null,
|
||||
creatorId: w.createdBy,
|
||||
status: followedStatus(w),
|
||||
hereNow: new Set(w.presence.map((p) => p.userId).filter((id) => id !== selfId)).size
|
||||
}))
|
||||
return (
|
||||
(workspaces ?? [])
|
||||
// Your own is the current owner's: a workspace handed to you leaves Following (FOLLOW-OWN-AFTER-TRANSFER).
|
||||
.filter((w) => w.following === true && w.ownerUserId !== selfId)
|
||||
.sort((a, b) => b.lastActivityAt - a.lastActivityAt)
|
||||
.map((w) => ({
|
||||
sandboxId: w.id,
|
||||
title: workspaceDisplayLabel(w),
|
||||
numberLabel: w.number ? formatWorkspaceNumber(w.number) : null,
|
||||
creatorId: w.createdBy,
|
||||
status: followedStatus(w),
|
||||
hereNow: new Set(w.presence.map((p) => p.userId).filter((id) => id !== selfId)).size
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,20 +7,41 @@ describe('followedWorkspaces (PARITY-FOLLOW)', () => {
|
||||
it("lists teammates' workspaces you follow, most recently active first, with who's here", () => {
|
||||
const rows = followedWorkspaces(
|
||||
[
|
||||
workspace({ title: 'Old', createdBy: 'user_grace', following: true, lastActivityAt: 1 }),
|
||||
workspace({
|
||||
title: 'Old',
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: 'user_grace',
|
||||
following: true,
|
||||
lastActivityAt: 1
|
||||
}),
|
||||
workspace({
|
||||
title: 'Checkout',
|
||||
number: 582,
|
||||
createdBy: 'user_linus',
|
||||
ownerUserId: 'user_linus',
|
||||
following: true,
|
||||
lastActivityAt: 9,
|
||||
presence: [presence('user_mae'), presence(SELF_ID), presence('user_mae', 'typing')]
|
||||
}),
|
||||
workspace({ title: 'Not followed', createdBy: 'user_grace', following: false }),
|
||||
workspace({
|
||||
title: 'Not followed',
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: 'user_grace',
|
||||
following: false
|
||||
}),
|
||||
workspace({ title: 'Mine', createdBy: SELF_ID, following: true }),
|
||||
// Handed to you by its creator: yours now, so it leaves Following.
|
||||
workspace({
|
||||
title: 'Handed to me',
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: SELF_ID,
|
||||
following: true,
|
||||
ownershipTransferredAt: 5
|
||||
}),
|
||||
workspace({
|
||||
title: 'Asleep',
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: 'user_grace',
|
||||
following: true,
|
||||
status: 'suspended',
|
||||
lastActivityAt: 0
|
||||
@@ -38,11 +59,42 @@ describe('followedWorkspaces (PARITY-FOLLOW)', () => {
|
||||
|
||||
describe('followOffer (PARITY-FOLLOW)', () => {
|
||||
it("offers Follow on a teammate's workspace, never on your own or from an older control plane", () => {
|
||||
expect(followOffer(workspace({ createdBy: 'user_grace', following: false }), SELF_ID)).toBe(
|
||||
false
|
||||
)
|
||||
expect(followOffer(workspace({ createdBy: 'user_grace', following: true }), SELF_ID)).toBe(true)
|
||||
const grace = { createdBy: 'user_grace', ownerUserId: 'user_grace' }
|
||||
expect(followOffer(workspace({ ...grace, following: false }), SELF_ID)).toBe(false)
|
||||
expect(followOffer(workspace({ ...grace, following: true }), SELF_ID)).toBe(true)
|
||||
expect(followOffer(workspace({ createdBy: SELF_ID, following: false }), SELF_ID)).toBeNull()
|
||||
expect(followOffer(workspace({ createdBy: 'user_grace' }), SELF_ID)).toBeNull()
|
||||
expect(followOffer(workspace(grace), SELF_ID)).toBeNull()
|
||||
})
|
||||
|
||||
it('follows the current owner after a hand-off, not the creator (FOLLOW-OWN-AFTER-TRANSFER)', () => {
|
||||
// Created by Grace, handed to me: mine now, so no Follow.
|
||||
const handedToMe = workspace({
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: SELF_ID,
|
||||
following: false,
|
||||
ownershipTransferredAt: 5
|
||||
})
|
||||
expect(followOffer(handedToMe, SELF_ID)).toBeNull()
|
||||
// Created by me, handed to Grace: hers now, so I may follow it.
|
||||
const handedAway = workspace({
|
||||
createdBy: SELF_ID,
|
||||
ownerUserId: 'user_grace',
|
||||
following: false,
|
||||
ownershipTransferredAt: 5
|
||||
})
|
||||
expect(followOffer(handedAway, SELF_ID)).toBe(false)
|
||||
})
|
||||
|
||||
it('a hand-off arriving in a live refresh changes the offer with no reload', () => {
|
||||
const before = workspace({
|
||||
createdBy: 'user_grace',
|
||||
ownerUserId: 'user_grace',
|
||||
following: true
|
||||
})
|
||||
expect(followOffer(before, SELF_ID)).toBe(true)
|
||||
const after = { ...before, ownerUserId: SELF_ID, ownershipTransferredAt: 9 }
|
||||
expect(followOffer(after, SELF_ID)).toBeNull()
|
||||
expect(followedWorkspaces([before], SELF_ID)).toHaveLength(1)
|
||||
expect(followedWorkspaces([after], SELF_ID)).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user