Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 9d7b462

Browse files
committed
Subscribe only after account information was received.
1 parent 0243601 commit 9d7b462

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

libsignald.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ signald_handle_input(SignaldAccount *sa, const char * json)
160160
} else if (purple_strequal(type, "contact_list")) {
161161
signald_parse_contact_list(sa, json_object_get_array_member(obj, "data"));
162162

163-
if (! sa->initialized) {
163+
if (! sa->groups_updated) {
164164
signald_request_group_list(sa);
165165
}
166166

@@ -169,8 +169,8 @@ signald_handle_input(SignaldAccount *sa, const char * json)
169169
signald_parse_group_list(sa, json_object_get_array_member(obj, "groups"));
170170
signald_parse_groupV2_list(sa, json_object_get_array_member(obj, "groupsv2"));
171171

172-
if (! sa->initialized) {
173-
sa->initialized = TRUE;
172+
if (! sa->groups_updated) {
173+
sa->groups_updated = TRUE;
174174
}
175175

176176
} else if (purple_strequal(type, "message")) {
@@ -425,11 +425,6 @@ signald_login(PurpleAccount *account)
425425
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Could not write list account message."));
426426
}
427427
json_object_unref(data);
428-
429-
if (!purple_account_get_bool(sa->account, "handle_signald", FALSE)) {
430-
// subscribe if signald is globally running
431-
signald_subscribe(sa);
432-
}
433428
}
434429

435430
static void

libsignald.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ typedef struct {
6060
PurpleConnection *pc;
6161
char *uuid; // own uuid, might be NULL – always check before use
6262

63-
gboolean initialized;
63+
gboolean account_exists; // whether account exists in signald
64+
gboolean groups_updated; // whether groups have been updated after login
6465

6566
int fd;
6667
guint watcher;

link.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ signald_verify_ok_cb (SignaldAccount *sa, const char* input)
108108

109109
// TODO: Is there an acknowledge on successful registration? If yes,
110110
// subscribe afterwards or display an error otherwise
111-
signald_subscribe(sa);
111+
// signald_subscribe(sa);
112+
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Verification code was sent. Reconnect needed."));
112113
}
113114

114115
void
@@ -129,7 +130,6 @@ signald_link_or_register (SignaldAccount *sa)
129130
JsonObject *data = json_object_new();
130131
json_object_set_string_member(data, "type", "link");
131132
if (!signald_send_json(sa, data)) {
132-
//purple_connection_set_state(pc, PURPLE_DISCONNECTED);
133133
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Could not write link message."));
134134
}
135135
} else {
@@ -140,7 +140,6 @@ signald_link_or_register (SignaldAccount *sa)
140140
json_object_set_string_member(data, "type", "register");
141141
json_object_set_string_member(data, "username", username);
142142
if (!signald_send_json(sa, data)) {
143-
//purple_connection_set_state(pc, PURPLE_DISCONNECTED);
144143
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Could not write registration message."));
145144
}
146145

@@ -166,6 +165,7 @@ signald_process_account(JsonArray *array, guint index_, JsonNode *element_node,
166165
const char *username = json_object_get_string_member(obj, "username");
167166
if (purple_strequal (username, purple_account_get_username(sa->account))) {
168167
// The current account
168+
sa->account_exists = TRUE;
169169
gboolean registered = json_object_get_boolean_member (obj, "registered");
170170
purple_debug_info(SIGNALD_PLUGIN_ID, "Account %s registered: %d\n", username, registered);
171171
if (registered) {
@@ -181,5 +181,9 @@ signald_process_account(JsonArray *array, guint index_, JsonNode *element_node,
181181
void
182182
signald_parse_account_list(SignaldAccount *sa, JsonArray *data)
183183
{
184+
sa->account_exists = FALSE;
184185
json_array_foreach_element(data, signald_process_account, sa);
186+
if (!sa->account_exists) {
187+
signald_link_or_register(sa);
188+
}
185189
}

0 commit comments

Comments
 (0)