From 6d22c44eb6e4acd3db4be33062be2c0db38ba914 Mon Sep 17 00:00:00 2001
From: Marta Sokolska <marta@pionaiki.com>
Date: Tue, 26 Nov 2024 19:56:07 +0100
Subject: [PATCH 1/2] added support for akkoma

---
 src/fetcher.rs | 25 +++++++++++++++++++++++++
 src/misc.rs    |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/src/fetcher.rs b/src/fetcher.rs
index d07a18c..cd201ab 100644
--- a/src/fetcher.rs
+++ b/src/fetcher.rs
@@ -114,6 +114,7 @@ impl EmojiFetcher {
                 self.needs_interactive("logging into gotosocial", self.try_fetch_gts())
                     .await
             }
+            FediSoftware::Akkoma => self.try_fetch_akkoma().await,
             FediSoftware::Other(other) => {
                 error!("unsupported fedi software: `{other}`");
                 Ok(())
@@ -166,11 +167,35 @@ impl EmojiFetcher {
         Ok(())
     }
 
+    async fn try_fetch_akkoma(&self) -> Result<()> {
+        info!("trying to fetch emojis from akkoma");
+        info!("trying without authentication");
+        let unauth_res = self.do_fetch(|rb| rb).await;
+        if unauth_res.is_ok() {
+            info!("successfully fetched from akkoma without authentication");
+            return Ok(());
+        }
+        info!("seems like authentication is needed; asking necessary info");
+        let access_token = self
+            .needs_interactive(
+                "logging into akkoma",
+                mastodon::auth_interactive(&self.client),
+            )
+            .await?;
+
+        mastodon::verify_login(&self.client, &access_token).await?;
+
+        self.do_fetch(|rb| rb.bearer_auth(&access_token)).await?;
+
+        mastodon::invalidate_token(&self.client, &access_token).await
+    }
+
     async fn ask_target_and_try_fetch(&self) -> Result<()> {
         info!("Could not auto-detect which software the instance uses.");
         let options = vec![
             FediSoftware::Mastodon,
             FediSoftware::Gotosocial,
+            FediSoftware::Akkoma,
             FediSoftware::Other("".into()),
         ];
         let answer = inquire::Select::new("Please select the instance software:", options)
diff --git a/src/misc.rs b/src/misc.rs
index 1feb38c..cea2eb1 100644
--- a/src/misc.rs
+++ b/src/misc.rs
@@ -7,6 +7,7 @@ use serde::Deserialize;
 pub enum FediSoftware {
     Mastodon,
     Gotosocial,
+    Akkoma,
     Other(String),
     #[default]
     Unknown,
@@ -20,6 +21,7 @@ where
         match value.as_ref() {
             "mastodon" => FediSoftware::Mastodon,
             "gotosocial" => FediSoftware::Gotosocial,
+            "akkoma" => FediSoftware::Akkoma,
             "" => FediSoftware::Unknown,
             other => FediSoftware::Other(other.to_owned()),
         }
@@ -31,6 +33,7 @@ impl Display for FediSoftware {
         match self {
             FediSoftware::Mastodon => write!(f, "Mastodon"),
             FediSoftware::Gotosocial => write!(f, "Gotosocial"),
+            FediSoftware::Akkoma => write!(f, "Akkoma"), 
             FediSoftware::Other(_) => write!(f, "Other Software"),
             FediSoftware::Unknown => write!(f, "Unknown Software"),
         }
-- 
2.30.2


From 1f89393c73271d33a91c2ab8f243ed02d4d68b03 Mon Sep 17 00:00:00 2001
From: Marta Sokolska <marta@pionaiki.com>
Date: Tue, 26 Nov 2024 20:05:52 +0100
Subject: [PATCH 2/2] version bump

---
 Cargo.lock | 2 +-
 Cargo.toml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 6c71750..947dfd0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -322,7 +322,7 @@ dependencies = [
 
 [[package]]
 name = "fedi_emoji_downloader"
-version = "0.1.2"
+version = "0.1.3"
 dependencies = [
  "chrono",
  "clap",
diff --git a/Cargo.toml b/Cargo.toml
index 47b59c7..26ab7f4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "fedi_emoji_downloader"
-version = "0.1.2"
+version = "0.1.3"
 edition = "2021"
 
 [dependencies]
-- 
2.30.2