Skip to content

Commit

Permalink
Display server-side errors (if any) when sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
EionRobb committed Dec 14, 2016
1 parent 92c376f commit 00f102c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
25 changes: 24 additions & 1 deletion skypeweb/skypeweb_messages.c
Expand Up @@ -1205,6 +1205,29 @@ skypeweb_set_idle(PurpleConnection *pc, int time)
}


static void
skypeweb_sent_message_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
gchar *convname = user_data;
JsonObject *obj = NULL;

if (node != NULL && json_node_get_node_type(node) == JSON_NODE_OBJECT)
obj = json_node_get_object(node);

if (obj != NULL) {
if (json_object_has_member(obj, "errorCode")) {
PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, convname, sa->account);
if (conv == NULL) {
purple_conv_present_error(skypeweb_strip_user_prefix(convname), sa->account, json_object_get_string_member(obj, "message"));
} else {
purple_conversation_write(conv, NULL, json_object_get_string_member(obj, "message"), PURPLE_MESSAGE_ERROR, time(NULL));
}
}
}

g_free(convname);
}

static void
skypeweb_send_message(SkypeWebAccount *sa, const gchar *convname, const gchar *message)
{
Expand Down Expand Up @@ -1238,7 +1261,7 @@ skypeweb_send_message(SkypeWebAccount *sa, const gchar *convname, const gchar *m

post = skypeweb_jsonobj_to_string(obj);

skypeweb_post_or_get(sa, SKYPEWEB_METHOD_POST | SKYPEWEB_METHOD_SSL, sa->messages_host, url, post, NULL, NULL, TRUE);
skypeweb_post_or_get(sa, SKYPEWEB_METHOD_POST | SKYPEWEB_METHOD_SSL, sa->messages_host, url, post, skypeweb_sent_message_cb, g_strdup(convname), TRUE);

g_free(post);
json_object_unref(obj);
Expand Down
12 changes: 12 additions & 0 deletions skypeweb/skypeweb_util.c
Expand Up @@ -404,3 +404,15 @@ skypeweb_user_url_prefix(const gchar *who)
return "8:";
}
}

const gchar *
skypeweb_strip_user_prefix(const gchar *who)
{
if (who[1] == ':') {
if (who[0] != '2') {
return who + 2;
}
}

return who;
}
1 change: 1 addition & 0 deletions skypeweb/skypeweb_util.h
Expand Up @@ -40,3 +40,4 @@ skypeweb_fetch_url_request(SkypeWebAccount *sa,
void skypeweb_url_prevent_follow_redirects(PurpleUtilFetchUrlData *requestdata);

const gchar *skypeweb_user_url_prefix(const gchar *who);
const gchar *skypeweb_strip_user_prefix(const gchar *who);

0 comments on commit 00f102c

Please sign in to comment.