]> www.infradead.org Git - pidgin-chime.git/commitdiff
Start supporting join by PIN
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 28 Aug 2017 17:57:55 +0000 (18:57 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 28 Aug 2017 17:57:55 +0000 (18:57 +0100)
We don't actually implement "join" yet, so we're only really adding
it to the list of joinable meetings. Joining them comes next...

chime-meeting.c
chime-meeting.h
chime.c
chime.h
meeting.c

index 2caa57ef8d8cf423651bcd375cd6781c381e4ce3..d571ab7eca826bb75a7833d81a743b58fcaeb798 100644 (file)
@@ -61,7 +61,7 @@ G_DEFINE_TYPE(ChimeMeeting, chime_meeting, CHIME_TYPE_OBJECT)
 CHIME_DEFINE_ENUM_TYPE(ChimeMeetingType, chime_meeting_type,                           \
        CHIME_ENUM_VALUE(CHIME_MEETING_TYPE_ADHOC,              "AdHocMeeting")         \
        CHIME_ENUM_VALUE(CHIME_MEETING_TYPE_GOOGLE_CALENDAR,    "GoogleCalendarMeeting")\
-       CHIME_ENUM_VALUE(CHIME_MEETING_TYPE_CONFERENCE_BRIDGE,  "ConferenceBridge")     \
+       CHIME_ENUM_VALUE(CHIME_MEETING_TYPE_CONFERENCE_BRIDGE,  "ConferenceBridgeMeeting") \
        CHIME_ENUM_VALUE(CHIME_MEETING_TYPE_WEBINAR,            "Webinar"))
 
 static void close_meeting(gpointer key, gpointer val, gpointer data);
@@ -456,7 +456,7 @@ void chime_init_meetings(ChimeConnection *cxn)
                             meeting_jugg_cb, NULL);
        chime_jugg_subscribe(cxn, priv->device_channel, "AdHocMeeting",
                             meeting_jugg_cb, NULL);
-       chime_jugg_subscribe(cxn, priv->device_channel, "ConferenceBridge",
+       chime_jugg_subscribe(cxn, priv->device_channel, "ConferenceBridgeMeeting",
                             meeting_jugg_cb, NULL);
        chime_jugg_subscribe(cxn, priv->device_channel, "Webinar",
                             meeting_jugg_cb, NULL);
@@ -473,7 +473,7 @@ void chime_destroy_meetings(ChimeConnection *cxn)
                             meeting_jugg_cb, NULL);
        chime_jugg_unsubscribe(cxn, priv->device_channel, "AdHocMeeting",
                             meeting_jugg_cb, NULL);
