Skip to content

Commit 89f7803

Browse files
Fankvitalyster
authored andcommitted
Added multi tree support in roomlist
1 parent f3c9e7c commit 89f7803

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
@@ -854,7 +854,8 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
854854
else if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) {
855855
if (CONFIG_STRING(config, "service.protocol") == "prpl-jabber") {
856856
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, (roomName + "/" + nickname).c_str());
857-
} else {
857+
}
858+
else {
858859
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, roomName.c_str());
859860
}
860861
}
@@ -2110,6 +2111,8 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21102111
GList *field;
21112112
int topicId = -1;
21122113
int usersId = -1;
2114+
int descriptionId = -1;
2115+
int roomId = -1;
21132116
int id = 0;
21142117
for (field = fields; field != NULL; field = field->next, id++) {
21152118
PurpleRoomlistField *f = (PurpleRoomlistField *) field->data;
@@ -2124,12 +2127,18 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21242127
continue;
21252128
}
21262129
std::string fstring = f->name;
2127-
if (fstring == "topic" || fstring == "description") {
2130+
if (fstring == "id") {
2131+
roomId = id;
2132+
}
2133+
else if (fstring == "topic" || fstring == "name" || fstring == "description") {
21282134
topicId = id;
21292135
}
21302136
else if (fstring == "users") {
21312137
usersId = id;
21322138
}
2139+
else if (fstring == "type") {
2140+
descriptionId = id;
2141+
}
21332142
else {
21342143
LOG4CXX_INFO(logger, "Unknown RoomList field " << fstring);
21352144
}
@@ -2141,37 +2150,64 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
21412150
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
21422151
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
21432152
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
2144-
if (room->type == PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) continue;
2145-
std::string roomId = prpl_info && prpl_info->roomlist_room_serialize ?
2146-
prpl_info->roomlist_room_serialize(room)
2147-
: room->name;
2148-
np->m_rooms[np->m_accounts[list->account]].push_back(roomId);
2153+
2154+
std::string roomIdentifier = room->name;
2155+
if (roomId != -1) {
2156+
char *roomIdField = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), roomId);
2157+
if (roomIdField) {
2158+
roomIdentifier = std::string(roomIdField);
2159+
}
2160+
}
2161+
np->m_rooms[np->m_accounts[list->account]].push_back(roomIdentifier);
2162+
2163+
std::string roomName = "";
2164+
int nestedLevel = 0;
2165+
PurpleRoomlistRoom *parentRoom = purple_roomlist_room_get_parent(room);
2166+
while (parentRoom != NULL) {
2167+
nestedLevel++;
2168+
parentRoom = purple_roomlist_room_get_parent(parentRoom);
2169+
}
2170+
2171+
if (nestedLevel > 0) {
2172+
std::string roomNamePrefix = std::string(nestedLevel, '-');
2173+
if (roomNamePrefix != "") {
2174+
roomNamePrefix = roomNamePrefix + "> ";
2175+
}
2176+
roomName = roomNamePrefix;
2177+
}
21492178

21502179
if (topicId == -1) {
2151-
m_topics.push_back(room->name);
2180+
roomName += room->name;
21522181
}
21532182
else {
21542183
char *topic = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), topicId);
21552184
if (topic) {
2156-
m_topics.push_back(topic);
2185+
roomName += topic;
21572186
}
2158-
else {
2159-
if (usersId) {
2160-
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2161-
if (users) {
2162-
m_topics.push_back(users);
2163-
}
2164-
else {
2165-
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2166-
m_topics.push_back(room->name);
2167-
}
2187+
else if (usersId) {
2188+
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
2189+
if (users) {
2190+
roomName += users;
21682191
}
21692192
else {
2170-
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2171-
m_topics.push_back(room->name);
2193+
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
2194+
roomName += room->name;
21722195
}
21732196
}
2197+
else {
2198+
LOG4CXX_WARN(logger, "RoomList topic is NULL");
2199+
roomName += room->name;
2200+
}
2201+
}
2202+
2203+
if (descriptionId != -1) {
2204+
char *description = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), descriptionId);
2205+
if (description) {
2206+
roomName += " (" + std::string(description) + ")";
2207+
}
21742208
}
2209+
2210+
m_topics.push_back(roomName);
21752211
}
21762212

21772213
std::string user = "";

0 commit comments

Comments
 (0)