Skip to content

Commit e69b727

Browse files
Fankvitalyster
authored andcommitted
Added multi tree support in roomlist
1 parent b497f10 commit e69b727

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
}
@@ -2086,6 +2087,8 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
20862087
GList *field;
20872088
int topicId = -1;
20882089
int usersId = -1;
2090+
int descriptionId = -1;
2091+
int roomId = -1;
20892092
int id = 0;
20902093
for (field = fields; field != NULL; field = field->next, id++) {
20912094
PurpleRoomlistField *f = (PurpleRoomlistField *) field->data;
@@ -2100,12 +2103,18 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21002103
continue;
21012104
}
21022105
std::string fstring = f->name;
2103-
if (fstring == "topic" || fstring == "description") {
2106+
if (fstring == "id") {
2107+
roomId = id;
2108+
}
2109+
else if (fstring == "topic" || fstring == "name") {
21042110
topicId = id;
21052111
}
21062112
else if (fstring == "users") {
21072113
usersId = id;
21082114
}
2115+
else if (fstring == "type") {
2116+
descriptionId = id;
2117+
}
21092118
else {
21102119
LOG4CXX_INFO(logger, "Unknown RoomList field " << fstring);
21112120
}
@@ -2117,37 +2126,64 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21172126
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
21182127
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
21192128
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
2120-
if (room->type == PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) continue;
2121-
std::string roomId = prpl_info && prpl_info->roomlist_room_serialize ?
2122-
prpl_info->roomlist_room_serialize(room)
2123-
: room->name;
2124-
np->m_rooms[np->m_accounts[list->account]].push_back(roomId);
2129+
2130+
std::string roomIdentifier = room->name;
2131+
if (roomId != -1) {
2132+
char *roomIdField = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), roomId);
2133+
if (roomIdField) {
2134+
roomIdentifier = std::string(roomIdField);
2135+
}
2136+
}
2137+
np->m_rooms[np->m_accounts[list->account]].push_back(roomIdentifier);
2138+
2139+
std::string roomName = "";
2140+
int nestedLevel = 0;
2141+
PurpleRoomlistRoom *parentRoom = purple_roomlist_room_get_parent(room);
2142+
while (parentRoom != NULL) {
2143+
nestedLevel++;
2144+
parentRoom = purple_roomlist_room_get_parent(parentRoom);
2145+
}
2146+
2147+
if (nestedLevel > 0) {
2148+
std::string roomNamePrefix = std::string(nestedLevel, '-');
2149+
if (roomNamePrefix != "") {
2150+
roomNamePrefix = roomNamePrefix + "> ";
2151+
}
2152+
roomName = roomNamePrefix;
2153+
}
21252154

21262155
if (topicId == -1) {
2127-
m_topics.push_back(room->name);
2156+
roomName += room->name;
21282157
}
21292158
else {
21302159
char *topic = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), topicId);
21312160
if (topic) {
2132-
m_topics.push_back(topic);
2161+
roomName += topic;
21332162
}
2134-
else {
2135-
if (usersId) {
2136-
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2137-
if (users) {
2138-
m_topics.push_back(users);
2139-
}
2140-
else {
2141-
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2142-
m_topics.push_back(room->name);
2143-
}
2163+
else if (usersId) {
2164+
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2165+
if (users) {
2166+
roomName += users;
21442167
}
21452168
else {
2146-
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2147-
m_topics.push_back(room->name);
2169+
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2170+
roomName += room->name;
21482171
}
21492172
}
2173+
else {
2174+
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2175+
roomName += room->name;
2176+
}
2177+
}
2178+
2179+
if (descriptionId != -1) {
2180+
char *description = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), descriptionId);
2181+
if (description) {
2182+
roomName += " (" + std::string(description) + ")";
2183+
}
21502184
}
2185+
2186+
m_topics.push_back(roomName);
21512187
}
21522188

21532189
std::string user = "";

0 commit comments

Comments
 (0)