]> www.infradead.org Git - pidgin-chime.git/commitdiff
More ->prpl_conn elimination
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 9 Aug 2017 21:25:19 +0000 (22:25 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 9 Aug 2017 21:26:56 +0000 (22:26 +0100)
chat.c
chime.h
conversations.c
messages.c

diff --git a/chat.c b/chat.c
index 52cd77463ae80a3daa9e3119d945a4c97d2f3fb0..8394ab503f54407fa4a485cf3a6b123c560f7fe9 100644 (file)
--- a/chat.c
+++ b/chat.c
@@ -330,7 +330,7 @@ static void kill_member(gpointer _member)
        g_free(member);
 }
 
-static struct chime_chat *do_join_chat(ChimeConnection *cxn, ChimeRoom *room)
+static struct chime_chat *do_join_chat(PurpleConnection *conn, ChimeConnection *cxn, ChimeRoom *room)
 {
        ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        if (!room)
@@ -347,7 +347,7 @@ static struct chime_chat *do_join_chat(ChimeConnection *cxn, ChimeRoom *room)
                     "name", &name, "channel", &channel, NULL);
 
        int chat_id = ++priv->chat_id;
-       chat->conv = serv_got_joined_chat(cxn->prpl_conn, chat_id, name);
+       chat->conv = serv_got_joined_chat(conn, chat_id, name);
        g_free(name);
 
        g_hash_table_insert(priv->live_chats, GUINT_TO_POINTER(chat_id), chat);
@@ -365,6 +365,12 @@ static struct chime_chat *do_join_chat(ChimeConnection *cxn, ChimeRoom *room)
        chat->msgs.is_room = TRUE;
        chat->msgs.id = chat->id;
        chat->msgs.cb = chat_deliver_msg;
+
+       const gchar *after = NULL;
+       if (chime_read_last_msg(conn, TRUE, chat->id, &after, &chat->msgs.last_msg) &&
+           after && after[0])
+               chat->msgs.last_msg_time = g_strdup(after);
+
        fetch_messages(cxn, &chat->msgs, NULL);
        fetch_chat_memberships(cxn, chat, NULL);
 
@@ -381,7 +387,7 @@ void chime_purple_join_chat(PurpleConnection *conn, GHashTable *data)
        ChimeRoom *room = chime_connection_room_by_id(cxn, roomid);
        if (!room)
                return;
-       do_join_chat(cxn, room);
+       do_join_chat(conn, cxn, room);
 }
 
 void chime_purple_chat_leave(PurpleConnection *conn, int id)
@@ -470,8 +476,9 @@ int chime_purple_chat_send(PurpleConnection *conn, int id, const char *message,
        return ret;
 }
 
