1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Plugins: Added on_room_history_message

This commit is contained in:
James Booth 2016-04-08 00:11:33 +01:00
parent 2f432a942d
commit 93672eba9f
7 changed files with 72 additions and 0 deletions

View File

@ -93,6 +93,7 @@ c_plugin_create(const char *const filename)
plugin->post_room_message_display = c_post_room_message_display_hook;
plugin->pre_room_message_send = c_pre_room_message_send_hook;
plugin->post_room_message_send = c_post_room_message_send_hook;
plugin->on_room_history_message = c_on_room_history_message_hook;
plugin->pre_priv_message_display = c_pre_priv_message_display_hook;
plugin->post_priv_message_display = c_post_priv_message_display_hook;
plugin->pre_priv_message_send = c_pre_priv_message_send_hook;
@ -302,6 +303,22 @@ c_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const
func(room, message);
}
void
c_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *const message, const char *const timestamp)
{
void *f = NULL;
void (*func)(const char *const __room, const char *const __nick, const char *const __message,
const char *const __timestamp);
assert(plugin && plugin->module);
if (NULL == (f = dlsym(plugin->module, "prof_on_room_history_message")))
return;
func = (void (*)(const char *const, const char *const, const char *const, const char *const))f;
func(room, nick, message, timestamp);
}
char*
c_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *message)
{

View File

@ -60,6 +60,8 @@ void c_post_room_message_display_hook(ProfPlugin *plugin, const char *const room
const char *message);
char* c_pre_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message);
void c_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message);
void c_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *const message, const char *const timestamp);
char* c_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *message);

View File

@ -333,6 +333,27 @@ plugins_post_room_message_send(const char * const room, const char *message)
}
}
void
plugins_on_room_history_message(const char *const room, const char *const nick, const char *const message,
GDateTime *timestamp)
{
char *timestamp_str = NULL;
GTimeVal timestamp_tv;
gboolean res = g_date_time_to_timeval(timestamp, &timestamp_tv);
if (res) {
timestamp_str = g_time_val_to_iso8601(&timestamp_tv);
}
GSList *curr = plugins;
while (curr) {
ProfPlugin *plugin = curr->data;
plugin->on_room_history_message(plugin, room, nick, message, NULL);
curr = g_slist_next(curr);
}
free(timestamp_str);
}
char*
plugins_pre_priv_message_display(const char * const jid, const char *message)
{

View File

@ -67,6 +67,8 @@ typedef struct prof_plugin_t {
const char *message);
char* (*pre_room_message_send)(struct prof_plugin_t* plugin, const char *const room, const char *message);
void (*post_room_message_send)(struct prof_plugin_t* plugin, const char *const room, const char *message);
void (*on_room_history_message)(struct prof_plugin_t* plugin, const char *const room, const char *const nick, const char *const message,
const char *const timestamp);
char* (*pre_priv_message_display)(struct prof_plugin_t* plugin, const char *const room, const char *const nick,
const char *message);
@ -117,6 +119,8 @@ char* plugins_pre_room_message_display(const char *const room, const char *const
void plugins_post_room_message_display(const char *const room, const char *const nick, const char *message);
char* plugins_pre_room_message_send(const char *const room, const char *message);
void plugins_post_room_message_send(const char *const room, const char *message);
void plugins_on_room_history_message(const char *const room, const char *const nick, const char *const message,
GDateTime *timestamp);
char* plugins_pre_priv_message_display(const char *const jid, const char *message);
void plugins_post_priv_message_display(const char *const jid, const char *message);

View File

@ -111,6 +111,7 @@ python_plugin_create(const char *const filename)
plugin->post_room_message_display = python_post_room_message_display_hook;
plugin->pre_room_message_send = python_pre_room_message_send_hook;
plugin->post_room_message_send = python_post_room_message_send_hook;
plugin->on_room_history_message = python_on_room_history_message_hook;
plugin->pre_priv_message_display = python_pre_priv_message_display_hook;
plugin->post_priv_message_display = python_post_priv_message_display_hook;
plugin->pre_priv_message_send = python_pre_priv_message_send_hook;
@ -463,6 +464,28 @@ python_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, c
allow_python_threads();
}
void
python_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *const message, const char *const timestamp)
{
disable_python_threads();
PyObject *p_args = Py_BuildValue("ssss", room, nick, message, timestamp);
PyObject *p_function;
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, "prof_on_room_history_message")) {
p_function = PyObject_GetAttrString(p_module, "prof_on_room_history_message");
python_check_error();
if (p_function && PyCallable_Check(p_function)) {
PyObject_CallObject(p_function, p_args);
python_check_error();
Py_XDECREF(p_function);
}
}
allow_python_threads();
}
char*
python_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *message)

View File

@ -60,6 +60,8 @@ void python_post_room_message_display_hook(ProfPlugin *plugin, const char *const
const char *message);
char* python_pre_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message);
void python_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message);
void python_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *const message, const char *const timestamp);
char* python_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick,
const char *message);

View File

@ -43,6 +43,7 @@
#include "log.h"
#include "config/preferences.h"
#include "ui/window.h"
#include "plugins/plugins.h"
void
mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason)
@ -356,6 +357,8 @@ mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp,
win_print(window, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", line->str);
g_string_free(line, TRUE);
plugins_on_room_history_message(mucwin->roomjid, nick, message, timestamp);
}
static void