diff --git a/src/modules/rpc/channel.c b/src/modules/rpc/channel.c index ab9857306..698072085 100644 --- a/src/modules/rpc/channel.c +++ b/src/modules/rpc/channel.c @@ -8,7 +8,7 @@ ModuleHeader MOD_HEADER = { "rpc/channel", - "1.0.1", + "1.0.2", "channel.* RPC calls", "UnrealIRCd Team", "unrealircd-6", @@ -18,6 +18,7 @@ ModuleHeader MOD_HEADER void rpc_channel_list(Client *client, json_t *request, json_t *params); void rpc_channel_get(Client *client, json_t *request, json_t *params); void rpc_channel_set_mode(Client *client, json_t *request, json_t *params); +void rpc_channel_set_topic(Client *client, json_t *request, json_t *params); MOD_INIT() { @@ -47,6 +48,13 @@ MOD_INIT() config_error("[rpc/channel] Could not register RPC handler"); return MOD_FAILED; } + r.method = "channel.set_topic"; + r.call = rpc_channel_set_topic; + if (!RPCHandlerAdd(modinfo->handle, &r)) + { + config_error("[rpc/channel] Could not register RPC handler"); + return MOD_FAILED; + } return MOD_SUCCESS; } @@ -149,3 +157,46 @@ void rpc_channel_set_mode(Client *client, json_t *request, json_t *params) rpc_response(client, request, result); json_decref(result); } + +void rpc_channel_set_topic(Client *client, json_t *request, json_t *params) +{ + json_t *result, *item; + const char *channelname, *topic, *set_by=NULL, *str; + Channel *channel; + time_t set_at = 0; + + channelname = json_object_get_string(params, "channel"); + if (!channelname) + { + rpc_error(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing set_by: 'channel'"); + return; + } + + topic = json_object_get_string(params, "topic"); + if (!topic) + { + rpc_error(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing set_by: 'topic'"); + return; + } + + set_by = json_object_get_string(params, "set_by"); + str = json_object_get_string(params, "set_at"); + if (str) + set_at = server_time_to_unix_time(str); + + if (!(channel = find_channel(channelname))) + { + rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Channel not found"); + return; + } + + set_channel_topic(&me, channel, NULL, topic, set_by, set_at); + + // TODO: hmmm, i have my doubts about returning the whole channel as a result here... + // especially with detail level 3 !? + + result = json_object(); + json_expand_channel(result, "channel", channel, 3); + rpc_response(client, request, result); + json_decref(result); +}