-
Notifications
You must be signed in to change notification settings - Fork 458
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
Pinned posts #2771
Pinned posts #2771
Changes from 10 commits
b337796
217b1c7
f6c3782
c0834e1
c7202ee
136a3bf
6eb75ea
5b7c906
456c8f9
05662f8
cf04d28
ac04532
3c03ce0
eb4dde4
69208f8
835227f
e3eda61
27ce533
e7e2a47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,8 @@ | |
"like": { "type": "string", "format": "at-uri" }, | ||
"threadMuted": { "type": "boolean" }, | ||
"replyDisabled": { "type": "boolean" }, | ||
"embeddingDisabled": { "type": "boolean" } | ||
"embeddingDisabled": { "type": "boolean" }, | ||
"pinned": { "type": "boolean" } | ||
} | ||
}, | ||
"feedViewPost": { | ||
|
@@ -53,7 +54,7 @@ | |
"properties": { | ||
"post": { "type": "ref", "ref": "#postView" }, | ||
"reply": { "type": "ref", "ref": "#replyRef" }, | ||
"reason": { "type": "union", "refs": ["#reasonRepost"] }, | ||
"reason": { "type": "union", "refs": ["#reasonRepost", "#reasonPin"] }, | ||
"feedContext": { | ||
"type": "string", | ||
"description": "Context provided by feed generator that may be passed back alongside interactions.", | ||
|
@@ -88,6 +89,10 @@ | |
"indexedAt": { "type": "string", "format": "datetime" } | ||
} | ||
}, | ||
"reasonPin": { | ||
"type": "object", | ||
"properties": {} | ||
}, | ||
"threadViewPost": { | ||
"type": "object", | ||
"required": ["post"], | ||
|
@@ -171,7 +176,10 @@ | |
"required": ["post"], | ||
"properties": { | ||
"post": { "type": "string", "format": "at-uri" }, | ||
"reason": { "type": "union", "refs": ["#skeletonReasonRepost"] }, | ||
"reason": { | ||
"type": "union", | ||
"refs": ["#skeletonReasonRepost", "#skeletonReasonPin"] | ||
}, | ||
"feedContext": { | ||
"type": "string", | ||
"description": "Context that will be passed through to client and may be passed to feed generator back alongside interactions.", | ||
|
@@ -186,6 +194,10 @@ | |
"repost": { "type": "string", "format": "at-uri" } | ||
} | ||
}, | ||
"skeletonReasonPin": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually like that this could be used in the future for a feed gen to "pin" a post to the top of a feed |
||
"type": "object", | ||
"properties": {} | ||
}, | ||
"threadgateView": { | ||
"type": "object", | ||
"properties": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,21 +79,47 @@ export const skeleton = async (inputs: { | |
if (clearlyBadCursor(params.cursor)) { | ||
return { actor, filter: params.filter, items: [] } | ||
} | ||
|
||
const isFirstPageRequest = !params.cursor | ||
const hasPinnedPost = | ||
isFirstPageRequest && params.includePins && !!actor.profile?.pinnedPost | ||
|
||
const res = await ctx.dataplane.getAuthorFeed({ | ||
actorDid: did, | ||
limit: params.limit, | ||
cursor: params.cursor, | ||
feedType: FILTER_TO_FEED_TYPE[params.filter], | ||
}) | ||
|
||
let items = res.items.map((item) => ({ | ||
post: { uri: item.uri, cid: item.cid || undefined }, | ||
repost: item.repost | ||
? { uri: item.repost, cid: item.repostCid || undefined } | ||
: undefined, | ||
})) | ||
|
||
if (hasPinnedPost && actor.profile?.pinnedPost) { | ||
mozzius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const pinnedItem = { | ||
post: { | ||
uri: actor.profile.pinnedPost.uri, | ||
cid: actor.profile.pinnedPost.cid, | ||
}, | ||
repost: undefined, | ||
mozzius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
authorPinned: true, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I set |
||
if (params.limit === 1) { | ||
items[0] = pinnedItem | ||
} else { | ||
// filter pinned post from first page only | ||
items = items.filter((item) => item.post.uri !== pinnedItem.post.uri) | ||
items.unshift(pinnedItem) | ||
} | ||
} | ||
|
||
return { | ||
actor, | ||
filter: params.filter, | ||
items: res.items.map((item) => ({ | ||
post: { uri: item.uri, cid: item.cid || undefined }, | ||
repost: item.repost | ||
? { uri: item.repost, cid: item.repostCid || undefined } | ||
: undefined, | ||
})), | ||
items, | ||
cursor: parseString(res.cursor), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Kysely } from 'kysely' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The backend isn't using Scylla? What is this kysely about? Just curious There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the Postgres-based reference implementation |
||
|
||
export async function up(db: Kysely<unknown>): Promise<void> { | ||
await db.schema | ||
.alterTable('profile') | ||
.addColumn('pinnedPost', 'boolean') | ||
mozzius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.execute() | ||
await db.schema | ||
.alterTable('profile') | ||
.addColumn('pinnedPostCid', 'boolean') | ||
.execute() | ||
} | ||
|
||
export async function down(db: Kysely<unknown>): Promise<void> { | ||
await db.schema.alterTable('profile').dropColumn('pinnedPost').execute() | ||
await db.schema.alterTable('profile').dropColumn('pinnedPostCid').execute() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, does this affect the presentation of a post elsewhere in the app (other than a user's own author feed) when viewing their own pinned post?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use it to show "Pin post" or "Unpin post" in the context menu