-static gboolean chat_demuxing_jugg_cb(ChimeConnection *cxn, gpointer _unused, JsonNode *data_node)
+static gboolean chat_demuxing_jugg_cb(ChimeConnection *cxn, gpointer _conn, JsonNode *data_node)
 {
+       PurpleConnection *conn = _conn;
        ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        JsonObject *obj = json_node_get_object(data_node);
        JsonNode *record = json_object_get_member(obj, "record");
@@ -490,7 +497,7 @@ static gboolean chat_demuxing_jugg_cb(ChimeConnection *cxn, gpointer _unused, Js
 
        struct chime_chat *chat = g_hash_table_lookup(priv->chats_by_room, room);
        if (!chat)
-               chat = do_join_chat(cxn, room);
+               chat = do_join_chat(conn, cxn, room);
        if (!chat) {
                printf("No chat for room %s\n", room_id);
                return FALSE;
@@ -503,7 +510,7 @@ void chime_init_chats(ChimeConnection *cxn)
        ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        priv->live_chats = g_hash_table_new(g_direct_hash, g_direct_equal);
        priv->chats_by_room = g_hash_table_new(g_direct_hash, g_direct_equal);
-       chime_jugg_subscribe(cxn, priv->device_channel, "RoomMessage", chat_demuxing_jugg_cb, cxn);
+       chime_jugg_subscribe(cxn, priv->device_channel, "RoomMessage", chat_demuxing_jugg_cb, cxn->prpl_conn);
 }
 
 void chime_destroy_chats(ChimeConnection *cxn)
@@ -511,10 +518,9 @@ void chime_destroy_chats(ChimeConnection *cxn)
        ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        g_clear_pointer(&priv->live_chats, g_hash_table_unref);
        g_clear_pointer(&priv->chats_by_room, g_hash_table_unref);
-       chime_jugg_unsubscribe(cxn, priv->device_channel, "RoomMessage", chat_demuxing_jugg_cb, cxn);
+       chime_jugg_unsubscribe(cxn, priv->device_channel, "RoomMessage", chat_demuxing_jugg_cb, cxn->prpl_conn);
 }
 
-
 void on_chime_new_room(ChimeConnection *cxn, ChimeRoom *room, PurpleConnection *conn)
 {
        const gchar *id, *last_mentioned;
@@ -537,5 +543,5 @@ void on_chime_new_room(ChimeConnection *cxn, ChimeRoom *room, PurpleConnection *
        }
 
        /* We have been mentioned since we last looked at this room. Open it now. */
-       do_join_chat(cxn, room);
+       do_join_chat(conn, cxn, room);
 }
diff --git a/chime.h b/chime.h
index 51e25c8f4db8dfc641653b3d2475a766b32a5946..96d7c237943a80dc0c3f98e83e70b6a8563979ad 100644 (file)
--- a/chime.h
+++ b/chime.h
@@ -51,6 +51,7 @@ typedef void (*chime_msg_cb)(ChimeConnection *cxn, struct chime_msgs *msgs,
 struct chime_msgs {
        gboolean is_room;
        const gchar *id; /* of the conversation or room */
+       gchar *last_msg_time;
        gchar *last_msg; /* MessageId of last known message */
        GHashTable *messages; /* While fetching */
        SoupMessage *soup_msg; /* For cancellation */
index 8bfbe3a14dbb6352524911196fac5f272da20664..6a91865fd526adcae629bd0087f815b369ef7ee9 100644 (file)
@@ -177,6 +177,11 @@ void on_chime_new_conversation(ChimeConnection *cxn, ChimeConversation *conv, Pu
 
        if (last_sent && strcmp(last_seen, last_sent)) {
                purple_debug(PURPLE_DEBUG_INFO, "chime", "Fetch conv messages for %s\n", im->msgs.id);
+
+               const gchar *after = NULL;
+               if (chime_read_last_msg(conn, FALSE, im->msgs.id, &after, &im->msgs.last_msg) &&
+                   after && after[0])
+                       im->msgs.last_msg_time = g_strdup(after);
                fetch_messages(purple_connection_get_protocol_data(im->conn), &im->msgs, NULL);
        }
 }
index 2544d13ffb8afdc5018290cd1f9cfb641b890d0d..469b721c433edfcfda70ed612ac7fb682de79e87 100644 (file)
@@ -72,6 +72,7 @@ void chime_complete_messages(ChimeConnection *cxn, struct chime_msgs *msgs)
        g_hash_table_foreach_remove(msgs->messages, insert_queued_msg, &l);
        g_hash_table_destroy(msgs->messages);
        g_clear_pointer(&msgs->last_msg, g_free);
+       g_clear_pointer(&msgs->last_msg_time, g_free);
        msgs->messages = NULL;
 
        while (l) {
@@ -139,15 +140,12 @@ void fetch_messages(ChimeConnection *cxn, struct chime_msgs *msgs, const gchar *
        const gchar *opts[4];
        int i = 0;
 
-       const gchar *after = NULL;
-       chime_read_last_msg(cxn->prpl_conn, msgs->is_room, msgs->id, &after, &msgs->last_msg);
-
        if (!msgs->messages)
                msgs->messages = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)json_node_unref);
 
-       if (after && after[0]) {
+       if (msgs->last_msg_time && msgs->last_msg_time[0]) {
                opts[i++] = "after";
-               opts[i++] = after;
+               opts[i++] = msgs->last_msg_time;
        }
        if (next_token) {
                opts[i++] = "next-token";