Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libpurple multilevel disco #315

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions backends/libpurple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,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 @@ -1989,6 +1990,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 @@ -2003,12 +2006,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" || fstring == "description") {
topicId = id;
}
else if (fstring == "users") {
usersId = id;
}
else if (fstring == "type") {
descriptionId = id;
}
else {
LOG4CXX_INFO(logger, "Unknown RoomList field " << fstring);
}
Expand All @@ -2020,37 +2029,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