Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented flagMessage using ImJSBackend and dropeed ImSoupRequest b…

…ased implementation.
  • Loading branch information...
commit 66cec6e3ffc5c721b3855b131834605d36172623 1 parent f40939c
@jdapena authored
View
55 data/js/mainView.js
@@ -117,32 +117,32 @@ function abortShowMessages ()
function markMessageAsRead(uid)
{
- iwkRequest ("flagMessage", "Marking message as read", {
- account: globalStatus.currentAccount,
- folder: globalStatus.currentFolder,
- message: uid,
- setFlags: "seen"
- }).done(function (msg) {
+ result = iwk.ServiceMgr.flagMessage(globalStatus.currentAccount,
+ globalStatus.currentFolder,
+ uid,
+ "seen",
+ "");
+ result.onSuccess = function (result) {
$("#message-item-"+uid).removeClass("iwk-unread-item");
$("#message-item-"+uid).addClass("iwk-read-item");
$("#message-view-mark-as-read").hide();
$("#message-view-mark-as-unread").show()
- });
+ };
}
function markMessageAsUnread(uid)
{
- iwkRequest ("flagMessage", "Marking message as unread", {
- account: globalStatus.currentAccount,
- folder: globalStatus.currentFolder,
- message: uid,
- unsetFlags: "seen"
- }).done(function (msg) {
+ result = iwk.ServiceMgr.flagMessage(globalStatus.currentAccount,
+ globalStatus.currentFolder,
+ uid,
+ "",
+ "seen");
+ result.onSuccess = function (result) {
$("#message-item-"+uid).removeClass("iwk-read-item");
$("#message-item-"+uid).addClass("iwk-unread-item");
$("#message-view-mark-as-unread").hide();
$("#message-view-mark-as-read").show();
- });
+ };
}
function markAsRead ()
@@ -157,14 +157,12 @@ function markAsUnread ()
function markMessageAsDeleted(uid)
{
+ result = iwk.ServiceMgr.flagMessage(globalStatus.currentAccount,
+ globalStatus.currentFolder,
+ uid,
+ "deleted",
+ "");
$(".iwk-message-item[data-iwk-message-id='"+uid+"']").hide ();
- iwkRequest ("flagMessage", "Marking message as deleted", {
- account: globalStatus.currentAccount,
- folder: globalStatus.currentFolder,
- message: uid,
- setFlags: "deleted",
- }).done(function (msg) {
- });
}
function deleteMessage ()
@@ -181,17 +179,16 @@ function hasBlockedImages()
function unblockImages ()
{
- iwkRequest ("flagMessage", "Marking message as unblockImages", {
- account: globalStatus.currentAccount,
- folder: globalStatus.currentFolder,
- message: globalStatus.currentMessage,
- setFlags: "unblockImages"
- }).done(function (msg) {
+ result = iwk.ServiceMgr.flagMessage(globalStatus.currentAccount,
+ globalStatus.currentFolder,
+ globalStatus.currentMessage,
+ "unblockImages",
+ "");
+ result.onSuccess = function (result) {
$("#page-message-blocked-images-banner").hide();
clearMessageViewBody ();
fillMessageViewBody (globalStatus.messageStructure);
- });
-
+ };
}
function showMessage(message)
View
1  src/im-error.h
@@ -52,6 +52,7 @@ typedef enum {
IM_ERROR_ACCOUNT_MGR_ADD_ACCOUNT_FAILED,
IM_ERROR_ACCOUNT_MGR_DELETE_ACCOUNT_FAILED,
IM_ERROR_ACCOUNT_MGR_GET_ACCOUNTS_FAILED,
+ IM_ERROR_SERVICE_MGR_FLAG_MESSAGE_FAILED,
IM_ERROR_SETTINGS_INVALID_ACCOUNT_NAME,
IM_ERROR_SETTINGS_INVALID_AUTH_PROTOCOL,
IM_ERROR_SETTINGS_INVALID_CONNECTION_PROTOCOL,
View
114 src/im-js-backend.c
@@ -43,6 +43,8 @@
#include "im-error.h"
#include "im-js-gobject-wrapper.h"
#include "im-js-utils.h"
+#include "im-mail-ops.h"
+#include "im-service-mgr.h"
#include <glib/gi18n.h>
@@ -358,21 +360,133 @@ NULL,
NULL
};
+static void
+flag_message_mail_op_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer userdata)
+{
+ GError *_error = NULL;
+ ImJSCallContext *call_context = (ImJSCallContext *) userdata;
+
+ im_mail_op_flag_message_finish (IM_SERVICE_MGR (object),
+ result, &_error);
+ if (_error)
+ g_propagate_error (&(call_context->error), _error);
+ finish_im_js_call_context (call_context);
+}
+
+static JSValueRef
+im_service_mgr_js_flag_message (JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argument_count,
+ const JSValueRef arguments[],
+ JSValueRef *exception)
+{
+ ImJSCallContext *call_context;
+ GError *_error = NULL;
+ char *account_id, *folder_name, *message_uid;
+ char *set_flags, *unset_flags;
+ JSValueRef _exception = NULL;
+
+ call_context = im_js_call_context_new (context);
+
+ if (argument_count != 5 ||
+ !JSValueIsString (context, arguments[0]) ||
+ !JSValueIsString (context, arguments[1]) ||
+ !JSValueIsString (context, arguments[2]) ||
+ !JSValueIsString (context, arguments[3]) ||
+ !JSValueIsString (context, arguments[4])) {
+ g_set_error (&(call_context->error),
+ IM_ERROR_DOMAIN,
+ IM_ERROR_SERVICE_MGR_FLAG_MESSAGE_FAILED,
+ _("Invalid arguments"));
+ goto finish;
+ }
+
+ if (_exception == NULL)
+ account_id = im_js_value_to_utf8 (context, arguments[0], &_exception);
+ if (_exception == NULL)
+ folder_name = im_js_value_to_utf8 (context, arguments[1], &_exception);
+ if (_exception == NULL)
+ message_uid = im_js_value_to_utf8 (context, arguments[2], &_exception);
+ if (_exception == NULL)
+ set_flags = im_js_value_to_utf8 (context, arguments[3], &_exception);
+ if (_exception == NULL)
+ unset_flags = im_js_value_to_utf8 (context, arguments[4], &_exception);
+
+ if (_error)
+ g_propagate_error (&(call_context->error), _error);
+
+ if (_exception == NULL)
+ im_mail_op_flag_message_async (im_service_mgr_get_instance (),
+ account_id, folder_name, message_uid,
+ set_flags, unset_flags,
+ G_PRIORITY_DEFAULT_IDLE,
+ NULL,
+ flag_message_mail_op_cb,
+ call_context);
+ else
+ finish_im_js_call_context (call_context);
+
+finish:
+ return call_context->result_obj;
+}
+
+
+
+static const JSStaticFunction im_service_mgr_class_staticfuncs[] =
+{
+{ "flagMessage", im_service_mgr_js_flag_message, kJSPropertyAttributeNone },
+{ NULL, NULL, 0 }
+};
+
+static const JSClassDefinition im_service_mgr_class_def =
+{
+0,
+kJSClassAttributeNone,
+"ImServiceMgrClass",
+NULL,
+
+NULL,
+im_service_mgr_class_staticfuncs,
+
+NULL,
+NULL,
+
+NULL,
+NULL,
+NULL,
+NULL,
+NULL,
+NULL,
+NULL,
+NULL,
+NULL
+};
+
static void
im_account_mgr_setup_js_class (JSGlobalContextRef context)
{
JSClassRef account_mgr_class;
JSObjectRef account_mgr_obj;
+ JSClassRef service_mgr_class;
+ JSObjectRef service_mgr_obj;
JSObjectRef iwk_obj;
JSObjectRef global_obj;
account_mgr_class = JSClassCreate (&im_account_mgr_class_def);
account_mgr_obj = JSObjectMake (context, account_mgr_class, NULL);
+ service_mgr_class = JSClassCreate (&im_service_mgr_class_def);
+ service_mgr_obj = JSObjectMake (context, service_mgr_class, NULL);
+
iwk_obj = JSObjectMake (context, NULL, NULL);
im_js_object_set_property_from_value (context, iwk_obj, "AccountMgr",
account_mgr_obj, NULL);
+ im_js_object_set_property_from_value (context, iwk_obj, "ServiceMgr",
+ service_mgr_obj, NULL);
im_js_object_set_property_from_value (context, iwk_obj, "AccountSettings",
(JSValueRef) im_js_gobject_wrapper_init_constructor (im_js_gobject_wrapper_get_instance (),
context,
View
21 src/im-js-utils.c
@@ -53,6 +53,27 @@ im_js_string_to_utf8 (JSStringRef js_string)
return result;
}
+char *
+im_js_value_to_utf8 (JSContextRef context,
+ JSValueRef js_value,
+ JSValueRef *exception)
+{
+ JSStringRef string;
+ JSValueRef _exception = NULL;
+ char *result = NULL;
+
+ string = JSValueToStringCopy (context, js_value, &_exception);
+ if (_exception == NULL) {
+ result = im_js_string_to_utf8 (string);
+ JSStringRelease (string);
+ }
+
+ if (exception)
+ *exception = _exception;
+
+ return result;
+}
+
JSValueRef
im_js_object_get_property (JSContextRef context,
JSObjectRef obj,
View
3  src/im-js-utils.h
@@ -44,6 +44,9 @@
G_BEGIN_DECLS
char * im_js_string_to_utf8 (JSStringRef js_string);
+char * im_js_value_to_utf8 (JSContextRef context,
+ JSValueRef js_string,
+ JSValueRef *exception);
JSValueRef im_js_object_get_property (JSContextRef context,
JSObjectRef obj,
View
54 src/im-soup-request.c
@@ -1057,58 +1057,6 @@ get_message (GAsyncResult *result, GHashTable *params, GCancellable *cancellable
data);
}
-typedef struct _FlagMessageData {
- GAsyncResult *result;
- gchar *callback_id;
-} FlagMessageData;
-
-static void
-flag_message_mail_op_cb (GObject *object,
- GAsyncResult *result,
- gpointer userdata)
-{
- GError *_error = NULL;
- FlagMessageData *data = (FlagMessageData *) userdata;
-
- im_mail_op_flag_message_finish (IM_SERVICE_MGR (object),
- result, &_error);
- response_finish (data->result, data->callback_id, NULL, _error);
- if (_error) g_error_free (_error);
- g_object_unref (data->result);
- g_free (data->callback_id);
- g_free (data);
-}
-
-static void
-flag_message (GAsyncResult *result, GHashTable *params, GCancellable *cancellable)
-{
- const gchar *account_id;
- const gchar *folder_name;
- const gchar *message_uid;
- const gchar *set_flags, *unset_flags;
- FlagMessageData *data = g_new0 (FlagMessageData, 1);
-
- data->result = g_object_ref (result);
- data->callback_id = g_strdup (g_hash_table_lookup (params, "callback"));
-
- account_id = g_hash_table_lookup (params, "account");
- folder_name = g_hash_table_lookup (params, "folder");
- message_uid = g_hash_table_lookup (params, "message");
- set_flags = g_strdup (g_hash_table_lookup (params, "setFlags"));
- unset_flags = g_strdup (g_hash_table_lookup (params, "unsetFlags"));
-
- im_mail_op_flag_message_async (im_service_mgr_get_instance (),
- account_id,
- folder_name,
- message_uid,
- set_flags,
- unset_flags,
- G_PRIORITY_DEFAULT_IDLE,
- cancellable,
- flag_message_mail_op_cb,
- data);
-}
-
typedef struct _ComposerSaveData {
GAsyncResult *result;
gchar *callback_id;
@@ -1384,8 +1332,6 @@ im_soup_request_send_async (SoupRequest *soup_request,
composer_save (result, params, TRUE, cancellable);
} else if (!g_strcmp0 (uri->path, "composerSaveDraft")) {
composer_save (result, params, FALSE, cancellable);
- } else if (!g_strcmp0 (uri->path, "flagMessage")) {
- flag_message (result, params, cancellable);
} else if (!g_strcmp0 (uri->path, "openFileURI")) {
open_file_uri (result, params);
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.