Compare commits

...

2 Commits

Author SHA1 Message Date
Artem Savkov 69e16be9d1 Call imcb_connected only after we parsed the whole READY message
Do not call imcb_connceted prematurely as it breaks group dms for
instance.

Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
2020-02-07 23:23:45 +01:00
Artem Savkov 3a300cd417 Sync private groups as well
Turns out opcode 13 is responsible for syncing private group DMs. Ask
for that on join. Don't have any way to check it currently, just hoping
it will return a familiar message.
2020-02-07 21:59:25 +01:00
4 changed files with 15 additions and 4 deletions

View File

@ -901,9 +901,6 @@ gboolean discord_parse_message(struct im_connection *ic, gchar *buf, guint64 siz
}
}
dd->state = WS_READY;
imcb_connected(ic);
json_value *pcs = json_o_get(data, "private_channels");
if (pcs != NULL && pcs->type == json_array) {
for (int pcidx = 0; pcidx < pcs->u.array.length; pcidx++) {
@ -946,6 +943,9 @@ gboolean discord_parse_message(struct im_connection *ic, gchar *buf, guint64 siz
}
}
dd->state = WS_READY;
imcb_connected(ic);
} else if (g_strcmp0(event, "GUILD_SYNC") == 0) {
json_value *data = json_o_get(js, "d");
const char *id = json_o_str(data, "id");

View File

@ -108,6 +108,15 @@ void discord_ws_sync_channel(discord_data *dd, const char *guild_id,
g_string_free(buf, TRUE);
}
void discord_ws_sync_private_group(discord_data *dd, const char *channel_id)
{
GString *buf = g_string_new("");
g_string_printf(buf, "{\"op\":%d,\"d\":{\"channel_id\":\"%s\"}}",
OPCODE_REQUEST_SYNC_PRIVATE_GROUP, channel_id);
discord_ws_send_payload(dd, buf->str, buf->len);
g_string_free(buf, TRUE);
}
static gboolean discord_ws_heartbeat_timeout(gpointer data, gint fd,
b_input_condition cond)
{

View File

@ -30,7 +30,7 @@ typedef enum {
OPCODE_HELLO,
OPCODE_HEARTBEAT_ACK,
OPCODE_REQUEST_SYNC,
OPCODE_UNKNOWN,
OPCODE_REQUEST_SYNC_PRIVATE_GROUP,
OPCODE_REQUEST_SYNC_CHANNEL
} discord_opcode;
@ -44,3 +44,4 @@ void discord_ws_set_status(struct im_connection *ic, gchar *status,
void discord_ws_sync_server(discord_data *dd, const char *id);
void discord_ws_sync_channel(discord_data *dd, const char *guild_id,
const char *channel_id, unsigned int members);
void discord_ws_sync_private_group(discord_data *dd, const char *channel_id);

View File

@ -217,6 +217,7 @@ struct groupchat *discord_chat_do_join(struct im_connection *ic,
} else if (cinfo != NULL && cinfo->type == CHANNEL_GROUP_PRIVATE) {
gc = imcb_chat_new(ic, cinfo->to.group.name);
discord_ws_sync_private_group(dd, cinfo->id);
if (is_auto_join) {
imcb_chat_name_hint(gc, room);
}