1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-14 18:14:15 -04:00

Added /roster private command

This commit is contained in:
James Booth 2016-01-24 01:04:21 +00:00
parent 67abfaa21e
commit 6d8a3e2020
7 changed files with 122 additions and 58 deletions

View File

@ -286,6 +286,7 @@ static struct cmd_t command_defs[] =
"/roster room position first|last",
"/roster room order name|unread",
"/roster room unread before|after|off",
"/roster private room|group|off",
"/roster header char <char>|none",
"/roster presence indent <indent>",
"/roster contact char <char>|none",
@ -340,6 +341,9 @@ static struct cmd_t command_defs[] =
{ "room unread before", "Show unread message count before room in roster." },
{ "room unread after", "Show unread message count after room in roster." },
{ "room unread off", "Do not show unread message count for rooms in roster." },
{ "room private room", "Show room private chats below the room in the roster." },
{ "room private group", "Show room private chats as a separate roster group." },
{ "room private off", "Do not show room private chats in the roster." },
{ "header char <char>", "Prefix roster headers with specified character." },
{ "header char none", "Remove roster header character prefix." },
{ "contact char <char>", "Prefix roster contacts with specified character." },
@ -1931,6 +1935,7 @@ static Autocomplete roster_room_ac;
static Autocomplete roster_room_position_ac;
static Autocomplete roster_room_order_ac;
static Autocomplete roster_unread_ac;
static Autocomplete roster_private_ac;
static Autocomplete group_ac;
static Autocomplete bookmark_ac;
static Autocomplete bookmark_property_ac;
@ -2198,6 +2203,12 @@ cmd_init(void)
autocomplete_add(roster_ac, "contact");
autocomplete_add(roster_ac, "resource");
autocomplete_add(roster_ac, "presence");
autocomplete_add(roster_ac, "private");
roster_private_ac = autocomplete_new();
autocomplete_add(roster_private_ac, "room");
autocomplete_add(roster_private_ac, "group");
autocomplete_add(roster_private_ac, "off");
roster_header_ac = autocomplete_new();
autocomplete_add(roster_header_ac, "char");
@ -2532,6 +2543,7 @@ cmd_uninit(void)
autocomplete_free(roster_room_position_ac);
autocomplete_free(roster_room_order_ac);
autocomplete_free(roster_remove_all_ac);
autocomplete_free(roster_private_ac);
autocomplete_free(group_ac);
autocomplete_free(bookmark_ac);
autocomplete_free(bookmark_property_ac);
@ -2744,6 +2756,7 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(roster_room_position_ac);
autocomplete_reset(roster_room_order_ac);
autocomplete_reset(roster_remove_all_ac);
autocomplete_reset(roster_private_ac);
autocomplete_reset(group_ac);
autocomplete_reset(titlebar_ac);
autocomplete_reset(bookmark_ac);
@ -3228,6 +3241,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster private", roster_private_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE);
if (result) {
return result;

View File

@ -2408,6 +2408,33 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
} else if (g_strcmp0(args[0], "private") == 0) {
if (g_strcmp0(args[1], "room") == 0) {
cons_show("Showing room private chats under room.");
prefs_set_string(PREF_ROSTER_PRIVATE, "room");
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "group") == 0) {
cons_show("Showing room private chats as roster group.");
prefs_set_string(PREF_ROSTER_PRIVATE, "group");
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "off") == 0) {
cons_show("Hiding room private chats in roster.");
prefs_set_string(PREF_ROSTER_PRIVATE, "off");
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else {
cons_bad_cmd_usage(command);
return TRUE;
}
} else if (g_strcmp0(args[0], "room") == 0) {
if (g_strcmp0(args[1], "position") == 0) {
if (g_strcmp0(args[2], "first") == 0) {

View File

@ -1051,6 +1051,7 @@ _get_group(preference_t pref)
case PREF_ROSTER_ROOMS_POS:
case PREF_ROSTER_ROOMS_ORDER:
case PREF_ROSTER_ROOMS_UNREAD:
case PREF_ROSTER_PRIVATE:
case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE:
case PREF_ENC_WARN:
@ -1257,6 +1258,8 @@ _get_key(preference_t pref)
return "roster.rooms.order";
case PREF_ROSTER_ROOMS_UNREAD:
return "roster.rooms.unread";
case PREF_ROSTER_PRIVATE:
return "roster.private";
case PREF_RESOURCE_TITLE:
return "resource.title";
case PREF_RESOURCE_MESSAGE:
@ -1353,6 +1356,8 @@ _get_default_string(preference_t pref)
return "name";
case PREF_ROSTER_ROOMS_UNREAD:
return "after";
case PREF_ROSTER_PRIVATE:
return "room";
case PREF_TIME_CONSOLE:
return "%H:%M:%S";
case PREF_TIME_CHAT:

View File

@ -79,6 +79,7 @@ typedef enum {
PREF_ROSTER_ROOMS_POS,
PREF_ROSTER_ROOMS_ORDER,
PREF_ROSTER_ROOMS_UNREAD,
PREF_ROSTER_PRIVATE,
PREF_MUC_PRIVILEGES,
PREF_PRESENCE,
PREF_WRAP,

View File

@ -414,6 +414,7 @@ _load_preferences(void)
_set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER);
_set_string_preference("roster.rooms.unread", PREF_ROSTER_ROOMS_UNREAD);
_set_string_preference("roster.rooms.pos", PREF_ROSTER_ROOMS_POS);
_set_string_preference("roster.private", PREF_ROSTER_PRIVATE);
if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) {
gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
prefs_set_roster_size(roster_size);

View File

@ -1354,6 +1354,15 @@ cons_roster_setting(void)
else
cons_show("Roster rooms (/roster) : hide");
char *priv = prefs_get_string(PREF_ROSTER_PRIVATE);
if (g_strcmp0(priv, "room") == 0) {
cons_show("Roster private (/roster) : room");
} else if (g_strcmp0(priv, "group") == 0) {
cons_show("Roster private (/roster) : group");
} else {
cons_show("Roster private (/roster) : OFF");
}
char *rooms_pos = prefs_get_string(PREF_ROSTER_ROOMS_POS);
cons_show("Roster rooms position (/roster) : %s", rooms_pos);
prefs_free_string(rooms_pos);

View File

@ -520,72 +520,76 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
// TODO if show private chat with room
GList *privs = wins_get_private_chats(mucwin->roomjid);
GList *curr = privs;
while (curr) {
ProfPrivateWin *privwin = curr->data;
win_sub_newline_lazy(layout->subwin);
char *privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
if (g_strcmp0(privpref, "room") == 0) {
GList *privs = wins_get_private_chats(mucwin->roomjid);
GList *curr = privs;
while (curr) {
ProfPrivateWin *privwin = curr->data;
win_sub_newline_lazy(layout->subwin);
GString *privmsg = g_string_new(" ");
indent = prefs_get_roster_contact_indent();
current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
GString *privmsg = g_string_new(" ");
indent = prefs_get_roster_contact_indent();
current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
}
}
}
// TODO add preference
indent = prefs_get_roster_resource_indent();
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
// TODO add preference
indent = prefs_get_roster_resource_indent();
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
}
}
// TODO add preference
unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
}
// TODO add preference
ch = '/';
if (ch) {
g_string_append_printf(privmsg, "%c", ch);
}
g_string_append(privmsg, privwin->fulljid + strlen(mucwin->roomjid) + 1);
if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, " (%d)", privwin->unread);
}
prefs_free_string(unreadpos);
if (privwin->unread > 0) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
if (mucwin->unread > 0) {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
g_string_free(privmsg, TRUE);
curr = g_list_next(curr);
}
// TODO add preference
unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
}
// TODO add preference
ch = '/';
if (ch) {
g_string_append_printf(privmsg, "%c", ch);
}
g_string_append(privmsg, privwin->fulljid + strlen(mucwin->roomjid) + 1);
if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, " (%d)", privwin->unread);
}
prefs_free_string(unreadpos);
if (privwin->unread > 0) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
if (mucwin->unread > 0) {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
g_string_free(privmsg, TRUE);
curr = g_list_next(curr);
g_list_free(privs);
}
g_list_free(privs);
prefs_free_string(privpref);
}
static int