Skip to content

Commit

Permalink
Added multi tree support in roomlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Fank authored and vitalyster committed Jun 5, 2019
1 parent 3aa1ca0 commit 1349539
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions backends/libpurple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
else if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) {
if (CONFIG_STRING(config, "service.protocol") == "prpl-jabber") {
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, (roomName + "/" + nickname).c_str());
} else {
}
else {
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, roomName.c_str());
}
}
Expand Down Expand Up @@ -2095,6 +2096,8 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
GList *field;
int topicId = -1;
int usersId = -1;
int descriptionId = -1;
int roomId = -1;
int id = 0;
for (field = fields; field != NULL; field = field->next, id++) {
PurpleRoomlistField *f = (PurpleRoomlistField *) field->data;
Expand All @@ -2109,12 +2112,18 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
continue;
}
std::string fstring = f->name;
if (fstring == "topic" || fstring == "description") {
if (fstring == "id") {
roomId = id;
}
else if (fstring == "topic" || fstring == "name") {
topicId = id;
}
else if (fstring == "users") {
usersId = id;
}
else if (fstring == "type") {
descriptionId = id;
}
else {
LOG4CXX_INFO(logger, "Unknown RoomList field " << fstring);
}
Expand All @@ -2126,37 +2135,64 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
if (room->type == PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) continue;
std::string roomId = prpl_info && prpl_info->roomlist_room_serialize ?
prpl_info->roomlist_room_serialize(room)
: room->name;
np->m_rooms[np->m_accounts[list->account]].push_back(roomId);

std::string roomIdentifier = room->name;
if (roomId != -1) {
char *roomIdField = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), roomId);
if (roomIdField) {
roomIdentifier = std::string(roomIdField);
}
}
np->m_rooms[np->m_accounts[list->account]].push_back(roomIdentifier);

std::string roomName = "";
int nestedLevel = 0;
PurpleRoomlistRoom *parentRoom = purple_roomlist_room_get_parent(room);
while (parentRoom != NULL) {
nestedLevel++;
parentRoom = purple_roomlist_room_get_parent(parentRoom);
}

if (nestedLevel > 0) {
std::string roomNamePrefix = std::string(nestedLevel, '-');
if (roomNamePrefix != "") {
roomNamePrefix = roomNamePrefix + "> ";
}
roomName = roomNamePrefix;
}

if (topicId == -1) {
m_topics.push_back(room->name);
roomName += room->name;
}
else {
char *topic = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), topicId);
if (topic) {
m_topics.push_back(topic);
roomName += topic;
}
else {
if (usersId) {
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
if (users) {
m_topics.push_back(users);
}
else {
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
m_topics.push_back(room->name);
}
else if (usersId) {
char *users = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), usersId);
if (users) {
roomName += users;
}
else {
LOG4CXX_WARN(logger, "RoomList topic is NULL");
m_topics.push_back(room->name);
LOG4CXX_WARN(logger, "RoomList topic and users is NULL");
roomName += room->name;
}
}
else {
LOG4CXX_WARN(logger, "RoomList topic is NULL");
roomName += room->name;
}
}

if (descriptionId != -1) {
char *description = (char *) g_list_nth_data(purple_roomlist_room_get_fields(room), descriptionId);
if (description) {
roomName += " (" + std::string(description) + ")";
}
}

m_topics.push_back(roomName);
}

std::string user = "";
Expand Down

0 comments on commit 1349539

Please sign in to comment.