@indexnetwork/protocol 66.0.0-rc.635.1 → 66.0.0-rc.637.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -60,9 +60,11 @@ export declare function presentOpportunityCard(deps: OpportunityCardsDeps, oppor
|
|
|
60
60
|
}): Promise<OpportunityCard | null>;
|
|
61
61
|
/**
|
|
62
62
|
* List the viewer's opportunities in the given statuses as presented cards,
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* one card per counterpart. An accepted row keeps that person's slot over a
|
|
64
|
+
* newer pending or negotiating one, and a pending row this viewer already
|
|
65
|
+
* committed to keeps it over a newer unanswered one. Among the same rank,
|
|
66
|
+
* newest wins. A rejected or expired row never takes the slot from a live
|
|
67
|
+
* one. Cards whose presentation fails are dropped.
|
|
66
68
|
*
|
|
67
69
|
* @param deps - Database, cache, and presenter.
|
|
68
70
|
* @param input - Viewer, statuses, optional network/intent scope, limit, cache bypass, skeleton mode.
|
|
@@ -33,6 +33,20 @@ function counterpartUserIds(opportunity, viewerId) {
|
|
|
33
33
|
function viewerHasCommitted(opportunity, viewerId) {
|
|
34
34
|
return (opportunity.committedActorIds ?? []).includes(viewerId);
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Which row keeps a person's single radar slot.
|
|
38
|
+
* Accepted first, then a pending row this viewer already committed to,
|
|
39
|
+
* then other live rows. Rejected and expired never take the slot from those.
|
|
40
|
+
*/
|
|
41
|
+
function counterpartSlotRank(opportunity, viewerId) {
|
|
42
|
+
if (opportunity.status === 'rejected' || opportunity.status === 'expired')
|
|
43
|
+
return 3;
|
|
44
|
+
if (opportunity.status === 'accepted')
|
|
45
|
+
return 0;
|
|
46
|
+
if (opportunity.status === 'pending' && viewerHasCommitted(opportunity, viewerId))
|
|
47
|
+
return 1;
|
|
48
|
+
return 2;
|
|
49
|
+
}
|
|
36
50
|
function stampViewerCommitted(card, viewerCommitted) {
|
|
37
51
|
return { ...card, viewerCommitted };
|
|
38
52
|
}
|
|
@@ -113,9 +127,11 @@ export async function presentOpportunityCard(deps, opportunity, viewerId, option
|
|
|
113
127
|
}
|
|
114
128
|
/**
|
|
115
129
|
* List the viewer's opportunities in the given statuses as presented cards,
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
130
|
+
* one card per counterpart. An accepted row keeps that person's slot over a
|
|
131
|
+
* newer pending or negotiating one, and a pending row this viewer already
|
|
132
|
+
* committed to keeps it over a newer unanswered one. Among the same rank,
|
|
133
|
+
* newest wins. A rejected or expired row never takes the slot from a live
|
|
134
|
+
* one. Cards whose presentation fails are dropped.
|
|
119
135
|
*
|
|
120
136
|
* @param deps - Database, cache, and presenter.
|
|
121
137
|
* @param input - Viewer, statuses, optional network/intent scope, limit, cache bypass, skeleton mode.
|
|
@@ -133,9 +149,9 @@ export async function listOpportunityCards(deps, input) {
|
|
|
133
149
|
const visible = raw
|
|
134
150
|
.filter((opp) => requested.has(opp.status) && canUserSeeOpportunity(opp.actors, opp.status, viewerId))
|
|
135
151
|
.sort((a, b) => {
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
return
|
|
152
|
+
const rank = counterpartSlotRank(a, viewerId) - counterpartSlotRank(b, viewerId);
|
|
153
|
+
if (rank !== 0)
|
|
154
|
+
return rank;
|
|
139
155
|
return b.createdAt.getTime() - a.createdAt.getTime();
|
|
140
156
|
});
|
|
141
157
|
const seen = new Set();
|