-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: shift some text messages to work on blabsy #199
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
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
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 |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { functions, firestore, regionalFunctions } from './lib/utils'; | ||
import { tweetConverter, bookmarkConverter } from './types'; | ||
import type { Tweet } from './types'; | ||
import { firestore, functions, regionalFunctions } from "./lib/utils"; | ||
import { bookmarkConverter, tweetConverter } from "./types"; | ||
import type { Tweet } from "./types"; | ||
|
||
export const normalizeStats = regionalFunctions.firestore | ||
.document('tweets/{tweetId}') | ||
.onDelete(async (snapshot): Promise<void> => { | ||
const tweetId = snapshot.id; | ||
const tweetData = snapshot.data() as Tweet; | ||
.document("tweets/{tweetId}") | ||
.onDelete(async (snapshot): Promise<void> => { | ||
const tweetId = snapshot.id; | ||
const tweetData = snapshot.data() as Tweet; | ||
|
||
functions.logger.info(`Normalizing stats from tweet ${tweetId}`); | ||
functions.logger.info(`Normalizing stats from tweet ${tweetId}`); | ||
|
||
const { userRetweets, userLikes } = tweetData; | ||
const { userRetweets, userLikes } = tweetData; | ||
|
||
const usersStatsToDelete = new Set([...userRetweets, ...userLikes]); | ||
const usersStatsToDelete = new Set([...userRetweets, ...userLikes]); | ||
|
||
const batch = firestore().batch(); | ||
const batch = firestore().batch(); | ||
|
||
usersStatsToDelete.forEach((userId) => { | ||
functions.logger.info(`Deleting stats from ${userId}`); | ||
usersStatsToDelete.forEach((userId) => { | ||
functions.logger.info(`Deleting stats from ${userId}`); | ||
|
||
const userStatsRef = firestore() | ||
.doc(`users/${userId}/stats/stats`) | ||
.withConverter(tweetConverter); | ||
const userStatsRef = firestore() | ||
.doc(`users/${userId}/stats/stats`) | ||
.withConverter(tweetConverter); | ||
|
||
batch.update(userStatsRef, { | ||
tweets: firestore.FieldValue.arrayRemove(tweetId), | ||
likes: firestore.FieldValue.arrayRemove(tweetId) | ||
}); | ||
}); | ||
batch.update(userStatsRef, { | ||
tweets: firestore.FieldValue.arrayRemove(tweetId), | ||
likes: firestore.FieldValue.arrayRemove(tweetId), | ||
}); | ||
}); | ||
|
||
const bookmarksQuery = firestore() | ||
.collectionGroup('bookmarks') | ||
.where('id', '==', tweetId) | ||
.withConverter(bookmarkConverter); | ||
const bookmarksQuery = firestore() | ||
.collectionGroup("bookmarks") | ||
.where("id", "==", tweetId) | ||
.withConverter(bookmarkConverter); | ||
|
||
const docsSnap = await bookmarksQuery.get(); | ||
const docsSnap = await bookmarksQuery.get(); | ||
|
||
functions.logger.info(`Deleting ${docsSnap.size} bookmarks`); | ||
functions.logger.info(`Deleting ${docsSnap.size} bookmarks`); | ||
|
||
docsSnap.docs.forEach(({ id, ref }) => { | ||
functions.logger.info(`Deleting bookmark ${id}`); | ||
batch.delete(ref); | ||
}); | ||
docsSnap.docs.forEach(({ id, ref }) => { | ||
functions.logger.info(`Deleting bookmark ${id}`); | ||
batch.delete(ref); | ||
}); | ||
|
||
await batch.commit(); | ||
await batch.commit(); | ||
|
||
functions.logger.info(`Normalizing stats for tweet ${tweetId} is done`); | ||
}); | ||
functions.logger.info(`Normalizing stats for blab ${tweetId} is done`); | ||
}); |
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 |
---|---|---|
@@ -1,45 +1,47 @@ | ||
import { createTransport } from 'nodemailer'; | ||
import { firestore, functions, regionalFunctions } from './lib/utils'; | ||
import { EMAIL_API, EMAIL_API_PASSWORD, TARGET_EMAIL } from './lib/env'; | ||
import type { Tweet, User } from './types'; | ||
import { createTransport } from "nodemailer"; | ||
import { EMAIL_API, EMAIL_API_PASSWORD, TARGET_EMAIL } from "./lib/env"; | ||
import { firestore, functions, regionalFunctions } from "./lib/utils"; | ||
import type { Tweet, User } from "./types"; | ||
|
||
export const notifyEmail = regionalFunctions.firestore | ||
.document('tweets/{tweetId}') | ||
.onCreate(async (snapshot): Promise<void> => { | ||
functions.logger.info('Sending notification email.'); | ||
|
||
const { text, createdBy, images, parent } = snapshot.data() as Tweet; | ||
|
||
const imagesLength = images?.length ?? 0; | ||
|
||
const { name, username } = ( | ||
await firestore().doc(`users/${createdBy}`).get() | ||
).data() as User; | ||
|
||
const client = createTransport({ | ||
service: 'Gmail', | ||
auth: { | ||
user: EMAIL_API.value(), | ||
pass: EMAIL_API_PASSWORD.value() | ||
} | ||
}); | ||
|
||
const tweetLink = `https://twitter-clone-ccrsxx.vercel.app/tweet/${snapshot.id}`; | ||
|
||
const emailHeader = `New Tweet${ | ||
parent ? ' reply' : '' | ||
} from ${name} (@${username})`; | ||
|
||
const emailText = `${text ?? 'No text provided'}${ | ||
images ? ` (${imagesLength} image${imagesLength > 1 ? 's' : ''})` : '' | ||
}\n\nLink to Tweet: ${tweetLink}\n\n- Firebase Function.`; | ||
|
||
await client.sendMail({ | ||
from: EMAIL_API.value(), | ||
to: TARGET_EMAIL.value(), | ||
subject: emailHeader, | ||
text: emailText | ||
.document("tweets/{tweetId}") | ||
.onCreate(async (snapshot): Promise<void> => { | ||
functions.logger.info("Sending notification email."); | ||
|
||
const { text, createdBy, images, parent } = snapshot.data() as Tweet; | ||
|
||
const imagesLength = images?.length ?? 0; | ||
|
||
const { name, username } = ( | ||
await firestore().doc(`users/${createdBy}`).get() | ||
).data() as User; | ||
|
||
const client = createTransport({ | ||
service: "Gmail", | ||
auth: { | ||
user: EMAIL_API.value(), | ||
pass: EMAIL_API_PASSWORD.value(), | ||
}, | ||
}); | ||
|
||
const tweetLink = `https://twitter-clone-ccrsxx.vercel.app/tweet/${snapshot.id}`; | ||
|
||
const emailHeader = `New Blab${ | ||
parent ? " reply" : "" | ||
} from ${name} (@${username})`; | ||
|
||
const emailText = `${text ?? "No text provided"}${ | ||
images | ||
? ` (${imagesLength} image${imagesLength > 1 ? "s" : ""})` | ||
: "" | ||
}\n\nLink to Blab: ${tweetLink}\n\n- Firebase Function.`; | ||
|
||
await client.sendMail({ | ||
from: EMAIL_API.value(), | ||
to: TARGET_EMAIL.value(), | ||
subject: emailHeader, | ||
text: emailText, | ||
}); | ||
|
||
functions.logger.info("Notification email sent."); | ||
}); | ||
|
||
functions.logger.info('Notification email sent.'); | ||
}); |
Large diffs are not rendered by default.
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.
💡 Verification agent
🧩 Analysis chain
Verify URL domain consistency with Blabsy rebranding.
The email contains a link to
twitter-clone-ccrsxx.vercel.app
which may be inconsistent with the Blabsy rebranding effort. Consider updating the domain to reflect the new branding if applicable.🏁 Script executed:
Length of output: 209
I’ll broaden the search to catch all occurrences and any config references:
🏁 Script executed:
Length of output: 1682
Use a configurable Blabsy base URL instead of hard-coding the old domain
It looks like
notify-email.ts
is still generating links withtwitter-clone-ccrsxx.vercel.app
, and there isn’t a matching environment variable in this function. To keep branding consistent and make future updates painless:Define (or reuse) an env var, e.g.
PUBLIC_BLABSY_BASE_URL
, for the Blabsy site URL.Update
platforms/blabsy/functions/src/notify-email.ts
to use that var with a sensible default:This ensures all outbound links adopt the correct Blabsy domain and can be updated centrally.
📝 Committable suggestion
🤖 Prompt for AI Agents