Skip to content
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
44 changes: 44 additions & 0 deletions apps/docs/examples/attachments-browser.ts
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 };
}
43 changes: 43 additions & 0 deletions apps/docs/examples/attachments-node.ts
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 };
}
29 changes: 29 additions & 0 deletions apps/docs/examples/metadata-fields-browser.ts
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;
}
29 changes: 29 additions & 0 deletions apps/docs/examples/metadata-fields-node.ts
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;
}
2 changes: 1 addition & 1 deletion apps/docs/scripts/search-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const searchRanking = {
termSaturation: 2,
termSimilarity: 9,
// Keep guide title matches above repeated terms in longer guide bodies.
metaWeights: { title: 0, guideTitle: 100 },
metaWeights: { title: 0, guideTitle: 1000 },

Copy link
Copy Markdown
Contributor

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 chat case is fixed without regressing the other expected results, then rerun the browser search tests?

Posted via Macroscope — Code Quality

};
119 changes: 0 additions & 119 deletions apps/docs/src/content/docs/content-types/attachments.md

This file was deleted.

Loading
Loading