This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backends: make init async, add glitch (#355)
* add glitch-soc with post formatting & emoji reactions support. * force adapter creation to be async
- Loading branch information
1 parent
0516205
commit a0b3269
Showing
11 changed files
with
157 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import "package:fediverse_objects/mastodon.dart" as mastodon; | ||
import "package:kaiteki/fediverse/backends/glitch/capabilities.dart"; | ||
import "package:kaiteki/fediverse/backends/glitch/client.dart"; | ||
import "package:kaiteki/fediverse/backends/mastodon/shared_adapter.dart"; | ||
import "package:kaiteki/fediverse/interfaces/reaction_support.dart"; | ||
|
||
import "../../model/emoji/emoji.dart"; | ||
import "../../model/instance.dart"; | ||
import "../../model/notification.dart"; | ||
import "../../model/post/post.dart"; | ||
|
||
class GlitchAdapter extends SharedMastodonAdapter<GlitchClient> | ||
implements ReactionSupport { | ||
@override | ||
final String instance; | ||
final mastodon.Instance instanceInfo; | ||
|
||
static Future<GlitchAdapter> create(String instance) async { | ||
final cli = GlitchClient(instance); | ||
final instanceInfo = await cli.getInstance(); | ||
return GlitchAdapter.custom(instance, instanceInfo, cli); | ||
} | ||
|
||
GlitchAdapter.custom(this.instance, this.instanceInfo, super.client); | ||
|
||
@override | ||
GlitchCapabilities get capabilities { | ||
final supportsReactions = | ||
(instanceInfo.configuration?.reactions?.maxReactions ?? 0) != 0; | ||
|
||
return GlitchCapabilities(supportsReactions); | ||
} | ||
|
||
@override | ||
Future<Instance?> probeInstance() async { | ||
if (!instanceInfo.version.contains("+glitch")) { | ||
return null; | ||
} | ||
|
||
return toInstance(instanceInfo); | ||
} | ||
|
||
@override | ||
Future<Instance> getInstance() async { | ||
return toInstance(instanceInfo); | ||
} | ||
|
||
@override | ||
Future<void> deleteAccount(String password) { | ||
// TODO(Craftplacer): implement deleteAccount | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<void> markAllNotificationsAsRead() async { | ||
// HACK(Craftplacer): refetching latest notifcation will mark previously unfetched notifications as read as well | ||
final latest = await client.getNotifications(limit: 1); | ||
if (latest.isEmpty) return; | ||
await client.setMarkerPosition(notifications: latest.first.id); | ||
} | ||
|
||
@override | ||
Future<void> markNotificationAsRead(Notification notification) { | ||
throw UnsupportedError( | ||
"Mastodon does not support marking individual notifications as read", | ||
); | ||
} | ||
|
||
@override | ||
Future<void> addReaction(Post post, Emoji emoji) async { | ||
await client.react(post.id, emoji.tag); | ||
} | ||
|
||
@override | ||
Future<void> removeReaction(Post post, Emoji emoji) async { | ||
await client.removeReaction(post.id, emoji.tag); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/kaiteki/lib/fediverse/backends/glitch/capabilities.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import "package:kaiteki/fediverse/backends/mastodon/capabilities.dart"; | ||
import "package:kaiteki/fediverse/interfaces/reaction_support.dart"; | ||
import "package:kaiteki/fediverse/model/formatting.dart"; | ||
|
||
class GlitchCapabilities extends MastodonCapabilities | ||
implements ReactionSupportCapabilities { | ||
final bool supportsReactions; | ||
|
||
const GlitchCapabilities(this.supportsReactions); | ||
|
||
// TODO(erincandescent): Take from | ||
// api/v1/instance:configuration.statuses.supported_media_types | ||
@override | ||
Set<Formatting> get supportedFormattings { | ||
return const { | ||
Formatting.plainText, | ||
Formatting.markdown, | ||
}; | ||
} | ||
|
||
@override | ||
bool get supportsCustomEmojiReactions => supportsReactions; | ||
@override | ||
bool get supportsUnicodeEmojiReactions => supportsReactions; | ||
@override | ||
bool get supportsMultipleReactions => supportsReactions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import "package:kaiteki/fediverse/backends/mastodon/client.dart"; | ||
import "package:kaiteki/http/http.dart"; | ||
|
||
class GlitchClient extends MastodonClient { | ||
GlitchClient(super.instance); | ||
|
||
Future<void> react(String postId, String emoji) async { | ||
await client.sendRequest( | ||
HttpMethod.post, | ||
"/api/v1/statuses/$postId/react/$emoji", | ||
); | ||
} | ||
|
||
Future<void> removeReaction(String postId, String emoji) async { | ||
await client.sendRequest( | ||
HttpMethod.post, | ||
"/api/v1/statuses/$postId/unreact/$emoji", | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters