diff options
author | Dr. David Alan Gilbert <dave@treblig.org> | 2016-09-01 00:22:44 +0100 |
---|---|---|
committer | Dr. David Alan Gilbert <dave@treblig.org> | 2016-09-03 00:05:09 +0100 |
commit | 3857950b0b8c0310f1608d391db47d2e9f592e1a (patch) | |
tree | f7783cdc891de6429d8c2ec8f4bf719a2e4dec56 /matrix-room.c | |
parent | 511fa3c1e886fd968c6e29fcafd80f840b0b6f51 (diff) | |
download | purple-matrix-3857950b0b8c0310f1608d391db47d2e9f592e1a.tar.gz |
event hooks
Some events need to do something else before the event can be
transmitted, and indeed the contents of the event aren't necessarily
known until that other thing has happened.
Add a hook that gets called when the event is ready to be sent
and when the event is to be free'd.
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Diffstat (limited to 'matrix-room.c')
-rw-r--r-- | matrix-room.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/matrix-room.c b/matrix-room.c index ee5cdb5..4e003eb 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -375,6 +375,9 @@ static void _send_queued_event(PurpleConversation *conv) } else { event = queue -> data; g_assert(event != NULL); + if (event->hook) + return event->hook(event, FALSE); + purple_debug_info("matrixprpl", "Sending %s with txn id %s\n", event->event_type, event->txn_id); @@ -389,7 +392,8 @@ static void _send_queued_event(PurpleConversation *conv) static void _enqueue_event(PurpleConversation *conv, const gchar *event_type, - JsonObject *event_content) + JsonObject *event_content, + EventSendHook hook, void *hook_data) { MatrixRoomEvent *event; GList *event_queue; @@ -398,6 +402,8 @@ static void _enqueue_event(PurpleConversation *conv, const gchar *event_type, event = matrix_event_new(event_type, event_content); event->txn_id = g_strdup_printf("%"G_GINT64_FORMAT"%"G_GUINT32_FORMAT, g_get_monotonic_time(), g_random_int()); + event->hook = hook; + event->hook_data = hook_data; event_queue = _get_event_queue(conv); event_queue = g_list_append(event_queue, event); @@ -803,7 +809,7 @@ void matrix_room_send_message(PurpleConversation *conv, const gchar *message) json_object_set_string_member(content, "msgtype", type_string); json_object_set_string_member(content, "body", message_to_send); - _enqueue_event(conv, "m.room.message", content); + _enqueue_event(conv, "m.room.message", content, NULL, NULL); json_object_unref(content); purple_conv_chat_write(chat, _get_my_display_name(conv), |