kensanata / bitlbee-mastodon

A Mastodon plugin for Bitlbee
https://alexschroeder.ch/software/Bitlbee_Mastodon
GNU General Public License v2.0
30 stars 7 forks source link

Slower login #21

Open kensanata opened 6 years ago

kensanata commented 6 years ago

Perhaps we are pipelining the requests too quickly on login. So I figured we could move the code that depends on a successful login (and getting the account id) into the handler for the very first request, mastodon_verify_credentials. But now I'm getting segmentation faults. Any ideas?

diff --git a/src/mastodon-lib.c b/src/mastodon-lib.c
index a28eca6..fe61ba8 100644
--- a/src/mastodon-lib.c
+++ b/src/mastodon-lib.c
@@ -2562,6 +2562,17 @@ static void mastodon_http_verify_credentials(struct http_request *req)

        json_value_free(parsed);
    }
+
+   // Now that we have verified that the login worked, let's add our buddies (if we are in a group chat).
+   struct mastodon_data *md = ic->proto_data;
+   if (!(md->flags & MASTODON_MODE_ONE) &&
+       !(md->flags & MASTODON_HAVE_FRIENDS)) {
+       mastodon_following(ic);
+   }
+
+   // And fill our timeline with some toots. And connect to the streams.
+   mastodon_initial_timeline(ic);
+   mastodon_open_user_stream(ic);
 }

 /**
diff --git a/src/mastodon-lib.h b/src/mastodon-lib.h
index 3a71bb1..747b979 100644
--- a/src/mastodon-lib.h
+++ b/src/mastodon-lib.h
@@ -80,12 +80,9 @@ typedef enum {

 void mastodon_register_app(struct im_connection *ic);
 void mastodon_verify_credentials(struct im_connection *ic);
-void mastodon_following(struct im_connection *ic);
-void mastodon_initial_timeline(struct im_connection *ic);
 void mastodon_hashtag_timeline(struct im_connection *ic, char *hashtag);
 void mastodon_local_timeline(struct im_connection *ic);
 void mastodon_federated_timeline(struct im_connection *ic);
-void mastodon_open_user_stream(struct im_connection *ic);
 struct http_request *mastodon_open_hashtag_stream(struct im_connection *ic, char *hashtag);
 struct http_request *mastodon_open_local_stream(struct im_connection *ic);
 struct http_request *mastodon_open_federated_stream(struct im_connection *ic);
diff --git a/src/mastodon.c b/src/mastodon.c
index 4dd4f5c..72601b3 100644
--- a/src/mastodon.c
+++ b/src/mastodon.c
@@ -320,21 +320,14 @@ static void mastodon_connect(struct im_connection *ic)
        md->flags |= MASTODON_MODE_CHAT;
    }

-   if (!(md->flags & MASTODON_MODE_ONE) &&
-       !(md->flags & MASTODON_HAVE_FRIENDS)) {
-       // find our id
-       mastodon_verify_credentials(ic);
-       // add buddies for this id
-       mastodon_following(ic);
-   }
-
    /* Create the room. */
    if (md->flags & MASTODON_MODE_CHAT) {
        mastodon_groupchat_init(ic);
    }

-   mastodon_initial_timeline(ic);
-   mastodon_open_user_stream(ic);
+   /* find our id and finish login */
+   mastodon_verify_credentials(ic);
+
    ic->flags |= OPT_PONGS;
 }