Changeset df701918


Ignore:
Timestamp:
2015-12-08T22:31:05Z (5 years ago)
Author:
dequis <dx@…>
Parents:
459dec8
Message:

Add imcb_buddy_nick_change(), like nick_hint but stronger

nick_hint only works when creating new users, it's a no-op after the
user is online. This new function takes care of nick changes after that.

It also helps clean up couple of hacks in irc_im.c \o/

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • irc_im.c

    r459dec8 rdf701918  
    342342}
    343343
    344 static gboolean bee_irc_user_nick_update(irc_user_t *iu);
     344static gboolean bee_irc_user_nick_update(irc_user_t *iu, gboolean offline_only);
    345345
    346346static gboolean bee_irc_user_fullname(bee_t *bee, bee_user_t *bu)
     
    370370        }
    371371
    372         bee_irc_user_nick_update(iu);
     372        bee_irc_user_nick_update(iu, TRUE);
    373373
    374374        return TRUE;
     
    377377static gboolean bee_irc_user_nick_hint(bee_t *bee, bee_user_t *bu, const char *hint)
    378378{
    379         bee_irc_user_nick_update((irc_user_t *) bu->ui_data);
     379        bee_irc_user_nick_update((irc_user_t *) bu->ui_data, TRUE);
     380
     381        return TRUE;
     382}
     383
     384static gboolean bee_irc_user_nick_change(bee_t *bee, bee_user_t *bu, const char *nick)
     385{
     386        bee_irc_user_nick_update((irc_user_t *) bu->ui_data, FALSE);
    380387
    381388        return TRUE;
     
    388395        bee_user_flags_t online;
    389396
    390         /* Take the user offline temporarily so we can change the nick (if necessary). */
    391         if ((online = bu->flags & BEE_USER_ONLINE)) {
    392                 bu->flags &= ~BEE_USER_ONLINE;
    393         }
    394 
    395397        bee_irc_channel_update(irc, NULL, iu);
    396         bee_irc_user_nick_update(iu);
    397 
    398         if (online) {
    399                 bu->flags |= online;
    400                 bee_irc_channel_update(irc, NULL, iu);
    401         }
    402 
    403         return TRUE;
    404 }
    405 
    406 static gboolean bee_irc_user_nick_update(irc_user_t *iu)
     398        bee_irc_user_nick_update(iu, FALSE);
     399
     400        return TRUE;
     401}
     402
     403static gboolean bee_irc_user_nick_update(irc_user_t *iu, gboolean offline_only)
    407404{
    408405        bee_user_t *bu = iu->bu;
    409406        char *newnick;
    410407
    411         if (bu->flags & BEE_USER_ONLINE) {
     408        if (offline_only && bu->flags & BEE_USER_ONLINE) {
    412409                /* Ignore if the user is visible already. */
    413410                return TRUE;
     
    432429{
    433430        bee_user_t *bu = iu->bu;
    434         bee_user_flags_t online;
    435431
    436432        if (bu == FALSE) {
     
    438434        }
    439435
    440         /* In this case, pretend the user is offline. */
    441         if ((online = bu->flags & BEE_USER_ONLINE)) {
    442                 bu->flags &= ~BEE_USER_ONLINE;
    443         }
    444 
    445436        nick_del(bu);
    446         bee_irc_user_nick_update(iu);
    447 
    448         bu->flags |= online;
     437        bee_irc_user_nick_update(iu, FALSE);
     438
    449439}
    450440
     
    11461136
    11471137        bee_irc_log,
     1138        bee_irc_user_nick_change,
    11481139};
  • protocols/bee.h

    r459dec8 rdf701918  
    131131
    132132        void (*log)(bee_t *bee, const char *tag, const char *msg);
     133        gboolean (*user_nick_change)(bee_t *bee, bee_user_t *bu, const char *hint);
    133134} bee_ui_funcs_t;
    134135
  • protocols/nogaim.c

    r459dec8 rdf701918  
    479479}
    480480
    481 /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
    482    modules to suggest a nickname for a handle. */
    483 void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick)
     481/* Implements either imcb_buddy_nick_hint() or imcb_buddy_nick_change() depending on the value of 'change' */
     482static void buddy_nick_hint_or_change(struct im_connection *ic, const char *handle, const char *nick, gboolean change)
    484483{
    485484        bee_t *bee = ic->bee;
     
    493492        bu->nick = g_strdup(nick);
    494493
    495         if (bee->ui->user_nick_hint) {
     494        if (change && bee->ui->user_nick_change) {
     495                bee->ui->user_nick_change(bee, bu, nick);
     496        } else if (!change && bee->ui->user_nick_hint) {
    496497                bee->ui->user_nick_hint(bee, bu, nick);
    497498        }
    498499}
    499500
     501/* Soft variant, for newly created users. Does nothing if it's already online */
     502void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick)
     503{
     504        buddy_nick_hint_or_change(ic, handle, nick, FALSE);
     505}
     506
     507/* Hard variant, always changes the nick */
     508void imcb_buddy_nick_change(struct im_connection *ic, const char *handle, const char *nick)
     509{
     510        buddy_nick_hint_or_change(ic, handle, nick, TRUE);
     511}
    500512
    501513struct imcb_ask_cb_data {
  • protocols/nogaim.h

    r459dec8 rdf701918  
    325325G_MODULE_EXPORT void imcb_rename_buddy(struct im_connection *ic, const char *handle, const char *realname);
    326326G_MODULE_EXPORT void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick);
     327G_MODULE_EXPORT void imcb_buddy_nick_change(struct im_connection *ic, const char *handle, const char *nick);
    327328G_MODULE_EXPORT void imcb_buddy_action_response(bee_user_t *bu, const char *action, char * const args[], void *data);
    328329
Note: See TracChangeset for help on using the changeset viewer.