Skip to content

Commit

Permalink
enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jan 3, 2024
1 parent a646a0b commit 8b40cbe
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 53 deletions.
151 changes: 106 additions & 45 deletions apps/builddao/widget/Compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,50 @@ function tagsFromLabels(labels) {
);
}

const extractMentions = (text) => {
const mentionRegex =
/@((?:(?:[a-z\d]+[-_])*[a-z\d]+\.)*(?:[a-z\d]+[-_])*[a-z\d]+)/gi;
mentionRegex.lastIndex = 0;
const accountIds = new Set();
for (const match of text.matchAll(mentionRegex)) {
if (
!/[\w`]/.test(match.input.charAt(match.index - 1)) &&
!/[/\w`]/.test(match.input.charAt(match.index + match[0].length)) &&
match[1].length >= 2 &&
match[1].length <= 64
) {
accountIds.add(match[1].toLowerCase());
}
}
return [...accountIds];
};

const extractHashtags = (text) => {
const hashtagRegex = /#(\w+)/gi;
hashtagRegex.lastIndex = 0;
const hashtags = new Set();
for (const match of text.matchAll(hashtagRegex)) {
if (
!/[\w`]/.test(match.input.charAt(match.index - 1)) &&
!/[/\w`]/.test(match.input.charAt(match.index + match[0].length))
) {
hashtags.add(match[1].toLowerCase());
}
}
return [...hashtags];
};

const extractMentionNotifications = (text, item) =>
extractMentions(text || "")
.filter((accountId) => accountId !== context.accountId)
.map((accountId) => ({
key: accountId,
value: {
type: "mention",
item,
},
}));

function checkAndAppendHashtag(input, target) {
if (input.toLowerCase().includes(`#${target.toLowerCase()}`)) {
return input;
Expand All @@ -44,59 +88,76 @@ const postToCustomFeed = ({ feed, text, labels }) => {
labels.push(feed.name.toLowerCase());

const requiredHashtags = ["build"];
requiredHashtags.push((feed.hashtag).toLowerCase());
requiredHashtags.push((feed.name).toLowerCase());
requiredHashtags.push(feed.hashtag.toLowerCase());
requiredHashtags.push(feed.name.toLowerCase());

text = text + `\n\n`;

requiredHashtags.forEach((hashtag) => {
text = checkAndAppendHashtag(text, hashtag);
});

return Social.set(
{
// [feed.name]: {
// [postId]: {
// "": JSON.stringify({
// type: "md",
// text,
// labels,
// }),
// metadata: {
// type: feed.name,
// tags: tagsFromLabels(labels),
// },
// },
// },
post: {
main: JSON.stringify({
type: "md",
text,
// tags: tagsFromLabels(labels),
// postType: feed.name,
}),
},
index: {
post: JSON.stringify({ key: "main", value: { type: "md" } }),
// every: JSON.stringify({ key: feed.name, value: { type: "md" } }),
hashtag: JSON.stringify(
requiredHashtags.map((hashtag) => ({
key: hashtag,
value: { type: "social", path: `${context.accountId}/post/main` },
}))
),
},
const data = {
// [feed.name]: {
// [postId]: {
// "": JSON.stringify({
// type: "md",
// text,
// labels,
// }),
// metadata: {
// type: feed.name,
// tags: tagsFromLabels(labels),
// },
// },
// },
post: {
main: JSON.stringify({
type: "md",
text,
// tags: tagsFromLabels(labels),
// postType: feed.name,
}),
},
{
force: true,
onCommit: () => {
console.log(`Commited ${feed}: #${postId}`);
},
onCancel: () => {
console.log(`Cancelled ${feed}: #${postId}`);
},
}
);
index: {
post: JSON.stringify({ key: "main", value: { type: "md" } }),
// every: JSON.stringify({ key: feed.name, value: { type: "md" } }),
},
};

const item = {
type: "social",
path: `${context.accountId}/post/main`,
};

const notifications = extractMentionNotifications(text, item);

if (notifications.length) {
data.index.notify = JSON.stringify(
notifications.length > 1 ? notifications : notifications[0]
);
}

const hashtags = extractHashtags(text);

if (hashtags.length) {
data.index.hashtag = JSON.stringify(
hashtags.map((hashtag) => ({
key: hashtag,
value: item,
}))
);
}

return Social.set(data, {
force: true,
onCommit: () => {
// console.log(`Commited ${feed}: #${postId}`);
},
onCancel: () => {
// console.log(`Cancelled ${feed}: #${postId}`);
},
});
};

const PostCreator = styled.div`
Expand Down
16 changes: 8 additions & 8 deletions apps/builddao/widget/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ const feedsDict = {
icon: "bi-calendar3",
name: "resolution",
hashtag: "nearyearresolutions2024",
template: `## 🎉 NEAR YEAR RESOLUTIONS: 2024
template: `### 🎉 NEAR YEAR RESOLUTIONS: 2024
### 🌟 REFLECTIONS ON THE PAST YEAR:
**🌟 REFLECTIONS ON THE PAST YEAR:**
- [Reflection 1 from the past year]
- [Reflection 2 from the past year]
### 🎯 NEW YEAR'S RESOLUTIONS:
**🎯 NEW YEAR'S RESOLUTIONS:**
- [Resolution 1]
- [Resolution 2]
### 📊 MEASURING SUCCESS:
**📊 MEASURING SUCCESS:**
- [Metric 1 for Success]
- [Metric 2 for Success]
`,
Expand All @@ -88,17 +88,17 @@ const feedsDict = {
label: "Updates",
icon: "bi-bell",
name: "update",
template: `## 🔔 DAILY UPDATE: ${formatDate(new Date())}
template: `### 🔔 DAILY UPDATE: ${formatDate(new Date())}
### 📆 YESTERDAY:
**📆 YESTERDAY:**
- [Task 1, hyperlink proof]
- [Task 2, hyperlink proof]
### 💻 WHAT I AM DOING TODAY:
**💻 WHAT I AM DOING TODAY:**
- [Task 1]
- [Task 2]
### 🛑 BLOCKERS:
**🛑 BLOCKERS: **
- @anyone that is causing a blocker or outline any blockers in general`,
},
};
Expand Down

0 comments on commit 8b40cbe

Please sign in to comment.