-       chime_jugg_unsubscribe(cxn, priv->device_channel, "ConferenceBridge",
+       chime_jugg_unsubscribe(cxn, priv->device_channel, "ConferenceBridgeMeeting",
                             meeting_jugg_cb, NULL);
        chime_jugg_unsubscribe(cxn, priv->device_channel, "Webinar",
                             meeting_jugg_cb, NULL);
@@ -674,3 +674,72 @@ ChimeScheduledMeeting *chime_connection_meeting_schedule_info_finish(ChimeConnec
        return g_task_propagate_pointer(G_TASK(result), error);
 }
 
+static void pin_join_cb(ChimeConnection *cxn, SoupMessage *msg,
+                       JsonNode *node, gpointer user_data)
+{
+       GTask *task = G_TASK(user_data);
+
+       if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code) && node) {
+               GError *error = NULL;
+               JsonObject *obj = json_node_get_object(node);
+               node = json_object_get_member(obj, "meeting");
+               if (!node)
+                       goto eparse;
+
+               ChimeMeeting *mtg = chime_connection_parse_meeting(cxn, node, &error);
+               if (mtg)
+                       g_task_return_pointer(task, mtg, (GDestroyNotify)g_object_unref);
+               else
+                       g_task_return_error(task, error);
+               return;
+       } else {
+               const gchar *reason;
+       eparse:
+               reason = msg->reason_phrase;
+
+               if (node)
+                       parse_string(node, "Message", &reason);
+
+               g_task_return_new_error(task, CHIME_ERROR,
+                                       CHIME_ERROR_NETWORK,
+                                       _("Failed to obtain meeting details: %s"),
+                                       reason);
+       }
+
+       g_object_unref(task);
+}
+
+void chime_connection_lookup_meeting_by_pin_async(ChimeConnection *cxn,
+                                                 const gchar *pin,
+                                                 GCancellable *cancellable,
+                                                 GAsyncReadyCallback callback,
+                                                 gpointer user_data)
+{
+       g_return_if_fail(CHIME_IS_CONNECTION(cxn));
+       ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
+
+       GTask *task = g_task_new(cxn, cancellable, callback, user_data);
+
+       JsonBuilder *jb = json_builder_new();
+       jb = json_builder_begin_object(jb);
+       jb = json_builder_set_member_name(jb, "pin");
+       jb = json_builder_add_string_value(jb, pin);
+       jb = json_builder_end_object(jb);
+
+       JsonNode *node = json_builder_get_root(jb);
+       SoupURI *uri = soup_uri_new_printf(priv->conference_url, "/pin_joins");
+       chime_connection_queue_http_request(cxn, node, uri, "POST", pin_join_cb, task);
+       json_node_unref(node);
+       g_object_unref(jb);
+
+}
+
+ChimeMeeting *chime_connection_lookup_meeting_by_pin_finish(ChimeConnection *self,
+                                                           GAsyncResult *result,
+                                                           GError **error)
+{
+       g_return_val_if_fail(CHIME_IS_CONNECTION(self), FALSE);
+       g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
+
+       return g_task_propagate_pointer(G_TASK(result), error);
+}
index f298e842d99e67115ead20844e67cc6a1adb2fdb..b48841a464413b4d21d0b38b7c2da0399ef62596 100644 (file)
@@ -114,6 +114,17 @@ ChimeScheduledMeeting *chime_connection_meeting_schedule_info_finish(ChimeConnec
                                                                     GError **error);
 
 
+void chime_connection_lookup_meeting_by_pin_async(ChimeConnection *cxn,
+                                                 const gchar *pin,
+                                                 GCancellable *cancellable,
+                                                 GAsyncReadyCallback callback,
+                                                 gpointer user_data);
+
+ChimeMeeting *chime_connection_lookup_meeting_by_pin_finish(ChimeConnection *self,
+                                                           GAsyncResult *result,
+                                                           GError **error);
+
+
 G_END_DECLS
 
 #endif /* __CHIME_MEETING_H__ */
diff --git a/chime.c b/chime.c
index bfce67ca4466fbc3dcce772fce77b902a704dfb5..c1ecb6e5370859d283a7a0fef6549822cc458c04 100644 (file)
--- a/chime.c
+++ b/chime.c
@@ -198,6 +198,7 @@ static void chime_purple_login(PurpleAccount *account)
        purple_connection_set_protocol_data(conn, pc);
        purple_chime_init_conversations(pc);
        purple_chime_init_chats(pc);
+
        pc->cxn = chime_connection_new(conn, server, devtoken, token);
 
        g_signal_connect(pc->cxn, "notify::session-token",
@@ -210,6 +211,8 @@ static void chime_purple_login(PurpleAccount *account)
                         G_CALLBACK(on_chime_progress), conn);
        g_signal_connect(pc->cxn, "new-conversation",
                         G_CALLBACK(on_chime_new_conversation), conn);
+       g_signal_connect(pc->cxn, "new-meeting",
+                        G_CALLBACK(on_chime_new_meeting), conn);
        /* We don't use 'conn' for this one as we don't want it disconnected
           on close, and it doesn't use it anyway. */
        g_signal_connect(pc->cxn, "log-message",
@@ -346,6 +349,10 @@ static GList *chime_purple_plugin_actions(PurplePlugin *plugin,
                                       chime_purple_schedule_onetime);
        acts = g_list_append(acts, act);
 
+       act = purple_plugin_action_new(_("Join meeting by PIN..."),
+                                      chime_purple_pin_join);
+       acts = g_list_append(acts, act);
+
        return acts;
 }
 
