Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"botAccount": "Bot Account",
"newUser": "New User",
"cakeDay": "Cake Day",
"description": "Description",
"isNSFW": "Is NSFW",
"isNSFL": "Is NSFL",
"public": "Public",
"filter": "Filter by",
"filter_all": "All",
"filter_allResults": "All results",
Expand Down Expand Up @@ -107,6 +111,7 @@
"feeds_input": "Add input",
"feeds_import": "Import feed",
"feeds_selectInputs": "Select inputs",
"feeds_inputs": "Inputs",
"feeds_addTo": "Add to feed",
"topics": "Topics",
"topic": "Topic",
Expand Down Expand Up @@ -640,6 +645,7 @@
"action_moderateLock": "Lock Post",
"save": "Save",
"saveChanges": "Save changes",
"saveLocal": "Save locally",
"searchTheFediverse": "Search the fediverse",
"languages": "Languages",
"systemLanguage": "System language",
Expand Down
159 changes: 156 additions & 3 deletions lib/src/api/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,167 @@ class APIFeed {
}

Future<FeedModel> get(int feedId) async {
throw UnimplementedError('Not yet implemented');
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed';
final query = {'id': feedId.toString()};

final response = await client.get(path, queryParams: query);

return FeedModel.fromPiefed(response.bodyJson);
}
}

Future<FeedModel> getByName(String feedName) async {
throw UnimplementedError('Not yet implemented');
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed';
final query = {'name': feedName};

final response = await client.get(path, queryParams: query);

return FeedModel.fromPiefed(response.bodyJson);
}
}

Future<FeedModel> subscribe(int feedId, bool state) async {
throw UnimplementedError('Not yet implemented');
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed/follow';

final response = await client.post(
path,
body: {'feed_id': feedId, 'follow': state},
);

return FeedModel.fromPiefed(response.bodyJson);
}
}

Future<FeedModel> edit({
required int feedId,
String? title,
String? description,
String? iconUrl,
String? bannerUrl,
bool? nsfw,
bool? nsfl,
bool? public,
bool? instanceFeed,
bool? showChildPosts,
int? parentId,
List<String>? communities,
}) async {
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed';

final response = await client.put(
path,
body: {
'feed_id': feedId,
'title': ?title,
'description': ?description,
'icon_url': ?iconUrl,
'banner_url': ?bannerUrl,
'nsfw': ?nsfw,
'nsfl': ?nsfl,
'public': ?public,
'is_instance_feed': ?instanceFeed,
'show_child_posts': ?showChildPosts,
'parent_feed_id': ?parentId,
'communities': ?communities?.join('\n'),
},
);

return FeedModel.fromPiefed(response.bodyJson);
}
}

Future<FeedModel> create({
required String title,
String? description,
String? iconUrl,
String? bannerUrl,
bool? nsfw,
bool? nsfl,
bool? public,
bool? instanceFeed,
bool? showChildPosts,
int? parentId,
List<String>? communities,
}) async {
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed';

final response = await client.post(
path,
body: {
'name': title.toLowerCase(),
'title': title,
'description': ?description,
'icon_url': ?iconUrl,
'banner_url': ?bannerUrl,
'nsfw': ?nsfw,
'nsfl': ?nsfl,
'public': ?public,
'is_instance_feed': ?instanceFeed,
'show_child_posts': ?showChildPosts,
'parent_feed_id': ?parentId,
'communities': ?communities?.join('\n'),
},
);

return FeedModel.fromPiefed(response.bodyJson);
}
}

Future<void> delete({required int feedId}) async {
switch (client.software) {
case ServerSoftware.mbin:
throw Exception('Feeds not available on mbin');

case ServerSoftware.lemmy:
throw Exception('Feeds not available on lemmy');

case ServerSoftware.piefed:
const path = '/feed/delete';

final response = await client.post(
path,
body: {'feed_id': feedId, 'deleted': true},
);
}
}
}
20 changes: 13 additions & 7 deletions lib/src/controller/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class AppController with ChangeNotifier {
FeedInput(name: input.name, sourceType: input.source),
)
.toSet(),
server: feed.server,
owner: feed.owner,
),
),
),
Expand Down Expand Up @@ -810,7 +812,13 @@ class AppController with ChangeNotifier {

await database
.into(database.feeds)
.insertOnConflictUpdate(FeedsCompanion.insert(name: name));
.insertOnConflictUpdate(
FeedsCompanion.insert(
name: name,
server: Value(value.server),
owner: Value(value.owner),
),
);

await database.transaction(() async {
for (final input in value.inputs) {
Expand Down Expand Up @@ -1003,17 +1011,15 @@ class AppController with ChangeNotifier {
.get())
.firstOrNull;

if (cachedValue != null) return cachedValue.sourceId;
if (cachedValue != null && cachedValue.sourceId != null) {
return cachedValue.sourceId;
}

try {
final newValue = switch (source) {
FeedSource.community => (await api.community.getByName(name)).id,
FeedSource.user => (await api.users.getByName(name)).id,
FeedSource.feed =>
name.split(':').last !=
instanceHost // tmp until proper getByName method can be made
? throw Exception('Wrong instance')
: int.parse(name.split(':').first),
FeedSource.feed => (await api.feed.getByName(normalisedName)).id,
FeedSource.topic =>
name.split(':').last !=
instanceHost // tmp until proper getByName method can be made
Expand Down
5 changes: 5 additions & 0 deletions lib/src/controller/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Accounts extends Table {
@DataClassName('RawFeed')
class Feeds extends Table {
TextColumn get name => text().withLength(min: 1)();
BoolColumn get server => boolean().withDefault(const Constant(false))();
TextColumn get owner => text().nullable()();

@override
Set<Column<Object>> get primaryKey => {name};
Expand Down Expand Up @@ -492,6 +494,9 @@ class InterstellarDatabase extends _$InterstellarDatabase {
await m.dropColumn(schema.profiles, 'compact_mode');
await m.dropColumn(schema.profiles, 'show_posts_cards');

await m.addColumn(schema.feeds, schema.feeds.server);
await m.addColumn(schema.feeds, schema.feeds.owner);

await m.addColumn(schema.accounts, schema.accounts.unifiedpushKey);
await m.addColumn(schema.accounts, schema.accounts.unifiedpushToken);
await m.create(schema.accountUnifiedpushToken);
Expand Down
Loading
Loading