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)
"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);
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);
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)
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");
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;
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)
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;
}
/* 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);
}
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) {
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";