Skip to content

Commit

Permalink
Implement feature #296 Show Community Note.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fbriere committed Apr 30, 2024
1 parent 1679db4 commit 5656c14
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/45.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Implement PR #297 Add true black tweet cards when system theme is dark (thanks @TheHJC).
* Implement feature #296 Show Community Note.
* Fix issue #258 Rearranging subscriptions duplicates subscription list.
9 changes: 3 additions & 6 deletions fastlane/metadata/android/en-US/changelogs/default.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
* Fix issue #284 Hebrew Translation.
* Fix unnecessary rebuilds when using ModalRoute.of() with flutter 3.19.x.
* Fix issue #245 UNIQUE constraint failed: twitter_token error at the account renewal when Squawker opens.
* Use local time zone for absolute time (PR #285) (thanks @zihu12).
* Fix issue #293 Profile search keeps searching for first search term entered, even after deleting it and entering new search term.
* Fix issue #263 Search result not displaying properly.
* Implement PR #297 Add true black tweet cards when system theme is dark (thanks @TheHJC).
* Implement feature #296 Show Community Note.
* Fix issue #258 Rearranging subscriptions duplicates subscription list.
28 changes: 28 additions & 0 deletions lib/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ class TweetWithCard extends Tweet {
TweetWithCard? quotedStatusWithCard;
TweetWithCard? retweetedStatusWithCard;
bool? isTombstone;
TweetWithCard? birdwatchQuotedStatus;

TweetWithCard();

Expand Down Expand Up @@ -1211,9 +1212,36 @@ class TweetWithCard extends Tweet {
Map<String, dynamic> bindingValues = bindingValuesList.fold({}, (prev, elm) { prev[elm['key']] = elm['value']; return prev; });
tweet.card!['binding_values'] = bindingValues;
}
if (!leanerFeeds && result['birdwatch_pivot']?['subtitle'] != null) {
var birdwatchSubtitle = TweetWithCard.rearrangeBirdwatch(result['birdwatch_pivot']['subtitle']);
tweet.birdwatchQuotedStatus = TweetWithCard.fromJson(birdwatchSubtitle);
}
return tweet;
}

static Map<String, dynamic> rearrangeBirdwatch(Map<String, dynamic> birdwatch) {
Map<String, dynamic> newBirdwatch = {};
String text = birdwatch['text'];
newBirdwatch['text'] = text;
newBirdwatch['display_text_range'] = [0, text.length - 1];
Map<String, dynamic> entities = birdwatch['entities'][0];
int fromIndex = entities['fromIndex'];
int toIndex = entities['toIndex'];
String displayedUrl = text.substring(fromIndex, toIndex);
String url = entities['ref']['url'];
newBirdwatch['entities'] = {
'urls': [
{
'display_url': displayedUrl,
'expanded_url': url,
'url': url,
'indices': [fromIndex, toIndex]
}
]
};
return newBirdwatch;
}

factory TweetWithCard.fromCardJson(Map<String, dynamic> tweets, Map<String, dynamic> users, Map<String, dynamic> e) {
var user = e['user_id_str'] == null ? null : UserWithExtra.fromJson(users[e['user_id_str']]);

Expand Down
53 changes: 53 additions & 0 deletions lib/tweet/tweet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TweetTile extends StatefulWidget {
final TweetWithCard tweet;
final bool isPinned;
final bool isThread;
final bool isBirdwatchQuote;
final int? tweetIdx;
final VisiblePositionState? visiblePositionState;

Expand All @@ -53,6 +54,7 @@ class TweetTile extends StatefulWidget {
required this.tweet,
this.isPinned = false,
this.isThread = false,
this.isBirdwatchQuote = false,
this.tweetIdx,
this.visiblePositionState})
: super(key: key);
Expand All @@ -69,6 +71,7 @@ class TweetTileState extends State<TweetTile> with SingleTickerProviderStateMixi
late final TweetWithCard tweet;
late final bool isPinned;
late final bool isThread;
late final bool isBirdwatchQuote;

TranslationStatus _translationStatus = TranslationStatus.original;

Expand Down Expand Up @@ -235,6 +238,7 @@ class TweetTileState extends State<TweetTile> with SingleTickerProviderStateMixi
tweet = widget.tweet;
isPinned = widget.isPinned;
isThread = widget.isThread;
isBirdwatchQuote = widget.isBirdwatchQuote;

// Get the text to display from the actual tweet, i.e. the retweet if there is one, otherwise we end up with "RT @" crap in our text
var actualTweet = tweet.retweetedStatusWithCard ?? tweet;
Expand Down Expand Up @@ -467,6 +471,54 @@ class TweetTileState extends State<TweetTile> with SingleTickerProviderStateMixi
style: TextStyle(fontSize: optionTweetFontSizeValue)));
}

if (isBirdwatchQuote) {
return Card(
child: Container(
// Fill the width so both RTL and LTR text are displayed correctly
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Column(
children: [
_TweetTileLeading(icon: Symbols.group_rounded, children: [
TextSpan(
text: 'Readers added context',
style: TextStyle(color: theme.textTheme.bodySmall!.color, fontSize: theme.textTheme.bodySmall!.fontSize, fontWeight: ui.FontWeight.bold),
)
]),
SizedBox(height: 8),
AutoDirection(
text: tweetText,
child: Text.rich(
TextSpan(children: [
..._displayParts.map((e) {
if (e.plainText != null) {
return TextSpan(text: e.plainText, style: TextStyle(fontSize: optionTweetFontSizeValue));
}
else {
return e.entity!;
}
})]),
)
),
]
)
)
);
}

var birdwatchQuoted = Container();
if (tweet.birdwatchQuotedStatus != null) {
birdwatchQuoted = Container(
decoration: BoxDecoration(border: Border.all(color: theme.primaryColor), borderRadius: BorderRadius.circular(8)),
margin: const EdgeInsets.all(8),
child: TweetTile(
clickable: false,
tweet: tweet.birdwatchQuotedStatus!,
isBirdwatchQuote: true,
),
);
}

var quotedTweet = Container();

if (tweet.isQuoteStatus ?? false) {
Expand Down Expand Up @@ -685,6 +737,7 @@ class TweetTileState extends State<TweetTile> with SingleTickerProviderStateMixi
media,
quotedTweet,
TweetCard(tweet: tweet, card: tweet.card),
birdwatchQuoted,
Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 8),
Expand Down

0 comments on commit 5656c14

Please sign in to comment.