Repository navigation
docs: explain configurable metadata and native attachments #4459
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1329f0
docs: explain configurable metadata and native attachments
neekolas 24bda51
docs: use synced SDK tabs for native examples
neekolas 83c6e6c
docs: add Browser and Node variants to SDK tabs
neekolas c65669d
docs: weight repeated SDK examples below guide text
neekolas 631bf8f
docs: keep guide title ranking stable with SDK tabs
neekolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { | ||
| type Client, | ||
| type Group, | ||
| type RemoteAttachment, | ||
| } from "@xmtp/browser-sdk"; | ||
| import { initPureWasm, RemoteAttachmentCodec } from "@xmtp/browser-sdk/pure"; | ||
|
|
||
| export async function sendAttachment( | ||
| client: Client, | ||
| group: Group, | ||
| path: string, | ||
| ) { | ||
| // #region upload | ||
| await initPureWasm(); | ||
| const attachments = client.attachments; | ||
| if (!attachments.offered) { | ||
| throw new Error("The backend does not offer attachments"); | ||
| } | ||
|
|
||
| const pending = await attachments.create({ | ||
| kind: "path", | ||
| path, | ||
| filename: "photo.jpg", | ||
| mimeType: "image/jpeg", | ||
| }); | ||
| const remote = pending.remoteAttachment; | ||
| await group.send(new RemoteAttachmentCodec(), remote); | ||
| await pending.upload(); | ||
| // #endregion upload | ||
| return remote; | ||
| } | ||
|
|
||
| export async function downloadAttachment( | ||
| client: Client, | ||
| remote: RemoteAttachment, | ||
| ) { | ||
| // #region download | ||
| const downloaded = await client.attachments.download(remote); | ||
| const path = downloaded.path; | ||
| const mimeType = downloaded.mimeType; | ||
| const filename = downloaded.filename; | ||
| // #endregion download | ||
| return { path, mimeType, filename }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { | ||
| type Client, | ||
| type Group, | ||
| type RemoteAttachment, | ||
| RemoteAttachmentCodec, | ||
| } from "@xmtp/node-sdk"; | ||
|
|
||
| export async function sendAttachment( | ||
| client: Client, | ||
| group: Group, | ||
| path: string, | ||
| ) { | ||
| // #region upload | ||
| const attachments = client.attachments; | ||
| if (!attachments.offered) { | ||
| throw new Error("The backend does not offer attachments"); | ||
| } | ||
|
|
||
| const pending = await attachments.create({ | ||
| kind: "path", | ||
| path, | ||
| filename: "photo.jpg", | ||
| mimeType: "image/jpeg", | ||
| }); | ||
| const remote = pending.remoteAttachment; | ||
| await group.send(new RemoteAttachmentCodec(), remote); | ||
| await pending.upload(); | ||
| // #endregion upload | ||
| return remote; | ||
| } | ||
|
|
||
| export async function downloadAttachment( | ||
| client: Client, | ||
| remote: RemoteAttachment, | ||
| ) { | ||
| // #region download | ||
| const downloaded = await client.attachments.download(remote); | ||
| const path = downloaded.path; | ||
| const mimeType = downloaded.mimeType; | ||
| const filename = downloaded.filename; | ||
| // #endregion download | ||
| return { path, mimeType, filename }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { Group } from "@xmtp/browser-sdk"; | ||
|
|
||
| export async function updateFields(group: Group) { | ||
| // #region update | ||
| const category = await group.metadataField("GROUP_CATEGORY"); | ||
| const displayName = await group.metadataField("USER_DISPLAY_NAME"); | ||
| const pronouns = await group.metadataField("USER_PRONOUNS"); | ||
| if (!category || !displayName || !pronouns) { | ||
| throw new Error("The group has not registered the required fields"); | ||
| } | ||
|
|
||
| await group.updateMetadataField(category.field, { | ||
| kind: "replace", | ||
| value: { kind: "string", value: "engineering" }, | ||
| }); | ||
| await group.updateUserData([ | ||
| { field: displayName.field, value: { kind: "string", value: "Alix" } }, | ||
| { field: pronouns.field, value: { kind: "string", value: "they/them" } }, | ||
| ]); | ||
|
|
||
| await group.sync(); | ||
| const profiles = await group.userData( | ||
| [displayName.field, pronouns.field], | ||
| undefined, | ||
| ); | ||
| await group.updateUserData([{ field: pronouns.field, value: undefined }]); | ||
| // #endregion update | ||
| return profiles; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { Group } from "@xmtp/node-sdk"; | ||
|
|
||
| export async function updateFields(group: Group) { | ||
| // #region update | ||
| const category = await group.metadataField("GROUP_CATEGORY"); | ||
| const displayName = await group.metadataField("USER_DISPLAY_NAME"); | ||
| const pronouns = await group.metadataField("USER_PRONOUNS"); | ||
| if (!category || !displayName || !pronouns) { | ||
| throw new Error("The group has not registered the required fields"); | ||
| } | ||
|
|
||
| await group.updateMetadataField(category.field, { | ||
| kind: "replace", | ||
| value: { kind: "string", value: "engineering" }, | ||
| }); | ||
| await group.updateUserData([ | ||
| { field: displayName.field, value: { kind: "string", value: "Alix" } }, | ||
| { field: pronouns.field, value: { kind: "string", value: "they/them" } }, | ||
| ]); | ||
|
|
||
| await group.sync(); | ||
| const profiles = await group.userData( | ||
| [displayName.field, pronouns.field], | ||
| undefined, | ||
| ); | ||
| await group.updateUserData([{ field: pronouns.field, value: undefined }]); | ||
| // #endregion update | ||
| return profiles; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 0 additions & 119 deletions
119
apps/docs/src/content/docs/content-types/attachments.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This global 10× guide-title boost is causing the search-ranking checks to return the wrong first page for multiple queries. Could you tune the ranking more narrowly so the
group chatcase is fixed without regressing the other expected results, then rerun the browser search tests?Posted via Macroscope — Code Quality