revise api extensions

* change originInstanceHost extensions to
  extract from deeper structures
* add extension for getting proper user name
  that includes originInstanceHost if needed
This commit is contained in:
krawieck 2021-01-24 23:06:54 +01:00
parent 6c1049b5ee
commit 190ae1b3ae
6 changed files with 34 additions and 37 deletions

View File

@ -231,7 +231,7 @@ class CommunitiesTab extends HookWidget {
const SizedBox(width: 30),
const SizedBox(width: 10),
Text(
'''!${comm.community.name}${comm.community.local ? '' : '@${comm.originInstanceHost}'}''',
'''!${comm.community.name}${comm.community.local ? '' : '@${comm.community.originInstanceHost}'}''',
),
],
),

View File

@ -310,11 +310,11 @@ class _CommunityOverview extends StatelessWidget {
text: '@',
style: TextStyle(fontWeight: FontWeight.w200)),
TextSpan(
text: community.originInstanceHost,
text: community.community.originInstanceHost,
style: const TextStyle(fontWeight: FontWeight.w600),
recognizer: TapGestureRecognizer()
..onTap = () => goToInstance(
context, community.originInstanceHost),
context, community.community.originInstanceHost),
),
],
),

View File

@ -10,30 +10,41 @@ import '../cleanup_url.dart';
// [.isLocal] is true iff `.originInstanceHost == .instanceHost`
extension GetInstanceCommunityView on CommunityView {
String get originInstanceHost => _extract(community.actorId);
extension GetInstanceCommunitySafe on CommunitySafe {
String get originInstanceHost => _extract(actorId);
// bool get isLocal => originInstanceHost == instanceHost;
}
extension GetInstanceUserView on UserViewSafe {
String get originInstanceHost => _extract(user.actorId);
extension GetInstanceUserSafe on UserSafe {
String get originInstanceHost => _extract(actorId);
// bool get isLocal => originInstanceHost == instanceHost;
}
extension GetInstanceCommunityFollowerView on CommunityFollowerView {
String get originInstanceHost => _extract(community.actorId);
extension GetInstancePostView on Post {
String get originInstanceHost => _extract(apId);
// bool get isLocal => originInstanceHost == instanceHost;
}
extension GetInstancePostView on PostView {
String get originInstanceHost => _extract(post.apId);
// bool get isLocal => originInstanceHost == instanceHost;
}
extension GetInstanceCommentView on CommentView {
String get originInstanceHost => _extract(comment.apId);
extension GetInstanceCommentView on Comment {
String get originInstanceHost => _extract(apId);
// bool get isLocal => originInstanceHost == instanceHost;
}
// TODO: change it to something more robust? regex?
String _extract(String s) => cleanUpUrl(s.split('/')[2]);
extension ProperName on UserSafe {
String get properName {
final name = () {
if (preferredUsername != null && preferredUsername != '') {
return preferredUsername;
} else {
return '@${this.name}';
}
}();
if (!local) return '$name@$originInstanceHost';
return name;
}
}

View File

@ -222,20 +222,7 @@ class CommentWidget extends HookWidget {
}
// decide which username to use
final username = () {
final name = () {
if (comment.creator.preferredUsername != null &&
comment.creator.preferredUsername != '') {
return comment.creator.preferredUsername;
} else {
return '@${comment.creator.name}';
}
}();
if (!comment.comment.local) return '$name@${comment.originInstanceHost}';
return name;
}();
final username = comment.creator.properName;
final body = () {
if (isDeleted.value) {

View File

@ -173,12 +173,12 @@ class PostWidget extends HookWidget {
text: '@',
style: TextStyle(fontWeight: FontWeight.w300)),
TextSpan(
text: post.originInstanceHost,
text: post.post.originInstanceHost,
style:
const TextStyle(fontWeight: FontWeight.w600),
recognizer: TapGestureRecognizer()
..onTap = () => goToInstance(
context, post.originInstanceHost)),
context, post.post.originInstanceHost)),
],
),
)
@ -195,8 +195,7 @@ class PostWidget extends HookWidget {
text: 'by',
style: TextStyle(fontWeight: FontWeight.w300)),
TextSpan(
text:
''' ${post.creator.preferredUsername ?? post.creator.name}''',
text: ' ${post.creator.properName}',
style:
const TextStyle(fontWeight: FontWeight.w600),
recognizer: TapGestureRecognizer()

View File

@ -220,10 +220,10 @@ class _UserOverview extends HookWidget {
style: theme.textTheme.caption,
),
InkWell(
onTap: () =>
goToInstance(context, userView.originInstanceHost),
onTap: () => goToInstance(
context, userView.user.originInstanceHost),
child: Text(
userView.originInstanceHost,
userView.user.originInstanceHost,
style: theme.textTheme.caption,
),
)