Mercurial > pidgin
changeset 6407:ba0b99a72be2
[gaim-migrate @ 6913]
Added API commands for adding or removing a batch of users at once to/from
a chat. IRC no longer has half a billion "Diablo-D3 has entered the room."
messages anymore.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 07 Aug 2003 20:47:29 +0000 |
parents | efaff39618a5 |
children | 90fc2199c156 |
files | src/conversation.c src/conversation.h src/gtkconv.c src/protocols/irc/msgs.c |
diffstat | 4 files changed, 234 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/conversation.c Thu Aug 07 01:15:54 2003 +0000 +++ b/src/conversation.c Thu Aug 07 20:47:29 2003 +0000 @@ -1932,6 +1932,34 @@ } void +gaim_chat_add_users(GaimChat *chat, GList *users) +{ + GaimConversation *conv; + GaimConversationUiOps *ops; + GList *l; + + g_return_if_fail(chat != NULL); + g_return_if_fail(users != NULL); + + conv = gaim_chat_get_conversation(chat); + ops = gaim_conversation_get_ui_ops(conv); + + for (l = users; l != NULL; l = l->next) { + gaim_chat_set_users(chat, + g_list_insert_sorted(gaim_chat_get_users(chat), + g_strdup((char *)l->data), + insertname_compare)); + + gaim_event_broadcast(event_chat_buddy_join, + gaim_conversation_get_gc(conv), gaim_chat_get_id(chat), + (char *)l->data); + } + + if (ops != NULL && ops->chat_add_users != NULL) + ops->chat_add_users(conv, users); +} + +void gaim_chat_rename_user(GaimChat *chat, const char *old_user, const char *new_user) { @@ -2024,6 +2052,73 @@ } } +void +gaim_chat_remove_users(GaimChat *chat, GList *users, const char *reason) +{ + GaimConversation *conv; + GaimConversationUiOps *ops; + char tmp[BUF_LONG]; + GList *names, *l; + + g_return_if_fail(chat != NULL); + g_return_if_fail(users != NULL); + + conv = gaim_chat_get_conversation(chat); + ops = gaim_conversation_get_ui_ops(conv); + + for (l = users; l != NULL; l = l->next) { + gaim_event_broadcast(event_chat_buddy_leave, + gaim_conversation_get_gc(conv), + gaim_chat_get_id(chat), l->data); + } + + if (ops != NULL && ops->chat_remove_users != NULL) + ops->chat_remove_users(conv, users); + + for (l = users; l != NULL; l = l->next) { + for (names = gaim_chat_get_users(chat); + names != NULL; + names = names->next) { + + if (!gaim_utf8_strcasecmp((char *)names->data, (char *)l->data)) { + gaim_chat_set_users(chat, + g_list_remove(gaim_chat_get_users(chat), names->data)); + + break; + } + } + } + + /* NOTE: Don't remove them from ignored in case they re-enter. */ + + if (gaim_prefs_get_bool("/core/conversations/chat/show_leave")) { + if (reason != NULL && *reason != '\0') { + int i; + int size = g_list_length(users); + int max = MIN(10, size); + GList *l; + + *tmp = '\0'; + + for (l = users, i = 0; i < max; i++, l = l->next) { + g_strlcat(tmp, (char *)l->data, sizeof(tmp)); + + if (i < max - 1) + g_strlcat(tmp, ", ", sizeof(tmp)); + } + + if (size > 10) + g_snprintf(tmp, sizeof(tmp), + _("(+%d more)"), size - 10); + + g_snprintf(tmp, sizeof(tmp), _(" left the room (%s)."), reason); + + gaim_conversation_write(conv, NULL, tmp, -1, + WFLAG_SYSTEM, time(NULL)); + } + } +} + GaimConversation * gaim_find_chat(const GaimConnection *gc, int id) {
--- a/src/conversation.h Thu Aug 07 01:15:54 2003 +0000 +++ b/src/conversation.h Thu Aug 07 20:47:29 2003 +0000 @@ -143,9 +143,11 @@ time_t mtime); void (*chat_add_user)(GaimConversation *conv, const char *user); + void (*chat_add_users)(GaimConversation *conv, GList *users); void (*chat_rename_user)(GaimConversation *conv, const char *old_name, const char *new_name); void (*chat_remove_user)(GaimConversation *conv, const char *user); + void (*chat_remove_users)(GaimConversation *conv, GList *users); void (*set_title)(GaimConversation *conv, const char *title); void (*update_progress)(GaimConversation *conv, float percent); @@ -915,6 +917,10 @@ /** * Sets the list of users in the chat room. * + * @note Calling this function will not update the display of the users. + * Please use gaim_chat_add_user(), gaim_chat_add_users(), + * gaim_chat_remove_user(), and gaim_chat_remove_users() instead. + * * @param chat The chat. * @param users The list of users. * @@ -1061,6 +1067,17 @@ const char *extra_msg); /** + * Adds a list of users to a chat. + * + * The data is copied from @a users, so it is up to the developer to + * free this list after calling this function. + * + * @param chat The chat. + * @param users The list of users to add. + */ +void gaim_chat_add_users(GaimChat *chat, GList *users); + +/** * Renames a user in a chat. * * @param chat The chat. @@ -1073,6 +1090,8 @@ /** * Removes a user from a chat, optionally with a reason. * + * It is up to the developer to free this list after calling this function. + * * @param chat The chat. * @param user The user that is being removed. * @param reason The optional reason given for the removal. Can be @c NULL. @@ -1081,6 +1100,15 @@ const char *reason); /** + * Removes a list of users from a chat, optionally with a single reason. + * + * @param chat The chat. + * @param users The users that are being removed. + * @param reason The optional reason given for the removal. Can be @c NULL. + */ +void gaim_chat_remove_users(GaimChat *chat, GList *users, const char *reason); + +/** * Finds a chat with the specified chat ID. * * @param gc The gaim_connection.
--- a/src/gtkconv.c Thu Aug 07 01:15:54 2003 +0000 +++ b/src/gtkconv.c Thu Aug 07 20:47:29 2003 +0000 @@ -4623,6 +4623,37 @@ } static void +gaim_gtkconv_chat_add_users(GaimConversation *conv, GList *users) +{ + GaimChat *chat; + GaimGtkConversation *gtkconv; + GaimGtkChatPane *gtkchat; + GList *l; + char tmp[BUF_LONG]; + int num_users; + int pos; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + num_users = g_list_length(gaim_chat_get_users(chat)); + + g_snprintf(tmp, sizeof(tmp), + ngettext("%d person in room", "%d people in room", + num_users), + num_users); + + gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); + + for (l = users; l != NULL; l = l->next) { + pos = g_list_index(gaim_chat_get_users(chat), (char *)l->data); + + add_chat_buddy_common(conv, (char *)l->data, pos); + } +} + +static void gaim_gtkconv_chat_rename_user(GaimConversation *conv, const char *old_name, const char *new_name) { @@ -4740,6 +4771,70 @@ } static void +gaim_gtkconv_chat_remove_users(GaimConversation *conv, GList *users) +{ + GaimChat *chat; + GaimGtkConversation *gtkconv; + GaimGtkChatPane *gtkchat; + GtkTreeIter iter; + GtkTreeModel *model; + GList *names = NULL; + GList *l; + char tmp[BUF_LONG]; + int num_users; + int f = 1; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + num_users = g_list_length(gaim_chat_get_users(chat)) - + g_list_length(users); + + for (l = users; l != NULL; l = l->next) { + for (names = gaim_chat_get_users(chat); + names != NULL; + names = names->next) { + + char *u = (char *)names->data; + + if (!gaim_utf8_strcasecmp(u, (char *)l->data)) { + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), + &iter)) + break; + + while (f != 0) { + char *val; + + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, + 1, &val, -1); + + if (!gaim_utf8_strcasecmp((char *)l->data, val)) + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + + f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); + + g_free(val); + } + + break; + } + } + } + + if (names == NULL) + return; + + g_snprintf(tmp, sizeof(tmp), + ngettext("%d person in room", "%d people in room", + num_users), num_users); + + gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); +} + +static void gaim_gtkconv_set_title(GaimConversation *conv, const char *title) { GaimGtkConversation *gtkconv; @@ -4892,8 +4987,10 @@ gaim_gtkconv_write_im, /* write_im */ gaim_gtkconv_write_conv, /* write_conv */ gaim_gtkconv_chat_add_user, /* chat_add_user */ + gaim_gtkconv_chat_add_users, /* chat_add_users */ gaim_gtkconv_chat_rename_user, /* chat_rename_user */ gaim_gtkconv_chat_remove_user, /* chat_remove_user */ + gaim_gtkconv_chat_remove_users, /* chat_remove_users */ gaim_gtkconv_set_title, /* set_title */ NULL, /* update_progress */ gaim_gtkconv_updated /* updated */
--- a/src/protocols/irc/msgs.c Thu Aug 07 01:15:54 2003 +0000 +++ b/src/protocols/irc/msgs.c Thu Aug 07 20:47:29 2003 +0000 @@ -294,6 +294,8 @@ g_free(irc->nameconv); irc->nameconv = NULL; } else { + GList *users = NULL; + while (*cur) { end = strchr(cur, ' '); if (!end) @@ -301,12 +303,22 @@ if (*cur == '@' || *cur == '%' || *cur == '+') cur++; tmp = g_strndup(cur, end - cur); - gaim_chat_add_user(GAIM_CHAT(convo), tmp, NULL); - g_free(tmp); + users = g_list_append(users, tmp); cur = end; if (*cur) cur++; } + + if (users != NULL) { + GList *l; + + gaim_chat_add_users(GAIM_CHAT(convo), users); + + for (l = users; l != NULL; l = l->next) + g_free(l->data); + + g_list_free(users); + } } g_free(names); } else {