From 8f0a7e29d90daf3ffe65b19dfe32712aa8f63cdc Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 26 Dec 2022 22:32:14 -0500 Subject: [PATCH] Fix display reshares as reshared user and indicate with icon --- .../timeline/status_header_control.dart | 4 +- lib/models/timeline_entry.dart | 135 +++++++++--------- .../timeline_entry_mastodon_extensions.dart | 19 ++- 3 files changed, 91 insertions(+), 67 deletions(-) diff --git a/lib/controls/timeline/status_header_control.dart b/lib/controls/timeline/status_header_control.dart index 686ae7d..73e413d 100644 --- a/lib/controls/timeline/status_header_control.dart +++ b/lib/controls/timeline/status_header_control.dart @@ -28,8 +28,9 @@ class StatusHeaderControl extends StatelessWidget { @override Widget build(BuildContext context) { + final authorId = entry.isReshare ? entry.reshareAuthorId : entry.authorId; final author = getIt() - .getById(entry.authorId) + .getById(authorId) .getValueOrElse(() => Connection()); return Row( mainAxisAlignment: MainAxisAlignment.start, @@ -74,6 +75,7 @@ class StatusHeaderControl extends StatelessWidget { // ), ], ), + if (entry.isReshare) const Icon(Icons.repeat), if (showOpenControl) ...[ const Expanded(child: SizedBox()), buildActionBar(context), diff --git a/lib/models/timeline_entry.dart b/lib/models/timeline_entry.dart index 6534953..b8b436d 100644 --- a/lib/models/timeline_entry.dart +++ b/lib/models/timeline_entry.dart @@ -14,6 +14,10 @@ class TimelineEntry { final String parentAuthorId; + final String reshareAuthor; + + final String reshareAuthorId; + final int creationTimestamp; final int backdatedTimestamp; @@ -65,6 +69,8 @@ class TimelineEntry { this.authorId = '', this.parentAuthor = '', this.parentAuthorId = '', + this.reshareAuthor = '', + this.reshareAuthorId = '', this.externalLink = '', this.locationData = const LocationData(), this.isFavorited = false, @@ -76,22 +82,12 @@ class TimelineEntry { }); TimelineEntry.randomBuilt() - : creationTimestamp = DateTime - .now() - .millisecondsSinceEpoch, - backdatedTimestamp = DateTime - .now() - .millisecondsSinceEpoch, - modificationTimestamp = DateTime - .now() - .millisecondsSinceEpoch, + : creationTimestamp = DateTime.now().millisecondsSinceEpoch, + backdatedTimestamp = DateTime.now().millisecondsSinceEpoch, + modificationTimestamp = DateTime.now().millisecondsSinceEpoch, id = randomId(), - isReshare = DateTime - .now() - .second ~/ 2 == 0 ? true : false, - isPublic = DateTime - .now() - .second ~/ 2 == 0 ? true : false, + isReshare = DateTime.now().second ~/ 2 == 0 ? true : false, + isPublic = DateTime.now().second ~/ 2 == 0 ? true : false, parentId = randomId(), externalLink = 'Random external link ${randomId()}', body = 'Random post text ${randomId()}', @@ -101,43 +97,46 @@ class TimelineEntry { authorId = 'Random authorId ${randomId()}', parentAuthor = 'Random parent author ${randomId()}', parentAuthorId = 'Random parent author id ${randomId()}', + reshareAuthor = 'Random parent author ${randomId()}', + reshareAuthorId = 'Random parent author id ${randomId()}', locationData = LocationData.randomBuilt(), - isFavorited = DateTime - .now() - .second ~/ 2 == 0 ? true : false, + isFavorited = DateTime.now().second ~/ 2 == 0 ? true : false, links = [], likes = [], dislikes = [], mediaAttachments = [], engagementSummary = const EngagementSummary(); - TimelineEntry copy({int? creationTimestamp, - int? backdatedTimestamp, - int? modificationTimestamp, - bool? isReshare, - bool? isPublic, - String? id, - String? parentId, - String? externalLink, - String? body, - String? title, - String? spoilerText, - String? author, - String? authorId, - String? parentAuthor, - String? parentAuthorId, - LocationData? locationData, - bool? isFavorited, - List? links, - List? likes, - List? dislikes, - List? mediaAttachments, - EngagementSummary? engagementSummary}) { + TimelineEntry copy( + {int? creationTimestamp, + int? backdatedTimestamp, + int? modificationTimestamp, + bool? isReshare, + bool? isPublic, + String? id, + String? parentId, + String? externalLink, + String? body, + String? title, + String? spoilerText, + String? author, + String? authorId, + String? parentAuthor, + String? parentAuthorId, + String? reshareAuthor, + String? reshareAuthorId, + LocationData? locationData, + bool? isFavorited, + List? links, + List? likes, + List? dislikes, + List? mediaAttachments, + EngagementSummary? engagementSummary}) { return TimelineEntry( creationTimestamp: creationTimestamp ?? this.creationTimestamp, backdatedTimestamp: backdatedTimestamp ?? this.backdatedTimestamp, modificationTimestamp: - modificationTimestamp ?? this.modificationTimestamp, + modificationTimestamp ?? this.modificationTimestamp, id: id ?? this.id, isReshare: isReshare ?? this.isReshare, isPublic: isPublic ?? this.isPublic, @@ -150,6 +149,8 @@ class TimelineEntry { authorId: authorId ?? this.authorId, parentAuthor: parentAuthor ?? this.parentAuthor, parentAuthorId: parentAuthorId ?? this.parentAuthorId, + reshareAuthor: parentAuthor ?? this.reshareAuthor, + reshareAuthorId: parentAuthorId ?? this.reshareAuthorId, locationData: locationData ?? this.locationData, isFavorited: isFavorited ?? this.isFavorited, links: links ?? this.links, @@ -172,30 +173,32 @@ class TimelineEntry { @override bool operator ==(Object other) => identical(this, other) || - other is TimelineEntry && - runtimeType == other.runtimeType && - id == other.id && - parentId == other.parentId && - parentAuthor == other.parentAuthor && - parentAuthorId == other.parentAuthorId && - creationTimestamp == other.creationTimestamp && - backdatedTimestamp == other.backdatedTimestamp && - modificationTimestamp == other.modificationTimestamp && - body == other.body && - title == other.title && - spoilerText == other.spoilerText && - isReshare == other.isReshare && - isPublic == other.isPublic && - author == other.author && - authorId == other.authorId && - externalLink == other.externalLink && - locationData == other.locationData && - isFavorited == other.isFavorited && - links == other.links && - likes == other.likes && - dislikes == other.dislikes && - mediaAttachments == other.mediaAttachments && - engagementSummary == other.engagementSummary; + other is TimelineEntry && + runtimeType == other.runtimeType && + id == other.id && + parentId == other.parentId && + parentAuthor == other.parentAuthor && + parentAuthorId == other.parentAuthorId && + reshareAuthor == other.reshareAuthor && + reshareAuthorId == other.reshareAuthorId && + creationTimestamp == other.creationTimestamp && + backdatedTimestamp == other.backdatedTimestamp && + modificationTimestamp == other.modificationTimestamp && + body == other.body && + title == other.title && + spoilerText == other.spoilerText && + isReshare == other.isReshare && + isPublic == other.isPublic && + author == other.author && + authorId == other.authorId && + externalLink == other.externalLink && + locationData == other.locationData && + isFavorited == other.isFavorited && + links == other.links && + likes == other.likes && + dislikes == other.dislikes && + mediaAttachments == other.mediaAttachments && + engagementSummary == other.engagementSummary; @override int get hashCode => @@ -203,6 +206,8 @@ class TimelineEntry { parentId.hashCode ^ parentAuthor.hashCode ^ parentAuthorId.hashCode ^ + reshareAuthor.hashCode ^ + reshareAuthorId.hashCode ^ creationTimestamp.hashCode ^ backdatedTimestamp.hashCode ^ modificationTimestamp.hashCode ^ diff --git a/lib/serializers/mastodon/timeline_entry_mastodon_extensions.dart b/lib/serializers/mastodon/timeline_entry_mastodon_extensions.dart index 64ec5ff..a09ce8f 100644 --- a/lib/serializers/mastodon/timeline_entry_mastodon_extensions.dart +++ b/lib/serializers/mastodon/timeline_entry_mastodon_extensions.dart @@ -54,8 +54,23 @@ extension TimelineEntryMastodonExtensions on TimelineEntry { repliesCount: repliesCount, ); + final connectionManager = getIt(); final connection = ConnectionMastodonExtensions.fromJson(json['account']); - getIt().addConnection(connection); + connectionManager.addConnection(connection); + + late final String reshareAuthor; + late final String reshareAuthorId; + if (isReshare) { + final rebloggedUser = + ConnectionMastodonExtensions.fromJson(json['reblog']['account']); + connectionManager.addConnection(rebloggedUser); + reshareAuthor = rebloggedUser.name; + reshareAuthorId = rebloggedUser.id; + } else { + reshareAuthorId = ''; + reshareAuthor = ''; + } + return TimelineEntry( creationTimestamp: timestamp, modificationTimestamp: modificationTimestamp, @@ -68,6 +83,8 @@ extension TimelineEntryMastodonExtensions on TimelineEntry { id: id, parentId: parentId, parentAuthorId: parentAuthorId, + reshareAuthor: reshareAuthor, + reshareAuthorId: reshareAuthorId, isFavorited: isFavorited, externalLink: externalLink, author: author,