Skip to content

Commit 1349539

Browse files
Fankvitalyster
authored andcommitted
Added multi tree support in roomlist
1 parent 3aa1ca0 commit 1349539

File tree

1 file changed

+57
-21
lines changed

1 file changed

+57
-21
lines changed

backends/libpurple/main.cpp

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
851851
else if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) {
852852
if (CONFIG_STRING(config, "service.protocol") == "prpl-jabber") {
853853
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, (roomName + "/" + nickname).c_str());
854-
} else {
854+
}
855+
else {
855856
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, roomName.c_str());
856857
}
857858
}
@@ -2095,6 +2096,8 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
20952096
GList *field;
20962097
int topicId = -1;
20972098
int usersId = -1;
2099+
int descriptionId = -1;
2100+
int roomId = -1;
20982101
int id = 0;
20992102
for (field = fields; field != NULL; field = field->next, id++) {
21002103
PurpleRoomlistField *f = (PurpleRoomlistField *) field->data;
@@ -2109,12 +2112,18 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21092112
continue;
21102113
}
21112114
std::string fstring = f->name;
2112-
if (fstring == "topic" || fstring == "description") {
2115+
if (fstring == "id") {
2116+
roomId = id;
2117+
}
2118+
else if (fstring == "topic" || fstring == "name") {
21132119
topicId = id;
21142120
}
21152121
else if (fstring == "users") {
21162122
usersId = id;
21172123
}
2124+
else if (fstring == "type") {
2125+
descriptionId = id;
2126+
}
21182127
else {
21192128
LOG4CXX_INFO(logger, "Unknown RoomList field " << fstring);
21202129
}
@@ -2126,37 +2135,64 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21262135
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
21272136
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
21282137
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
2129-
if (room->type == PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) continue;
2130-
std::string roomId = prpl_info && prpl_info->roomlist_room_serialize ?
2131-
prpl_info->roomlist_room_serialize(room)
2132-
: room->name;
2133-
np->m_rooms[np->m_accounts[list->account]].push_back(roomId);
2138+
2139+
std::string roomIdentifier = room->name;
2140+
if (roomId != -1) {
2141+
char *roomIdField = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), roomId);
2142+
if (roomIdField) {
2143+
roomIdentifier = std::string(roomIdField);
2144+
}
2145+
}
2146+
np->m_rooms[np->m_accounts[list->account]].push_back(roomIdentifier);
2147+
2148+
std::string roomName = "";
2149+
int nestedLevel = 0;
2150+
PurpleRoomlistRoom *parentRoom = purple_roomlist_room_get_parent(room);
2151+
while (parentRoom != NULL) {
2152+
nestedLevel++;
2153+
parentRoom = purple_roomlist_room_get_parent(parentRoom);
2154+
}
2155+
2156+
if (nestedLevel > 0) {
2157+
std::string roomNamePrefix = std::string(nestedLevel, '-');
2158+
if (roomNamePrefix != "") {
2159+
roomNamePrefix = roomNamePrefix + "> ";
2160+
}
2161+
roomName = roomNamePrefix;
2162+
}
21342163

21352164
if (topicId == -1) {
2136-
m_topics.push_back(room->name);
2165+
roomName += room->name;
21372166
}
21382167
else {
21392168
char *topic = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), topicId);
21402169
if (topic) {
2141-
m_topics.push_back(topic);
2170+
roomName += topic;
21422171
}
2143-
else {
2144-
if (usersId) {
2145-
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2146-
if (users) {
2147-
m_topics.push_back(users);
2148-
}
2149-
else {
2150-
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2151-
m_topics.push_back(room->name);
2152-
}
2172+
else if (usersId) {
2173+
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2174+
if (users) {
2175+
roomName += users;
21532176
}
21542177
else {
2155-
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2156-
m_topics.push_back(room->name);
2178+
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2179+
roomName += room->name;
21572180
}
21582181
}
2182+
else {
2183+
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2184+
roomName += room->name;
2185+
}
2186+
}
2187+
2188+
if (descriptionId != -1) {
2189+
char *description = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), descriptionId);
2190+
if (description) {
2191+
roomName += " (" + std::string(description) + ")";
2192+
}
21592193
}
2194+
2195+
m_topics.push_back(roomName);
21602196
}
21612197

21622198
std::string user = "";

0 commit comments

Comments
 (0)