Commit d77b98f07b78e152ed32b7f10c67fa8b4999b306

Authored by dx
1 parent b330e2b0

WIP broken implementation of chat_info_defaults/roomlist_get_list

libpurple/pluginmain.cpp
... ... @@ -56,6 +56,7 @@ static void init_prpl_info(PurplePluginProtocolInfo &i) {
56 56 i.login = &PurpleLine::login;
57 57 i.close = WRAPPER(PurpleLine::close);
58 58 i.chat_info = WRAPPER(PurpleLine::chat_info);
  59 + i.chat_info_defaults = WRAPPER(PurpleLine::chat_info_defaults);
59 60 i.remove_buddy = WRAPPER(PurpleLine::remove_buddy);
60 61 i.send_im = WRAPPER(PurpleLine::send_im);
61 62 i.join_chat = WRAPPER(PurpleLine::join_chat);
... ... @@ -63,6 +64,7 @@ static void init_prpl_info(PurplePluginProtocolInfo &i) {
63 64 i.chat_leave = WRAPPER(PurpleLine::chat_leave);
64 65 i.chat_send = WRAPPER(PurpleLine::chat_send);
65 66 i.find_blist_chat = WRAPPER(PurpleLine::find_blist_chat);
  67 + i.roomlist_get_list = WRAPPER(PurpleLine::roomlist_get_list);
66 68  
67 69 i.struct_size = sizeof(PurplePluginProtocolInfo);
68 70 }
... ...
libpurple/purpleline.hpp
... ... @@ -216,6 +216,8 @@ public:
216 216 void chat_leave(int id);
217 217 int chat_send(int id, const char *message, PurpleMessageFlags flags);
218 218 PurpleChat *find_blist_chat(const char *name);
  219 + PurpleRoomlist *roomlist_get_list();
  220 + GHashTable *chat_info_defaults(const char *id);
219 221  
220 222 private:
221 223  
... ...
libpurple/purpleline_chats.cpp
... ... @@ -168,12 +168,26 @@ GList *PurpleLine::chat_info() {
168 168 struct proto_chat_entry *entry = g_new0(struct proto_chat_entry, 1);
169 169  
170 170 entry->label = "Group _Name";
171   - entry->identifier = "name",
  171 + entry->identifier = "id",
172 172 entry->required = TRUE;
173 173  
174 174 return g_list_append(nullptr, entry);
175 175 }
176 176  
  177 +
  178 +GHashTable *PurpleLine::chat_info_defaults(const char *id)
  179 +{
  180 + GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
  181 +
  182 + if (id != NULL) {
  183 + g_hash_table_insert(components, g_strdup("id"), g_strdup(id));
  184 + g_hash_table_insert(components, g_strdup("type"),
  185 + g_strdup(chat_type_to_string[ChatType::ROOM].c_str()));
  186 + }
  187 +
  188 + return components;
  189 +}
  190 +
177 191 void PurpleLine::join_chat(GHashTable *components) {
178 192 char *id_ptr = (char *)g_hash_table_lookup(components, "id");
179 193 if (!id_ptr) {
... ... @@ -292,3 +306,34 @@ int PurpleLine::chat_send(int id, const char *message, PurpleMessageFlags flags)
292 306 PurpleChat *PurpleLine::find_blist_chat(const char *name) {
293 307 return blist_find_chat(name, ChatType::ANY);
294 308 }
  309 +
  310 +PurpleRoomlist *PurpleLine::roomlist_get_list() {
  311 + PurpleRoomlist *roomlist;
  312 + PurpleRoomlistField *f;
  313 + GList *fields = NULL;
  314 +
  315 + roomlist = purple_roomlist_new(acct);
  316 +
  317 + f = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, "ID", "id", TRUE);
  318 + fields = g_list_append(fields, f);
  319 +
  320 + f = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, "Topic", "topic", FALSE);
  321 + fields = g_list_append(fields, f);
  322 +
  323 + purple_roomlist_set_fields(roomlist, fields);
  324 + purple_roomlist_set_in_progress(roomlist, TRUE);
  325 +
  326 + std::set<PurpleChat *> chats = blist_find<PurpleChat>();
  327 +
  328 + for (PurpleChat *chat: chats) {
  329 + GHashTable *components = purple_chat_get_components(chat);
  330 + char *id = (char *)g_hash_table_lookup(components, "id");
  331 +
  332 + PurpleRoomlistRoom *room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, id, NULL);
  333 + purple_roomlist_room_add_field(roomlist, room, id);
  334 + purple_roomlist_room_add(roomlist, room);
  335 + };
  336 +
  337 + purple_roomlist_set_in_progress(roomlist, FALSE);
  338 + return roomlist;
  339 +}
... ...