diff --git a/chime.h b/chime.h
index 2834c4f5dc09662d9bc9f634ce0efd75b0d9e078..0e30bc1728b9988132ad0087b2a37c30b8cc1219 100644 (file)
--- a/chime.h
+++ b/chime.h
@@ -27,6 +27,7 @@
 #include "chime-contact.h"
 #include "chime-conversation.h"
 #include "chime-room.h"
+#include "chime-meeting.h"
 
 struct purple_chime {
        ChimeConnection *cxn;
@@ -59,6 +60,8 @@ void chime_purple_user_search(PurplePluginAction *action);
 /* meeting.c */
 void chime_purple_schedule_onetime(PurplePluginAction *action);
 void chime_purple_schedule_personal(PurplePluginAction *action);
+void chime_purple_pin_join(PurplePluginAction *action);
+void on_chime_new_meeting(ChimeConnection *cxn, ChimeMeeting *mtg, PurpleConnection *conn);
 
 /* rooms.c */
 PurpleRoomlist *chime_purple_roomlist_get_list(PurpleConnection *conn);
index 38e18102aef95e0ad21a7260de903186547485da..a4d2828d33c920b19a88e00c7f83d2c3aa37871c 100644 (file)
--- a/meeting.c
+++ b/meeting.c
@@ -19,6 +19,7 @@
 #include <glib/glist.h>
 
 #include <prpl.h>
+#include <request.h>
 
 #include "chime.h"
 #include "chime-meeting.h"
@@ -37,9 +38,6 @@ static void schedule_meeting_cb(GObject *source, GAsyncResult *result, gpointer
                return;
        }
 
-       /* XXX: Choose the best one (not that chime does) */
-       ChimeDialin *d = mtg->international_dialin_info->data;
-
        gchar *secondary = g_strdup_printf(_("Remember to include Chime in the invites:\n%s"), mtg->delegate_scheduling_email);
        GString *invite_str = g_string_new("");
 
@@ -109,5 +107,55 @@ void chime_purple_schedule_onetime(PurplePluginAction *action)
 void chime_purple_schedule_personal(PurplePluginAction *action)
 {
        do_schedule_meeting(action, FALSE);
+}
+
+static void pin_join_done(GObject *source, GAsyncResult *result, gpointer _conn)
+{
+       PurpleConnection *conn = _conn;
+       GError *error = NULL;
+       ChimeMeeting *mtg = chime_connection_lookup_meeting_by_pin_finish(CHIME_CONNECTION(source), result, &error);
+
+       if (!mtg) {
+               purple_notify_error(conn, NULL,
+                                   _("Unable to join meeting"),
+                                   error->message);
+               return;
+       }
+       /* Actually we'll handle it in the NEW_MEETING signal handler */
+}
 
+static void pin_join_begin(PurpleConnection *conn, const char *query)
+{
+       ChimeConnection *cxn = PURPLE_CHIME_CXN(conn);
+
+       chime_connection_lookup_meeting_by_pin_async(cxn, query, NULL,
+                                                    pin_join_done, conn);
+}
+
+void chime_purple_pin_join(PurplePluginAction *action)
+{
+       PurpleConnection *conn = (PurpleConnection *) action->context;
+
+       purple_request_input(conn, _("Chime PIN join meeting"),
+                            _("Enter the meeting PIN"), NULL, NULL,
+                            FALSE, FALSE, NULL,
+                            _("Search"), PURPLE_CALLBACK(pin_join_begin),
+                            _("Cancel"), NULL,
+                            NULL, NULL, NULL, conn);
+}
+
+void on_chime_new_meeting(ChimeConnection *cxn, ChimeMeeting *mtg, PurpleConnection *conn)
+{
+       gchar *secondary = g_strdup_printf(_("Meeting PIN: %s"),
+                                            chime_meeting_get_passcode(mtg));
+
+       gchar *text = g_strdup_printf(_("Web join URL: %s"),
+                                     chime_meeting_get_passcode(mtg));
+
+       purple_notify_formatted(conn, _("Amazon Chime Meeting"),
+                               chime_meeting_get_name(mtg), secondary,
+                               text, NULL, NULL);
+       g_free(text);
+       g_free(secondary);
+       g_object_unref(mtg);
 }