degesch: show channel prefixes in PRIVMSG lines

This commit is contained in:
Přemysl Eric Janouch 2015-06-07 06:15:31 +02:00
parent 62845876d5
commit 0ddc0458ef
1 changed files with 38 additions and 4 deletions

View File

@ -918,6 +918,7 @@ struct buffer_line_args
char *object; ///< Object of action
char *text; ///< Text of message
char *reason; ///< Reason for PART, KICK, QUIT
char *prefixes; ///< Channel user prefixes
};
struct buffer_line
@ -947,6 +948,7 @@ buffer_line_destroy (struct buffer_line *self)
free (self->args.object);
free (self->args.text);
free (self->args.reason);
free (self->args.prefixes);
free (self);
}
@ -2385,9 +2387,11 @@ buffer_line_display (struct app_context *ctx,
{
case BUFFER_LINE_PRIVMSG:
if (line->flags & BUFFER_LINE_HIGHLIGHT)
formatter_add (&f, "#a<#s>#r #m", ATTR_HIGHLIGHT, nick, a->text);
formatter_add (&f, "#a<#s#s>#r #m",
a->prefixes ? a->prefixes : "", ATTR_HIGHLIGHT, nick, a->text);
else
formatter_add (&f, "<#c#s#r> #m", nick_color, nick, a->text);
formatter_add (&f, "<#s#c#s#r> #m",
a->prefixes ? a->prefixes : "", nick_color, nick, a->text);
break;
case BUFFER_LINE_ACTION:
if (line->flags & BUFFER_LINE_HIGHLIGHT)
@ -4457,6 +4461,22 @@ irc_handle_privmsg_text (struct server *s,
const char *target = msg->params.vector[0];
struct buffer *buffer = irc_get_buffer_for_message (s, msg, target);
const char *prefixes = "";
if (irc_is_channel (s, target))
{
char *nickname = irc_cut_nickname (msg->prefix);
struct user *user;
struct channel *channel;
struct channel_user *channel_user;
if ((user = str_map_find (&s->irc_users, nickname))
&& (channel = str_map_find (&s->irc_channels, target))
&& (channel_user = irc_channel_get_user (channel, user)))
prefixes = channel_user->prefixes.str;
free (nickname);
}
if (buffer)
{
// TODO: some more obvious indication of highlights
@ -4468,7 +4488,8 @@ irc_handle_privmsg_text (struct server *s,
: BUFFER_LINE_PRIVMSG;
buffer_send (s->ctx, buffer, type, flags,
.who = irc_to_utf8 (s->ctx, msg->prefix),
.text = irc_to_utf8 (s->ctx, text->str));
.text = irc_to_utf8 (s->ctx, text->str),
.prefixes = xstrdup (prefixes));
}
}
@ -5374,10 +5395,23 @@ static void
log_outcoming_privmsg (struct server *s,
struct send_autosplit_args *a, struct buffer *buffer, const char *line)
{
const char *prefixes = "";
if (irc_is_channel (s, a->target))
{
struct user *user;
struct channel *channel;
struct channel_user *channel_user;
if ((user = s->irc_user)
&& (channel = str_map_find (&s->irc_channels, a->target))
&& (channel_user = irc_channel_get_user (channel, user)))
prefixes = channel_user->prefixes.str;
}
if (buffer && soft_assert (s->irc_user))
buffer_send (s->ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
.who = irc_to_utf8 (s->ctx, s->irc_user->nickname),
.text = irc_to_utf8 (s->ctx, line));
.text = irc_to_utf8 (s->ctx, line),
.prefixes = xstrdup (prefixes));
else
// TODO: fix logging and encoding
buffer_send (s->ctx, s->buffer, BUFFER_LINE_STATUS, 0,