Fix channel mentions. Closes #2

v1
Tony Olagbaiye 7 years ago
parent 638abde1f9
commit c76c93fd71

@ -19,34 +19,83 @@ char *slack_message_translate_code(struct t_slack_workspace *workspace,
{ {
struct t_slack_channel *channel; struct t_slack_channel *channel;
struct t_slack_user *user; struct t_slack_user *user;
char *command; size_t resultlen;
char *identifier, *alttext, *result, *symbol, *prefix;
switch (code[0]) identifier = strdup(code);
alttext = strchr(identifier, '|');
if (alttext)
*alttext++ = '\0';
switch (identifier[0])
{ {
case '#': /* channel */ case '#': /* channel */
channel = slack_channel_search(workspace, code+1); if (alttext)
{
prefix = "#";
symbol = strdup(alttext);
}
else
{
channel = slack_channel_search(workspace, identifier+1);
if (channel) if (channel)
return strdup(channel->name); {
prefix = "#";
symbol = strdup(channel->name);
}
else else
return strdup(code); {
prefix = "Channel:";
symbol = strdup(identifier+1);
}
}
break;
case '@': /* user */ case '@': /* user */
user = slack_user_search(workspace, code+1); if (alttext)
{
prefix = "@";
symbol = strdup(alttext);
}
else
{
user = slack_user_search(workspace, identifier+1);
if (user) if (user)
{ {
size_t nicklen = snprintf(NULL, 0, "%s@%s%s", weechat_color("chat_nick"), user->profile.display_name, weechat_color("reset")) + 1; prefix = "@";
char *tag = malloc(nicklen); symbol = strdup(user->profile.display_name);
snprintf(tag, nicklen, "%s@%s%s", weechat_color("chat_nick"), user->profile.display_name, weechat_color("reset"));
return tag;
} }
else else
return strdup(code); {
prefix = "User:";
symbol = strdup(identifier+1);
}
}
break;
case '!': /* special */ case '!': /* special */
command = strdup(code); if (alttext)
command[0] = '@'; {
return command; prefix = "@";
symbol = strdup(alttext);
}
else
{
prefix = "@";
symbol = strdup(identifier+1);
}
break;
default: /* url */ default: /* url */
return strdup(code); prefix = "";
symbol = strdup(code);
break;
} }
free(identifier);
resultlen = snprintf(NULL, 0, "%s%s%s%s", weechat_color("chat_nick"), prefix, symbol, weechat_color("reset")) + 1;
result = malloc(resultlen);
snprintf(result, resultlen, "%s%s%s%s", weechat_color("chat_nick"), prefix, symbol, weechat_color("reset"));
free(symbol);
return result;
} }
void slack_message_htmldecode(char *dest, const char *src, size_t n) void slack_message_htmldecode(char *dest, const char *src, size_t n)

Loading…
Cancel
Save