Mercurial > pidgin.yaz
changeset 8158:e283be34aadf
[gaim-migrate @ 8870]
this hasn't crahed on me yet, and lets chats know what your nick is on a per-room basis,
since Jabber is cool enough to let you be different nicks in different rooms
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Wed, 21 Jan 2004 04:55:34 +0000 |
parents | 657b5acaec48 |
children | e1e871897a4b |
files | src/conversation.c src/conversation.h src/protocols/jabber/chat.c src/protocols/jabber/chat.h src/protocols/jabber/jabber.c src/protocols/jabber/presence.c |
diffstat | 6 files changed, 68 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/src/conversation.c Wed Jan 21 04:51:29 2004 +0000 +++ b/src/conversation.c Wed Jan 21 04:55:34 2004 +0000 @@ -85,59 +85,27 @@ } static gboolean -find_nick(GaimConnection *gc, const char *message) +find_nick(const char *nick, const char *message) { - GaimAccount *account; char *msg, *who, *p; - const char *disp; int n; - - account = gaim_connection_get_account(gc); + gboolean ret = FALSE; msg = g_utf8_strdown(message, -1); - who = g_utf8_strdown(gaim_account_get_username(account), -1); + who = g_utf8_strdown(nick, -1); n = strlen(who); if ((p = strstr(msg, who)) != NULL) { if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { - g_free(who); - g_free(msg); - - return TRUE; + ret = TRUE; } } g_free(who); - - disp = gaim_connection_get_display_name(gc); - - - if(disp) { - if (!gaim_utf8_strcasecmp(gaim_account_get_username(account), disp)) { - g_free(msg); - - return FALSE; - } - - who = g_utf8_strdown(disp, -1); - n = who ? strlen(who) : 0; - - if (n > 0 && (p = strstr(msg, who)) != NULL) { - if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { - g_free(who); - g_free(msg); - - return TRUE; - } - } - - g_free(who); - } - g_free(msg); - return FALSE; + return ret; } static gboolean @@ -817,10 +785,17 @@ } else if (type == GAIM_CONV_CHAT) { + const char *disp; + conv->u.chat = g_new0(GaimConvChat, 1); conv->u.chat->conv = conv; chats = g_list_append(chats, conv); + if((disp = gaim_connection_get_display_name(account->gc))) { + gaim_conv_chat_set_nick(conv->u.chat, disp); + } else { + gaim_conv_chat_set_nick(conv->u.chat, gaim_account_get_username(account)); + } gaim_conversation_set_logging(conv, gaim_prefs_get_bool("/core/logging/log_chats")); @@ -1855,20 +1830,17 @@ if (!(flags & GAIM_MESSAGE_WHISPER)) { char *str; - const char *disp; + const char *nick; str = g_strdup(gaim_normalize(account, who)); - disp = gaim_connection_get_display_name(gc); - - if (!gaim_utf8_strcasecmp(str, gaim_normalize(account, gaim_account_get_username(account))) || - (disp && !gaim_utf8_strcasecmp(str, gaim_normalize(account, disp)))) { - + nick = gaim_conv_chat_get_nick(chat); + + if (!g_utf8_collate(str, gaim_normalize(account, nick))) { flags |= GAIM_MESSAGE_SEND; - } - else { + } else { flags |= GAIM_MESSAGE_RECV; - if (find_nick(gc, message)) + if (find_nick(chat->nick, message)) flags |= GAIM_MESSAGE_NICK; } @@ -1969,6 +1941,7 @@ GaimConversationUiOps *ops; char tmp[BUF_LONG]; GList *names; + gboolean its_me = FALSE; g_return_if_fail(chat != NULL); g_return_if_fail(old_user != NULL); @@ -2002,9 +1975,19 @@ else if (gaim_conv_chat_is_user_ignored(chat, new_user)) gaim_conv_chat_unignore(chat, new_user); + if(!g_utf8_collate(old_user, chat->nick)) { + gaim_conv_chat_set_nick(chat, new_user); + its_me = TRUE; + } + if (gaim_prefs_get_bool("/core/conversations/chat/show_nick_change")) { - g_snprintf(tmp, sizeof(tmp), - _("%s is now known as %s"), old_user, new_user); + if(its_me) { + g_snprintf(tmp, sizeof(tmp), + _("You are now known as %s"), new_user); + } else { + g_snprintf(tmp, sizeof(tmp), + _("%s is now known as %s"), old_user, new_user); + } gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); } @@ -2166,6 +2149,20 @@ gaim_conv_chat_set_users(chat, NULL); } +void gaim_conv_chat_set_nick(GaimConvChat *chat, const char *nick) { + g_return_if_fail(chat != NULL); + + if(chat->nick) + g_free(chat->nick); + chat->nick = g_strdup(nick); +} + +const char *gaim_conv_chat_get_nick(GaimConvChat *chat) { + g_return_val_if_fail(chat != NULL, NULL); + + return chat->nick; +} + GaimConversation * gaim_find_chat(const GaimConnection *gc, int id) {
--- a/src/conversation.h Wed Jan 21 04:51:29 2004 +0000 +++ b/src/conversation.h Wed Jan 21 04:55:34 2004 +0000 @@ -223,6 +223,7 @@ char *who; /**< The person who set the topic. */ char *topic; /**< The topic. */ int id; /**< The chat ID. */ + char *nick; /**< Your nick in this chat. */ }; /** @@ -244,9 +245,9 @@ char *title; /**< The window title. */ gboolean logging; /**< The status of logging. */ - + GaimLog *log; /**< This conversation's log */ - + GList *send_history; /**< The send history. */ GString *history; /**< The conversation history. */ @@ -1180,6 +1181,22 @@ void gaim_conv_chat_clear_users(GaimConvChat *chat); /** + * Sets your nickname (used for hilighting) for a chat. + * + * @param chat The chat. + * @param nick The nick. + */ +void gaim_conv_chat_set_nick(GaimConvChat *chat, const char *nick); + +/** + * Gets your nickname (used for hilighting) for a chat. + * + * @param chat The chat. + * @return The nick. + */ +const char *gaim_conv_chat_get_nick(GaimConvChat *chat); + +/** * Finds a chat with the specified chat ID. * * @param gc The gaim_connection.
--- a/src/protocols/jabber/chat.c Wed Jan 21 04:51:29 2004 +0000 +++ b/src/protocols/jabber/chat.c Wed Jan 21 04:55:34 2004 +0000 @@ -190,7 +190,6 @@ chat->room = g_strdup(room); chat->server = g_strdup(server); - chat->nick = g_strdup(handle); g_hash_table_insert(js->chats, room_jid, chat); @@ -233,7 +232,6 @@ g_free(chat->room); g_free(chat->server); - g_free(chat->nick); g_free(chat); } @@ -588,8 +586,6 @@ xmlnode *presence; room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); - gaim_debug(GAIM_DEBUG_INFO, "jabber", "%s is leaving chat %s\n", - chat->nick, room_jid); presence = xmlnode_new("presence"); xmlnode_set_attrib(presence, "to", room_jid); xmlnode_set_attrib(presence, "type", "unavailable");
--- a/src/protocols/jabber/chat.h Wed Jan 21 04:51:29 2004 +0000 +++ b/src/protocols/jabber/chat.h Wed Jan 21 04:55:34 2004 +0000 @@ -34,7 +34,6 @@ JabberStream *js; char *room; char *server; - char *nick; int id; GaimConversation *conv; gboolean muc;
--- a/src/protocols/jabber/jabber.c Wed Jan 21 04:51:29 2004 +0000 +++ b/src/protocols/jabber/jabber.c Wed Jan 21 04:55:34 2004 +0000 @@ -1102,7 +1102,8 @@ if(!(server = g_hash_table_lookup(chat->components, "server"))) continue; - if(!g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { + if(jid->node && jid->domain && + !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { jabber_id_free(jid); return chat; }
--- a/src/protocols/jabber/presence.c Wed Jan 21 04:51:29 2004 +0000 +++ b/src/protocols/jabber/presence.c Wed Jan 21 04:55:34 2004 +0000 @@ -307,6 +307,7 @@ chat->id = i++; chat->muc = muc; chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); + gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), jid->resource); } if(type && !strcmp(type, "unavailable")) { @@ -331,15 +332,11 @@ continue; nick_change = TRUE; gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); - if(!g_utf8_collate(jid->resource, chat->nick)) { - g_free(chat->nick); - chat->nick = g_strdup(nick); - } break; } } if(!nick_change) { - if(!strcmp(jid->resource, chat->nick)) { + if(!g_utf8_collate(jid->resource, gaim_conv_chat_get_nick(GAIM_CONV_CHAT(chat->conv)))) { serv_got_chat_left(js->gc, chat->id); jabber_chat_destroy(chat); } else {