social bookmarking for atproto

[backend] support updates for profiles

hexmani.ac f7aace82 08c2fef2

verified
+23 -2
+23 -2
backend/src/network/commit.ts
··· 18 18 import { validateClip, validateProfile, validateTag } from "./validator.js"; 19 19 import { convertDidToString } from "./converters.js"; 20 20 import { hashString } from "../hasher.js"; 21 + import { eq } from "drizzle-orm"; 21 22 22 23 const db = Database.getInstance().getDb(); 23 24 ··· 165 166 export async function handleProfile( 166 167 event: CommitEvent<`social.clippr.${string}`>, 167 168 ): Promise<void> { 168 - if (event.commit.operation !== "create") { 169 + if (event.commit.operation === "delete") { 169 170 Logger.warn( 170 171 `Operation '${event.commit.operation}' for ${event.commit.collection} not supported. Ignoring.`, 171 172 ); 172 173 return; 173 - } // We currently do not handle these. 174 + } // We currently do not handle deletes. 174 175 175 176 if (event.commit.record.$type !== "social.clippr.actor.profile") { 176 177 Logger.verbose( ··· 241 242 242 243 // Independent validations 243 244 if (!(await validateProfile(record))) { 245 + return; 246 + } 247 + 248 + if (event.commit.operation === "update") { 249 + await db 250 + .update(usersTable) 251 + .set({ 252 + did: convertDidToString(event.did), 253 + cid: event.commit.cid, 254 + timestamp: convertMicroToDate(event.time_us), 255 + createdAt: new Date(record.createdAt), 256 + displayName: record.displayName, 257 + avatar: record.avatar?.ref.$link, 258 + description: record.description, 259 + }) 260 + .where(eq(usersTable.did, convertDidToString(event.did))) 261 + .execute(); 262 + 263 + Logger.verbose(`Updated profile: ${convertDidToString(event.did)}`, event); 264 + 244 265 return; 245 266 } 246 267