2021-04-05 20:14:39 +02:00
|
|
|
import 'package:lemmy_api_client/v3.dart';
|
2021-01-02 01:13:13 +01:00
|
|
|
|
|
|
|
import '../cleanup_url.dart';
|
|
|
|
|
|
|
|
// Extensions to lemmy api objects which give a [.originInstanceHost] getter
|
|
|
|
// allowing for a convenient way of knowing what is the origin of the object
|
|
|
|
// For example if a post on lemmy.ml is federated from lemmygrad.ml then
|
|
|
|
// `post.instanceHost == 'lemmy.ml'
|
|
|
|
// && post.originInstanceHost == 'lemmygrad.ml``
|
|
|
|
|
2021-01-27 20:53:09 +01:00
|
|
|
extension GetOriginInstanceCommunitySafe on CommunitySafe {
|
2021-01-24 23:06:54 +01:00
|
|
|
String get originInstanceHost => _extract(actorId);
|
2021-01-02 01:13:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-05 20:14:39 +02:00
|
|
|
extension GetOriginInstancePersonSafe on PersonSafe {
|
2021-01-24 23:06:54 +01:00
|
|
|
String get originInstanceHost => _extract(actorId);
|
2021-01-02 01:13:13 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 20:53:09 +01:00
|
|
|
extension GetOriginInstancePostView on Post {
|
2021-01-24 23:06:54 +01:00
|
|
|
String get originInstanceHost => _extract(apId);
|
2021-01-02 01:13:13 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 20:53:09 +01:00
|
|
|
extension GetOriginInstanceCommentView on Comment {
|
2021-01-24 23:06:54 +01:00
|
|
|
String get originInstanceHost => _extract(apId);
|
2021-01-02 01:13:13 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 20:53:09 +01:00
|
|
|
String _extract(String url) => urlHost(url);
|
2021-01-24 23:06:54 +01:00
|
|
|
|
2021-02-24 20:52:18 +01:00
|
|
|
extension CommunityDisplayNames on CommunitySafe {
|
|
|
|
String get displayName => '!$name';
|
|
|
|
String get originDisplayName =>
|
|
|
|
local ? displayName : '!$name@$originInstanceHost';
|
|
|
|
}
|
|
|
|
|
2021-04-05 20:14:39 +02:00
|
|
|
extension UserDisplayNames on PersonSafe {
|
2021-01-26 22:28:06 +01:00
|
|
|
String get displayName {
|
2021-01-31 14:38:47 +01:00
|
|
|
if (preferredUsername != null && preferredUsername.isNotEmpty) {
|
2021-01-27 21:11:36 +01:00
|
|
|
return preferredUsername;
|
|
|
|
}
|
2021-01-24 23:06:54 +01:00
|
|
|
|
2021-01-27 21:11:36 +01:00
|
|
|
return '@$name';
|
|
|
|
}
|
|
|
|
|
|
|
|
String get originDisplayName {
|
|
|
|
if (!local) return '$displayName@$originInstanceHost';
|
2021-01-24 23:06:54 +01:00
|
|
|
|
2021-01-27 21:11:36 +01:00
|
|
|
return displayName;
|
2021-01-24 23:06:54 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-03 13:12:28 +01:00
|
|
|
|
|
|
|
extension CommentLink on Comment {
|
|
|
|
String get link => 'https://$instanceHost/post/$postId/comment/$id';
|
|
|
|
}
|