summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/channel-rec.h2
-rw-r--r--src/core/channels.c1
-rw-r--r--src/fe-common/irc/fe-irc-commands.c30
-rw-r--r--src/irc/core/channel-events.c42
4 files changed, 68 insertions, 7 deletions
diff --git a/src/core/channel-rec.h b/src/core/channel-rec.h
index 9e991cb4..e0d5b858 100644
--- a/src/core/channel-rec.h
+++ b/src/core/channel-rec.h
@@ -3,6 +3,8 @@
#include "window-item-rec.h"
char *topic;
+char *topic_by;
+time_t topic_time;
GHashTable *nicks; /* list of nicks */
int no_modes:1; /* channel doesn't support modes */
diff --git a/src/core/channels.c b/src/core/channels.c
index 2d487d3e..3214a389 100644
--- a/src/core/channels.c
+++ b/src/core/channels.c
@@ -78,6 +78,7 @@ void channel_destroy(CHANNEL_REC *channel)
MODULE_DATA_DEINIT(channel);
g_free_not_null(channel->topic);
+ g_free_not_null(channel->topic_by);
g_free_not_null(channel->key);
g_free(channel->mode);
g_free(channel->name);
diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c
index 43bf0e94..fe361ef9 100644
--- a/src/fe-common/irc/fe-irc-commands.c
+++ b/src/fe-common/irc/fe-irc-commands.c
@@ -322,6 +322,34 @@ static void cmd_ver(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
g_free(str);
}
+static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
+{
+ CHANNEL_REC *channel;
+ char *timestr;
+ struct tm *tm;
+
+ g_return_if_fail(data != NULL);
+
+ channel = *data != '\0' ? channel_find(server, data) : CHANNEL(item);
+ if (channel == NULL) return;
+
+ printformat(server, channel->name, MSGLEVEL_CRAP,
+ channel->topic == NULL ? IRCTXT_NO_TOPIC : IRCTXT_TOPIC,
+ channel->name, channel->topic);
+
+ if (channel->topic_time > 0) {
+ tm = localtime(&channel->topic_time);
+ timestr = g_strdup(asctime(tm));
+ if (timestr[strlen(timestr)-1] == '\n')
+ timestr[strlen(timestr)-1] = '\0';
+
+ printformat(server, channel->name, MSGLEVEL_CRAP,
+ IRCTXT_TOPIC_INFO, channel->topic_by, timestr);
+ g_free(timestr);
+ }
+ signal_stop();
+}
+
/* SYNTAX: TS */
static void cmd_ts(const char *data)
{
@@ -350,6 +378,7 @@ void fe_irc_commands_init(void)
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind("nick", NULL, (SIGNAL_FUNC) cmd_nick);
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
+ command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
}
@@ -366,5 +395,6 @@ void fe_irc_commands_deinit(void)
command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
+ command_unbind("topic", (SIGNAL_FUNC) cmd_topic);
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);
}
diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c
index eb8a6b30..9714b38e 100644
--- a/src/irc/core/channel-events.c
+++ b/src/irc/core/channel-events.c
@@ -93,18 +93,28 @@ static void event_target_unavailable(const char *data, IRC_SERVER_REC *server)
g_free(params);
}
-static void channel_change_topic(IRC_SERVER_REC *server, const char *channel, const char *topic)
+static void channel_change_topic(IRC_SERVER_REC *server, const char *channel,
+ const char *topic, const char *setby,
+ time_t settime)
{
CHANNEL_REC *chanrec;
chanrec = channel_find(SERVER(server), channel);
- if (chanrec != NULL) {
+ if (chanrec == NULL) return;
+
+ if (topic != NULL) {
g_free_not_null(chanrec->topic);
chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
-
- signal_emit("channel topic changed", 1, chanrec);
}
+
+ g_free_not_null(chanrec->topic_by);
+ chanrec->topic_by = g_strdup(setby);
+
+ chanrec->topic_time = settime;
+
+ signal_emit("channel topic changed", 1, chanrec);
}
+
static void event_topic_get(const char *data, IRC_SERVER_REC *server)
{
char *params, *channel, *topic;
@@ -112,18 +122,34 @@ static void event_topic_get(const char *data, IRC_SERVER_REC *server)
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &channel, &topic);
- channel_change_topic(server, channel, topic);
+ channel_change_topic(server, channel, topic, NULL, 0);
g_free(params);
}
-static void event_topic(const char *data, IRC_SERVER_REC *server)
+static void event_topic(const char *data, IRC_SERVER_REC *server,
+ const char *nick)
{
char *params, *channel, *topic;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2, &channel, &topic);
- channel_change_topic(server, channel, topic);
+ channel_change_topic(server, channel, topic, nick, time(NULL));
+ g_free(params);
+}
+
+static void event_topic_info(const char *data, IRC_SERVER_REC *server)
+{
+ char *params, *channel, *topicby, *topictime;
+ time_t t;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 4, NULL, &channel,
+ &topicby, &topictime);
+
+ t = (time_t) atol(topictime);
+ channel_change_topic(server, channel, NULL, topicby, t);
g_free(params);
}
@@ -283,6 +309,7 @@ void channel_events_init(void)
signal_add("event kick", (SIGNAL_FUNC) event_kick);
signal_add("event invite", (SIGNAL_FUNC) event_invite);
signal_add("event 332", (SIGNAL_FUNC) event_topic_get);
+ signal_add("event 333", (SIGNAL_FUNC) event_topic_info);
signal_add_first("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
}
@@ -303,5 +330,6 @@ void channel_events_deinit(void)
signal_remove("event kick", (SIGNAL_FUNC) event_kick);
signal_remove("event invite", (SIGNAL_FUNC) event_invite);
signal_remove("event 332", (SIGNAL_FUNC) event_topic_get);
+ signal_remove("event 333", (SIGNAL_FUNC) event_topic_info);
signal_remove("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
}