Skip to content

Commit

Permalink
Merge pull request #4 from polyvariant/track-scala-accounts
Browse files Browse the repository at this point in the history
Always include posts by Scala related organization accounts
  • Loading branch information
majk-p authored Dec 17, 2024
2 parents f54d3ab + b4ab9e2 commit c898a34
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app

COPY . .

RUN yarn install && yarn build
RUN yarn install && yarn test && yarn build

RUN rm -rf /build

Expand Down
3 changes: 2 additions & 1 deletion src/FirehoseSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
// use only for debug purposes
for (const post of ops.posts.creates) {
console.log("================== [NEW POST] ==================")
console.log(post.author)
console.log(post.record.text)
console.log("================== [END POST] ==================")
}
Expand All @@ -26,7 +27,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
const postsToCreate = ops.posts.creates
.filter((create) => {
// only scala related posts
return isAboutScala(create.record.text);
return isAboutScala(create.author, create.record.text);
})
.map((create) => {
// map scala related posts to a db row
Expand Down
5 changes: 5 additions & 0 deletions src/scala/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const scalaRelatedOrganizationProfiles = [
"did:plc:mb6e2ashxeswusv7f7hwusp5", // scala-lang.org https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scala-lang.org
"did:plc:5nlshbn5adh3fjwzyz7xjpwl", // Scala Space https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalaspace.bsky.social
"did:plc:xs35x5l4ogj3g4eymh6ngcsr", // Scala Times https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalatimes.com
]
46 changes: 46 additions & 0 deletions src/scala/hashtags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const scalalang = [
"scala", "scala3", "dotty"
]

const typelevel = [
"cats-effect"
]

const scalameta = [
"munit", "scalameta", "scalafmt",
// "mdoc"
]

const softwaremill = [
"scalar", "scalarconf"
]

const sbt = [
"sbt"
]

const lihaoi = [
"os-lib", "requests-scala"
]

const lightbend = [
"akka", "playframework"
]

const others = [
"pekko"
]

function hashTag(word: String) {
return `#${word}`
}

export const allHashTags =
scalalang.concat(typelevel,
scalameta,
softwaremill,
// sbt, // sbt seems to be a thing in TV in Brasil
// lihaoi, // apparently people like to discuss hardware mills a lot
lightbend,
others
).map(w => hashTag(w))
58 changes: 11 additions & 47 deletions src/scala/index.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,17 @@
const scalalang = [
"scala", "scala3", "dotty"
]
import { allHashTags } from "./hashtags";
import { scalaRelatedOrganizationProfiles } from "./accounts";

const typelevel = [
"cats-effect"
]

const scalameta = [
"munit", "scalameta", "scalafmt",
// "mdoc"
]

const softwaremill = [
"scalar", "scalarconf"
]

const sbt = [
"sbt"
]

const lihaoi = [
"os-lib", "requests-scala"
]

const lightbend = [
"akka", "playframework"
]

const others = [
"pekko"
]

const allHashTags =
scalalang.concat(typelevel,
scalameta,
softwaremill,
// sbt, // sbt seems to be a thing in TV in Brasil
// lihaoi, // apparently people like to discuss hardware mills a lot
lightbend,
others
).map(w => hashTag(w))

function hashTag(word: String) {
return `#${word}`
}

export function isAboutScala(text: string): boolean {
function containsRelevantHashtag(text: string): boolean {
const input = text.toLowerCase();
const textWords = input.split(/\s+/);
return allHashTags.map(v => v.toLowerCase()).some(tag => textWords.includes(tag));
}

function postedByScalaOrgAccount(author: string): boolean {
return scalaRelatedOrganizationProfiles.includes(author);
}

export function isAboutScala(author: string, text: string): boolean {
return postedByScalaOrgAccount(author) || containsRelevantHashtag(text);
}

14 changes: 11 additions & 3 deletions tests/algos/scala-feed.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { scalaRelatedOrganizationProfiles } from '../../src/scala/accounts';
import { isAboutScala } from '../../src/scala/index';

const randomAuthorDid = "did:plc:abcde12345"

describe('testing isAboutScala', () => {
test('the #Scala hashtag should be picked up', () => {
expect(
isAboutScala("#Scala")
isAboutScala(randomAuthorDid, "#Scala")
).toBe(true);
});
test('proper message should be qualified as Scala related', () => {
expect(
isAboutScala("We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala...")
isAboutScala(randomAuthorDid, "We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala...")
).toBe(true);
});
test('post by scala related org account should be qualified as Scala related', () => {
expect(
isAboutScala(scalaRelatedOrganizationProfiles[0], "This one doesn't have a hashtag")
).toBe(true);
});
test('empty message should not be qualified as Scala', () => {
expect(
isAboutScala("")
isAboutScala(randomAuthorDid, "")
).toBe(false);
});
});

0 comments on commit c898a34

Please sign in to comment.