Skip to content

Commit c898a34

Browse files
authored
Merge pull request #4 from polyvariant/track-scala-accounts
Always include posts by Scala related organization accounts
2 parents f54d3ab + b4ab9e2 commit c898a34

File tree

6 files changed

+76
-52
lines changed

6 files changed

+76
-52
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /app
44

55
COPY . .
66

7-
RUN yarn install && yarn build
7+
RUN yarn install && yarn test && yarn build
88

99
RUN rm -rf /build
1010

src/FirehoseSubscription.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
1717
// use only for debug purposes
1818
for (const post of ops.posts.creates) {
1919
console.log("================== [NEW POST] ==================")
20+
console.log(post.author)
2021
console.log(post.record.text)
2122
console.log("================== [END POST] ==================")
2223
}
@@ -26,7 +27,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
2627
const postsToCreate = ops.posts.creates
2728
.filter((create) => {
2829
// only scala related posts
29-
return isAboutScala(create.record.text);
30+
return isAboutScala(create.author, create.record.text);
3031
})
3132
.map((create) => {
3233
// map scala related posts to a db row

src/scala/accounts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const scalaRelatedOrganizationProfiles = [
2+
"did:plc:mb6e2ashxeswusv7f7hwusp5", // scala-lang.org https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scala-lang.org
3+
"did:plc:5nlshbn5adh3fjwzyz7xjpwl", // Scala Space https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalaspace.bsky.social
4+
"did:plc:xs35x5l4ogj3g4eymh6ngcsr", // Scala Times https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=scalatimes.com
5+
]

src/scala/hashtags.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const scalalang = [
2+
"scala", "scala3", "dotty"
3+
]
4+
5+
const typelevel = [
6+
"cats-effect"
7+
]
8+
9+
const scalameta = [
10+
"munit", "scalameta", "scalafmt",
11+
// "mdoc"
12+
]
13+
14+
const softwaremill = [
15+
"scalar", "scalarconf"
16+
]
17+
18+
const sbt = [
19+
"sbt"
20+
]
21+
22+
const lihaoi = [
23+
"os-lib", "requests-scala"
24+
]
25+
26+
const lightbend = [
27+
"akka", "playframework"
28+
]
29+
30+
const others = [
31+
"pekko"
32+
]
33+
34+
function hashTag(word: String) {
35+
return `#${word}`
36+
}
37+
38+
export const allHashTags =
39+
scalalang.concat(typelevel,
40+
scalameta,
41+
softwaremill,
42+
// sbt, // sbt seems to be a thing in TV in Brasil
43+
// lihaoi, // apparently people like to discuss hardware mills a lot
44+
lightbend,
45+
others
46+
).map(w => hashTag(w))

src/scala/index.ts

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
1-
const scalalang = [
2-
"scala", "scala3", "dotty"
3-
]
1+
import { allHashTags } from "./hashtags";
2+
import { scalaRelatedOrganizationProfiles } from "./accounts";
43

5-
const typelevel = [
6-
"cats-effect"
7-
]
8-
9-
const scalameta = [
10-
"munit", "scalameta", "scalafmt",
11-
// "mdoc"
12-
]
13-
14-
const softwaremill = [
15-
"scalar", "scalarconf"
16-
]
17-
18-
const sbt = [
19-
"sbt"
20-
]
21-
22-
const lihaoi = [
23-
"os-lib", "requests-scala"
24-
]
25-
26-
const lightbend = [
27-
"akka", "playframework"
28-
]
29-
30-
const others = [
31-
"pekko"
32-
]
33-
34-
const allHashTags =
35-
scalalang.concat(typelevel,
36-
scalameta,
37-
softwaremill,
38-
// sbt, // sbt seems to be a thing in TV in Brasil
39-
// lihaoi, // apparently people like to discuss hardware mills a lot
40-
lightbend,
41-
others
42-
).map(w => hashTag(w))
43-
44-
function hashTag(word: String) {
45-
return `#${word}`
46-
}
47-
48-
export function isAboutScala(text: string): boolean {
4+
function containsRelevantHashtag(text: string): boolean {
495
const input = text.toLowerCase();
506
const textWords = input.split(/\s+/);
517
return allHashTags.map(v => v.toLowerCase()).some(tag => textWords.includes(tag));
528
}
539

10+
function postedByScalaOrgAccount(author: string): boolean {
11+
return scalaRelatedOrganizationProfiles.includes(author);
12+
}
13+
14+
export function isAboutScala(author: string, text: string): boolean {
15+
return postedByScalaOrgAccount(author) || containsRelevantHashtag(text);
16+
}
17+

tests/algos/scala-feed.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
import { scalaRelatedOrganizationProfiles } from '../../src/scala/accounts';
12
import { isAboutScala } from '../../src/scala/index';
23

4+
const randomAuthorDid = "did:plc:abcde12345"
5+
36
describe('testing isAboutScala', () => {
47
test('the #Scala hashtag should be picked up', () => {
58
expect(
6-
isAboutScala("#Scala")
9+
isAboutScala(randomAuthorDid, "#Scala")
710
).toBe(true);
811
});
912
test('proper message should be qualified as Scala related', () => {
1013
expect(
11-
isAboutScala("We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala...")
14+
isAboutScala(randomAuthorDid, "We've a full house at the #London #Scala OSS Hack night this Wednesday! www.meetup.com/london-scala...")
15+
).toBe(true);
16+
});
17+
test('post by scala related org account should be qualified as Scala related', () => {
18+
expect(
19+
isAboutScala(scalaRelatedOrganizationProfiles[0], "This one doesn't have a hashtag")
1220
).toBe(true);
1321
});
1422
test('empty message should not be qualified as Scala', () => {
1523
expect(
16-
isAboutScala("")
24+
isAboutScala(randomAuthorDid, "")
1725
).toBe(false);
1826
});
1927
});

0 commit comments

Comments
 (0)