Skip to content

Commit

Permalink
Getting the initial files in place
Browse files Browse the repository at this point in the history
Right now we still connect to the old streaming URLs so you definitely
cannot connect to Pleroma instances. Also, Pleroma doesn't handle our
OAuth scopes (we're getting an unsupported_grant_type error).

Current status: one websocket connects to your home stream and logs
what it sees, and sends back PONG frames when it sees PING frames,
thus avoiding a disconnect.
  • Loading branch information
kensanata committed Dec 6, 2019
1 parent c575665 commit 030d1ae
Show file tree
Hide file tree
Showing 8 changed files with 654 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ mastodon_la_SOURCES = \
mastodon-http.h \
mastodon-lib.c \
mastodon-lib.h \
mastodon-websockets.c \
mastodon-websockets.h \
rot13.c \
rot13.h
10 changes: 1 addition & 9 deletions src/mastodon-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
#include <ctype.h>
#include <errno.h>

typedef enum {
MT_HOME,
MT_LOCAL,
MT_FEDERATED,
MT_HASHTAG,
MT_LIST,
} mastodon_timeline_type_t;

typedef enum {
ML_STATUS,
ML_NOTIFICATION,
Expand Down Expand Up @@ -1322,7 +1314,7 @@ static void mastodon_stream_handle_delete(struct im_connection *ic, json_value *
}
}

static void mastodon_stream_handle_event(struct im_connection *ic, mastodon_evt_flags_t evt_type,
void mastodon_stream_handle_event(struct im_connection *ic, mastodon_evt_flags_t evt_type,
json_value *parsed, mastodon_timeline_type_t subscription)
{
if (evt_type == MASTODON_EVT_UPDATE) {
Expand Down
27 changes: 20 additions & 7 deletions src/mastodon-lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,36 @@

#include "nogaim.h"
#include "mastodon-http.h"
#include "json.h"

#define MASTODON_DEFAULT_INSTANCE "https://octodon.social"

// "2017-08-02T10:45:03.000Z" -- but we're ignoring microseconds and UTC timezone
#define MASTODON_TIME_FORMAT "%Y-%m-%dT%H:%M:%S"

#define MASTODON_API(version) "/api/v" #version
#define MASTODON_REGISTER_APP_URL MASTODON_API(1) "/apps"
#define MASTODON_VERIFY_CREDENTIALS_URL MASTODON_API(1) "/accounts/verify_credentials"
#define MASTODON_STREAMING_USER_URL MASTODON_API(1) "/streaming/user"
#define MASTODON_STREAMING_HASHTAG_URL MASTODON_API(1) "/streaming/hashtag"
#define MASTODON_STREAMING_LOCAL_URL MASTODON_API(1) "/streaming/public/local"
#define MASTODON_STREAMING_FEDERATED_URL MASTODON_API(1) "/streaming/public"
#define MASTODON_STREAMING_LIST_URL MASTODON_API(1) "/streaming/list"
#define MASTODON_REGISTER_APP_URL MASTODON_API(1) "/apps"
#define MASTODON_VERIFY_CREDENTIALS_URL MASTODON_API(1) "/accounts/verify_credentials"
#define MASTODON_HOME_TIMELINE_URL MASTODON_API(1) "/timelines/home"
#define MASTODON_PUBLIC_TIMELINE_URL MASTODON_API(1) "/timelines/public"
#define MASTODON_HASHTAG_TIMELINE_URL MASTODON_API(1) "/timelines/tag/%s"
#define MASTODON_LIST_TIMELINE_URL MASTODON_API(1) "/timelines/list/%" G_GINT64_FORMAT
#define MASTODON_NOTIFICATIONS_URL MASTODON_API(1) "/notifications"

/* Streaming URLs */
#define MASTODON_STREAMING_USER_URL MASTODON_API(1) "/streaming/user"
#define MASTODON_STREAMING_HASHTAG_URL MASTODON_API(1) "/streaming/hashtag"
#define MASTODON_STREAMING_LOCAL_URL MASTODON_API(1) "/streaming/public/local"
#define MASTODON_STREAMING_FEDERATED_URL MASTODON_API(1) "/streaming/public"
#define MASTODON_STREAMING_LIST_URL MASTODON_API(1) "/streaming/list"

/* Websocket URLs */
#define MASTODON_WEBSOCKET_USER_URL MASTODON_API(1) "/streaming?stream=user"
#define MASTODON_WEBSOCKET_HASHTAG_URL MASTODON_API(1) "/streaming?stream=hashtag&tag=%s"
#define MASTODON_WEBSOCKET_LOCAL_URL MASTODON_API(1) "/streaming?stream=public:local"
#define MASTODON_WEBSOCKET_FEDERATED_URL MASTODON_API(1) "/streaming?stream=public"
#define MASTODON_WEBSOCKET_LIST_URL MASTODON_API(1) "/streaming?stream=list&list=%s"

#define MASTODON_REPORT_URL MASTODON_API(1) "/reports"
#define MASTODON_SEARCH_URL MASTODON_API(2) "/search"

Expand Down Expand Up @@ -148,3 +158,6 @@ void mastodon_filters_destroy(struct mastodon_data *md);
void mastodon_filters(struct im_connection *ic);
void mastodon_filter_create(struct im_connection *ic, char *str);
void mastodon_filter_delete(struct im_connection *ic, char *arg);

void mastodon_stream_handle_event(struct im_connection *ic, mastodon_evt_flags_t evt_type,
json_value *parsed, mastodon_timeline_type_t subscription);
Loading

0 comments on commit 030d1ae

Please sign in to comment.