kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add replacing tag links to the local server
rodzic
03b3d1c272
commit
9b778999e5
|
@ -1,6 +1,4 @@
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:relatica/services/auth_service.dart';
|
|
||||||
import 'package:relatica/services/reshared_via_service.dart';
|
|
||||||
|
|
||||||
import '../../globals.dart';
|
import '../../globals.dart';
|
||||||
import '../../models/engagement_summary.dart';
|
import '../../models/engagement_summary.dart';
|
||||||
|
@ -8,10 +6,13 @@ import '../../models/link_data.dart';
|
||||||
import '../../models/location_data.dart';
|
import '../../models/location_data.dart';
|
||||||
import '../../models/timeline_entry.dart';
|
import '../../models/timeline_entry.dart';
|
||||||
import '../../models/visibility.dart';
|
import '../../models/visibility.dart';
|
||||||
|
import '../../services/auth_service.dart';
|
||||||
import '../../services/connections_manager.dart';
|
import '../../services/connections_manager.dart';
|
||||||
import '../../services/hashtag_service.dart';
|
import '../../services/hashtag_service.dart';
|
||||||
|
import '../../services/reshared_via_service.dart';
|
||||||
import '../../utils/active_profile_selector.dart';
|
import '../../utils/active_profile_selector.dart';
|
||||||
import '../../utils/dateutils.dart';
|
import '../../utils/dateutils.dart';
|
||||||
|
import '../../utils/html_to_edit_text_helper.dart';
|
||||||
import 'connection_mastodon_extensions.dart';
|
import 'connection_mastodon_extensions.dart';
|
||||||
import 'hashtag_mastodon_extensions.dart';
|
import 'hashtag_mastodon_extensions.dart';
|
||||||
import 'link_preview_mastodon_extensions.dart';
|
import 'link_preview_mastodon_extensions.dart';
|
||||||
|
@ -100,7 +101,6 @@ extension TimelineEntryMastodonExtensions on TimelineEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = '';
|
const title = '';
|
||||||
final body = json['content'] ?? '';
|
|
||||||
final spoilerText = json['spoiler_text'] ?? '';
|
final spoilerText = json['spoiler_text'] ?? '';
|
||||||
final externalLink = json['uri'] ?? '';
|
final externalLink = json['uri'] ?? '';
|
||||||
const actualLocationData = LocationData();
|
const actualLocationData = LocationData();
|
||||||
|
@ -137,6 +137,9 @@ extension TimelineEntryMastodonExtensions on TimelineEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final rawBody = json['content'] ?? '';
|
||||||
|
final body = htmlWithTagLinkSwap(rawBody, tags);
|
||||||
|
|
||||||
final connection = ConnectionMastodonExtensions.fromJson(json['account']);
|
final connection = ConnectionMastodonExtensions.fromJson(json['account']);
|
||||||
connectionManager?.upsertConnection(connection);
|
connectionManager?.upsertConnection(connection);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import 'package:html/dom.dart';
|
import 'package:html/dom.dart';
|
||||||
import 'package:html/parser.dart';
|
import 'package:html/parser.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
|
import '../globals.dart';
|
||||||
|
import '../services/auth_service.dart';
|
||||||
|
import 'network_utils.dart';
|
||||||
|
|
||||||
String htmlToSimpleText(String htmlContentFragment) {
|
String htmlToSimpleText(String htmlContentFragment) {
|
||||||
try {
|
try {
|
||||||
|
@ -13,6 +18,49 @@ String htmlToSimpleText(String htmlContentFragment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateSwapTagLinks(Node node, List<String> tags) {
|
||||||
|
if (node is Element) {
|
||||||
|
if (node.attributes.containsKey('href') &&
|
||||||
|
(node.attributes['class']?.contains('hashtag') ?? false) &&
|
||||||
|
node.attributes['rel'] == 'tag') {
|
||||||
|
final url = Uri.parse(node.attributes['href'] ?? '');
|
||||||
|
late final String tag;
|
||||||
|
final pathEnd = p.split(url.path).last;
|
||||||
|
if (pathEnd == 'search' && url.queryParameters.containsKey('tag')) {
|
||||||
|
tag = url.queryParameters['search']!;
|
||||||
|
} else {
|
||||||
|
tag = pathEnd;
|
||||||
|
}
|
||||||
|
// final tagLowercase = tag.toLowerCase();
|
||||||
|
// final hasExpectedTag = tags
|
||||||
|
// .firstWhere((t) => t.toLowerCase() == tagLowercase,
|
||||||
|
// orElse: () => '')
|
||||||
|
// .isNotEmpty;
|
||||||
|
const hasExpectedTag = true;
|
||||||
|
if (hasExpectedTag) {
|
||||||
|
final profile = getIt<AccountsService>().currentProfile;
|
||||||
|
final newTagUrl = generateTagUrlFromProfile(profile, tag);
|
||||||
|
print(node.attributes['href']);
|
||||||
|
node.attributes['href'] = newTagUrl.toString();
|
||||||
|
print(node.attributes['href']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.nodes.forEach((n) => _updateSwapTagLinks(n, tags));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String htmlWithTagLinkSwap(String htmlContentFragment, List<String> tags) {
|
||||||
|
try {
|
||||||
|
final dom = parseFragment(htmlContentFragment);
|
||||||
|
dom.nodes.forEach((n) => _updateSwapTagLinks(n, tags));
|
||||||
|
|
||||||
|
final result = dom.outerHtml;
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
return htmlContentFragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension NodeTextConverter on Node {
|
extension NodeTextConverter on Node {
|
||||||
String nodeToEditText() {
|
String nodeToEditText() {
|
||||||
if (nodes.isEmpty) {
|
if (nodes.isEmpty) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../friendica_client/paged_response.dart';
|
import '../friendica_client/paged_response.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
|
|
||||||
final _logger = Logger('NetworkUtils');
|
final _logger = Logger('NetworkUtils');
|
||||||
|
@ -267,3 +268,7 @@ FutureResult<String, ExecError> deleteUrl(
|
||||||
ExecError(type: ErrorType.localError, message: e.toString()));
|
ExecError(type: ErrorType.localError, message: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uri generateTagUrlFromProfile(Profile profile, String tag) {
|
||||||
|
return Uri.https(profile.serverName, '/search', {'tag': tag});
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue