Skip to content

Commit

Permalink
Merge pull request #126 from edmcman/master
Browse files Browse the repository at this point in the history
A fix for auto-join channels in bitlbee. Waits to set the as CONNECTED until the list of channels is received for every team.
  • Loading branch information
EionRobb authored Jan 22, 2020
2 parents e046629 + 1a65510 commit 158ce20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 21 additions & 6 deletions libmattermost.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ mm_find_channel_approximate_view_time(MattermostAccount *ma, const gchar *id)
return now;
}

gboolean
mm_idle_updater_timeout(gpointer data);

void
mm_set_status(PurpleAccount *account, PurpleStatus *status);

static void
mm_add_channels_to_blist(MattermostAccount *ma, JsonNode *node, gpointer user_data)
Expand Down Expand Up @@ -666,6 +671,17 @@ mm_add_channels_to_blist(MattermostAccount *ma, JsonNode *node, gpointer user_da

mm_get_users_by_ids(ma,mm_users);

// Is this the last team we are waiting to receive channels
// for? If so mark the connection as connected.
ma->groupchat_team_count --;
if (ma->groupchat_team_count == 0) {
purple_connection_set_state(ma->pc, PURPLE_CONNECTION_CONNECTED);

mm_set_status(ma->account, purple_presence_get_active_status(purple_account_get_presence(ma->account)));
ma->idle_timeout = g_timeout_add_seconds(270, mm_idle_updater_timeout, ma->pc);
}


}

static void
Expand Down Expand Up @@ -814,6 +830,9 @@ mm_got_teams(MattermostAccount *ma, JsonNode *node, gpointer user_data)
JsonArray *teams = json_node_get_array(node);
guint i, len = json_array_get_length(teams);

// Set the counter so we know how many teams to wait for
// before marking the connection as connected.
ma->groupchat_team_count = len;
for (i = 0; i < len; i++) {
JsonObject *team = json_array_get_object_element(teams, i);

Expand All @@ -824,13 +843,9 @@ mm_got_teams(MattermostAccount *ma, JsonNode *node, gpointer user_data)
g_hash_table_replace(ma->teams, g_strdup(team_id), g_strdup(name));
g_hash_table_replace(ma->teams_display_names, g_strdup(team_id), g_strdup(display_name));

mm_get_commands_for_team(ma, team_id);
mm_get_open_channels_for_team(ma, team_id);
mm_get_commands_for_team(ma, team_id);
mm_get_open_channels_for_team(ma, team_id);
}
purple_connection_set_state(ma->pc, PURPLE_CONNECTION_CONNECTED);

mm_set_status(ma->account, purple_presence_get_active_status(purple_account_get_presence(ma->account)));
ma->idle_timeout = g_timeout_add_seconds(270, mm_idle_updater_timeout, ma->pc);
}


Expand Down
2 changes: 2 additions & 0 deletions libmattermost.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ typedef struct {

gint seq; //incrementing counter
gint roomlist_team_count;
gint groupchat_team_count; // ejs: I wasn't sure if we could safely
// reuse roomlist_team_count here

GHashTable *one_to_ones; // A store of known room_id's -> username's
GHashTable *one_to_ones_rev; // A store of known usernames's -> room_id's
Expand Down

0 comments on commit 158ce20

Please sign in to comment.