Skip to content

Commit

Permalink
add content labeling to listed posts
Browse files Browse the repository at this point in the history
  • Loading branch information
videah committed Jan 16, 2024
1 parent ebfa480 commit a0c5d21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions lib/models/mastodon/mastodon_post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:bluesky/bluesky.dart' as bsky;
import 'package:bluesky_text/bluesky_text.dart';
import 'package:collection/collection.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:intl/intl.dart' show toBeginningOfSentenceCase;
import 'package:json_annotation/json_annotation.dart';
import 'package:sky_bridge/database.dart';
import 'package:sky_bridge/facets.dart';
Expand Down Expand Up @@ -181,11 +182,18 @@ class MastodonPost {
)
.toList();

// First, take the labels and remove duplicate values.
final labels = post.labels?.map((label) => label.value).toSet();

// Then all the labels, capitalize the first letter, and join them
// with a comma.
final labelsString = labels?.map(toBeginningOfSentenceCase).join(', ');

return MastodonPost(
id: id.toString(),
createdAt: post.indexedAt.toUtc(),
sensitive: false,
spoilerText: '',
sensitive: post.labels?.isNotEmpty ?? false,
spoilerText: labelsString ?? '',
visibility: PostVisibility.public,
language: language,
uri: url,
Expand Down Expand Up @@ -300,11 +308,18 @@ class MastodonPost {
)
.toList();

// First, take the labels and remove duplicate values.
final labels = post.labels?.map((label) => label.value).toSet();

// Then all the labels, capitalize the first letter, and join them
// with a comma.
final labelsString = labels?.map(toBeginningOfSentenceCase).join(', ');

return MastodonPost(
id: (await postToDatabase(post)).id.toString(),
createdAt: post.indexedAt.toUtc(),
sensitive: false,
spoilerText: '',
sensitive: post.labels?.isNotEmpty ?? false,
spoilerText: labelsString ?? '',
visibility: PostVisibility.public,
language: post.record.langs?.first ?? 'en',
uri: url,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ packages:
source: hosted
version: "1.0.4"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
html: ^0.15.3
http: ^0.13.6
image_compression: ^1.0.4
intl: ^0.19.0
json_annotation: ^4.8.0
orm: ^3.4.4
path: ^1.8.3
Expand Down

0 comments on commit a0c5d21

Please sign in to comment.