Mercurial > pidgin
comparison src/conversation.c @ 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 | 77d1252b3803 |
children | 1d86096ae0f4 |
comparison
equal
deleted
inserted
replaced
8157:657b5acaec48 | 8158:e283be34aadf |
---|---|
83 | 83 |
84 return strcasecmp(a, b); | 84 return strcasecmp(a, b); |
85 } | 85 } |
86 | 86 |
87 static gboolean | 87 static gboolean |
88 find_nick(GaimConnection *gc, const char *message) | 88 find_nick(const char *nick, const char *message) |
89 { | 89 { |
90 GaimAccount *account; | |
91 char *msg, *who, *p; | 90 char *msg, *who, *p; |
92 const char *disp; | |
93 int n; | 91 int n; |
94 | 92 gboolean ret = FALSE; |
95 account = gaim_connection_get_account(gc); | |
96 | 93 |
97 msg = g_utf8_strdown(message, -1); | 94 msg = g_utf8_strdown(message, -1); |
98 | 95 |
99 who = g_utf8_strdown(gaim_account_get_username(account), -1); | 96 who = g_utf8_strdown(nick, -1); |
100 n = strlen(who); | 97 n = strlen(who); |
101 | 98 |
102 if ((p = strstr(msg, who)) != NULL) { | 99 if ((p = strstr(msg, who)) != NULL) { |
103 if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { | 100 if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { |
104 g_free(who); | 101 ret = TRUE; |
105 g_free(msg); | |
106 | |
107 return TRUE; | |
108 } | 102 } |
109 } | 103 } |
110 | 104 |
111 g_free(who); | 105 g_free(who); |
112 | |
113 disp = gaim_connection_get_display_name(gc); | |
114 | |
115 | |
116 if(disp) { | |
117 if (!gaim_utf8_strcasecmp(gaim_account_get_username(account), disp)) { | |
118 g_free(msg); | |
119 | |
120 return FALSE; | |
121 } | |
122 | |
123 who = g_utf8_strdown(disp, -1); | |
124 n = who ? strlen(who) : 0; | |
125 | |
126 if (n > 0 && (p = strstr(msg, who)) != NULL) { | |
127 if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { | |
128 g_free(who); | |
129 g_free(msg); | |
130 | |
131 return TRUE; | |
132 } | |
133 } | |
134 | |
135 g_free(who); | |
136 } | |
137 | |
138 g_free(msg); | 106 g_free(msg); |
139 | 107 |
140 return FALSE; | 108 return ret; |
141 } | 109 } |
142 | 110 |
143 static gboolean | 111 static gboolean |
144 reset_typing(gpointer data) | 112 reset_typing(gpointer data) |
145 { | 113 { |
815 gaim_conversation_set_logging(conv, | 783 gaim_conversation_set_logging(conv, |
816 gaim_prefs_get_bool("/core/logging/log_ims")); | 784 gaim_prefs_get_bool("/core/logging/log_ims")); |
817 } | 785 } |
818 else if (type == GAIM_CONV_CHAT) | 786 else if (type == GAIM_CONV_CHAT) |
819 { | 787 { |
788 const char *disp; | |
789 | |
820 conv->u.chat = g_new0(GaimConvChat, 1); | 790 conv->u.chat = g_new0(GaimConvChat, 1); |
821 conv->u.chat->conv = conv; | 791 conv->u.chat->conv = conv; |
822 | 792 |
823 chats = g_list_append(chats, conv); | 793 chats = g_list_append(chats, conv); |
794 if((disp = gaim_connection_get_display_name(account->gc))) { | |
795 gaim_conv_chat_set_nick(conv->u.chat, disp); | |
796 } else { | |
797 gaim_conv_chat_set_nick(conv->u.chat, gaim_account_get_username(account)); | |
798 } | |
824 | 799 |
825 gaim_conversation_set_logging(conv, | 800 gaim_conversation_set_logging(conv, |
826 gaim_prefs_get_bool("/core/logging/log_chats")); | 801 gaim_prefs_get_bool("/core/logging/log_chats")); |
827 } | 802 } |
828 | 803 |
1853 if (gaim_conv_chat_is_user_ignored(chat, who)) | 1828 if (gaim_conv_chat_is_user_ignored(chat, who)) |
1854 return; | 1829 return; |
1855 | 1830 |
1856 if (!(flags & GAIM_MESSAGE_WHISPER)) { | 1831 if (!(flags & GAIM_MESSAGE_WHISPER)) { |
1857 char *str; | 1832 char *str; |
1858 const char *disp; | 1833 const char *nick; |
1859 | 1834 |
1860 str = g_strdup(gaim_normalize(account, who)); | 1835 str = g_strdup(gaim_normalize(account, who)); |
1861 disp = gaim_connection_get_display_name(gc); | 1836 nick = gaim_conv_chat_get_nick(chat); |
1862 | 1837 |
1863 if (!gaim_utf8_strcasecmp(str, gaim_normalize(account, gaim_account_get_username(account))) || | 1838 if (!g_utf8_collate(str, gaim_normalize(account, nick))) { |
1864 (disp && !gaim_utf8_strcasecmp(str, gaim_normalize(account, disp)))) { | |
1865 | |
1866 flags |= GAIM_MESSAGE_SEND; | 1839 flags |= GAIM_MESSAGE_SEND; |
1867 } | 1840 } else { |
1868 else { | |
1869 flags |= GAIM_MESSAGE_RECV; | 1841 flags |= GAIM_MESSAGE_RECV; |
1870 | 1842 |
1871 if (find_nick(gc, message)) | 1843 if (find_nick(chat->nick, message)) |
1872 flags |= GAIM_MESSAGE_NICK; | 1844 flags |= GAIM_MESSAGE_NICK; |
1873 } | 1845 } |
1874 | 1846 |
1875 g_free(str); | 1847 g_free(str); |
1876 } | 1848 } |
1967 { | 1939 { |
1968 GaimConversation *conv; | 1940 GaimConversation *conv; |
1969 GaimConversationUiOps *ops; | 1941 GaimConversationUiOps *ops; |
1970 char tmp[BUF_LONG]; | 1942 char tmp[BUF_LONG]; |
1971 GList *names; | 1943 GList *names; |
1944 gboolean its_me = FALSE; | |
1972 | 1945 |
1973 g_return_if_fail(chat != NULL); | 1946 g_return_if_fail(chat != NULL); |
1974 g_return_if_fail(old_user != NULL); | 1947 g_return_if_fail(old_user != NULL); |
1975 g_return_if_fail(new_user != NULL); | 1948 g_return_if_fail(new_user != NULL); |
1976 | 1949 |
2000 gaim_conv_chat_ignore(chat, new_user); | 1973 gaim_conv_chat_ignore(chat, new_user); |
2001 } | 1974 } |
2002 else if (gaim_conv_chat_is_user_ignored(chat, new_user)) | 1975 else if (gaim_conv_chat_is_user_ignored(chat, new_user)) |
2003 gaim_conv_chat_unignore(chat, new_user); | 1976 gaim_conv_chat_unignore(chat, new_user); |
2004 | 1977 |
1978 if(!g_utf8_collate(old_user, chat->nick)) { | |
1979 gaim_conv_chat_set_nick(chat, new_user); | |
1980 its_me = TRUE; | |
1981 } | |
1982 | |
2005 if (gaim_prefs_get_bool("/core/conversations/chat/show_nick_change")) { | 1983 if (gaim_prefs_get_bool("/core/conversations/chat/show_nick_change")) { |
2006 g_snprintf(tmp, sizeof(tmp), | 1984 if(its_me) { |
2007 _("%s is now known as %s"), old_user, new_user); | 1985 g_snprintf(tmp, sizeof(tmp), |
1986 _("You are now known as %s"), new_user); | |
1987 } else { | |
1988 g_snprintf(tmp, sizeof(tmp), | |
1989 _("%s is now known as %s"), old_user, new_user); | |
1990 } | |
2008 | 1991 |
2009 gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | 1992 gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); |
2010 } | 1993 } |
2011 } | 1994 } |
2012 | 1995 |
2162 g_free(user); | 2145 g_free(user); |
2163 } | 2146 } |
2164 | 2147 |
2165 g_list_free(users); | 2148 g_list_free(users); |
2166 gaim_conv_chat_set_users(chat, NULL); | 2149 gaim_conv_chat_set_users(chat, NULL); |
2150 } | |
2151 | |
2152 void gaim_conv_chat_set_nick(GaimConvChat *chat, const char *nick) { | |
2153 g_return_if_fail(chat != NULL); | |
2154 | |
2155 if(chat->nick) | |
2156 g_free(chat->nick); | |
2157 chat->nick = g_strdup(nick); | |
2158 } | |
2159 | |
2160 const char *gaim_conv_chat_get_nick(GaimConvChat *chat) { | |
2161 g_return_val_if_fail(chat != NULL, NULL); | |
2162 | |
2163 return chat->nick; | |
2167 } | 2164 } |
2168 | 2165 |
2169 GaimConversation * | 2166 GaimConversation * |
2170 gaim_find_chat(const GaimConnection *gc, int id) | 2167 gaim_find_chat(const GaimConnection *gc, int id) |
2171 { | 2168 { |