Add trailing @originInstanceHost to comments/community list

This commit is contained in:
shilangyu 2021-01-02 16:26:29 +00:00
parent 81ea5c051b
commit e82c1fa576
3 changed files with 26 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import 'package:lemmy_api_client/lemmy_api_client.dart';
import '../hooks/delayed_loading.dart'; import '../hooks/delayed_loading.dart';
import '../hooks/memo_future.dart'; import '../hooks/memo_future.dart';
import '../hooks/stores.dart'; import '../hooks/stores.dart';
import '../util/extensions/api.dart';
import '../util/extensions/iterators.dart'; import '../util/extensions/iterators.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
@ -205,7 +206,9 @@ class CommunitiesTab extends HookWidget {
else else
SizedBox(width: 30), SizedBox(width: 30),
SizedBox(width: 10), SizedBox(width: 10),
Text('!${comm.communityName}'), Text(
'''!${comm.communityName}${comm.isLocal ? '' : '@${comm.originInstanceHost}'}''',
),
], ],
), ),
trailing: _CommunitySubscribeToggle( trailing: _CommunitySubscribeToggle(

View File

@ -8,28 +8,31 @@ import '../cleanup_url.dart';
// `post.instanceHost == 'lemmy.ml' // `post.instanceHost == 'lemmy.ml'
// && post.originInstanceHost == 'lemmygrad.ml`` // && post.originInstanceHost == 'lemmygrad.ml``
// [.isLocal] is true iff `.originInstanceHost == .instanceHost`
extension GetInstanceCommunityView on CommunityView { extension GetInstanceCommunityView on CommunityView {
String get originInstanceHost => _extract(actorId); String get originInstanceHost => _extract(actorId);
bool get isLocal => originInstanceHost == instanceHost;
} }
extension GetInstanceUserView on UserView { extension GetInstanceUserView on UserView {
String get originInstanceHost => _extract(actorId); String get originInstanceHost => _extract(actorId);
bool get isLocal => originInstanceHost == instanceHost;
} }
extension GetInstanceCommunityModeratorView on CommunityModeratorView { extension GetInstanceCommunityFollowerView on CommunityFollowerView {
String get originInstanceHost => _extract(userActorId); String get originInstanceHost => _extract(communityActorId);
bool get isLocal => originInstanceHost == instanceHost;
} }
extension GetInstancePostView on PostView { extension GetInstancePostView on PostView {
String get originInstanceHost => _extract(apId); String get originInstanceHost => _extract(apId);
} bool get isLocal => originInstanceHost == instanceHost;
extension GetInstanceUser on User {
String get originInstanceHost => _extract(actorId);
} }
extension GetInstanceCommentView on CommentView { extension GetInstanceCommentView on CommentView {
String get originInstanceHost => _extract(apId); String get originInstanceHost => _extract(apId);
bool get isLocal => originInstanceHost == instanceHost;
} }
// TODO: change it to something more robust? regex? // TODO: change it to something more robust? regex?

View File

@ -11,6 +11,7 @@ import 'package:url_launcher/url_launcher.dart' as ul;
import '../comment_tree.dart'; import '../comment_tree.dart';
import '../hooks/delayed_loading.dart'; import '../hooks/delayed_loading.dart';
import '../hooks/logged_in_action.dart'; import '../hooks/logged_in_action.dart';
import '../util/extensions/api.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import '../util/intl.dart'; import '../util/intl.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
@ -191,6 +192,7 @@ class Comment extends HookWidget {
// decide which username to use // decide which username to use
final username = () { final username = () {
final name = () {
if (comment.creatorPreferredUsername != null && if (comment.creatorPreferredUsername != null &&
comment.creatorPreferredUsername != '') { comment.creatorPreferredUsername != '') {
return comment.creatorPreferredUsername; return comment.creatorPreferredUsername;
@ -199,6 +201,11 @@ class Comment extends HookWidget {
} }
}(); }();
if (!comment.isLocal) return '$name@${comment.originInstanceHost}';
return name;
}();
final body = () { final body = () {
if (isDeleted.value) { if (isDeleted.value) {
return Flexible( return Flexible(