Changeset 29ff5c2 for irc_im.c


Ignore:
Timestamp:
2015-11-21T00:01:50Z (8 years ago)
Author:
dequis <dx@…>
Parents:
e4f08bf (diff), 8fdeaa5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feat/hip-cat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_im.c

    re4f08bf r29ff5c2  
    118118        if (bu->flags & BEE_USER_AWAY || !(bu->flags & BEE_USER_ONLINE)) {
    119119                iu->flags |= IRC_USER_AWAY;
     120        }
     121
     122        if ((irc->caps & CAP_AWAY_NOTIFY) &&
     123            ((bu->flags & BEE_USER_AWAY) != (old->flags & BEE_USER_AWAY) ||
     124             (bu->flags & BEE_USER_ONLINE) != (old->flags & BEE_USER_ONLINE))) {
     125                irc_send_away_notify(iu);
    120126        }
    121127
     
    201207}
    202208
    203 static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at)
     209static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, guint32 flags, time_t sent_at)
    204210{
    205211        irc_t *irc = bee->ui_data;
    206212        irc_user_t *iu = (irc_user_t *) bu->ui_data;
     213        irc_user_t *src_iu = iu;
     214        irc_user_t *dst_iu = irc->user;
    207215        const char *dst;
    208216        char *prefix = NULL;
    209217        char *wrapped, *ts = NULL;
    210218        char *msg = g_strdup(msg_);
     219        char *message_type = "PRIVMSG";
    211220        GSList *l;
    212221
     
    216225
    217226        dst = irc_user_msgdest(iu);
    218         if (dst != irc->user->nick) {
    219                 /* if not messaging directly, call user by name */
    220                 prefix = g_strdup_printf("%s%s%s", irc->user->nick, set_getstr(&bee->set, "to_char"), ts ? : "");
     227
     228        if (flags & OPT_SELFMESSAGE) {
     229                char *setting = set_getstr(&irc->b->set, "self_messages");
     230
     231                if (is_bool(setting)) {
     232                        if (bool2int(setting)) {
     233                                /* set to true, send it with src/dst flipped */
     234                               
     235                                dst_iu = iu;
     236                                src_iu = irc->user;
     237
     238                                if (dst == irc->user->nick) {
     239                                        dst = dst_iu->nick;
     240                                }
     241                        } else {
     242                                /* set to false, skip the message completely */
     243                                goto cleanup;
     244                        }
     245                } else if (g_strncasecmp(setting, "prefix", 6) == 0) {
     246                        /* third state, prefix, loosely imitates the znc privmsg_prefix module */
     247
     248                        g_free(msg);
     249                        if (g_strncasecmp(msg_, "/me ", 4) == 0) {
     250                                msg = g_strdup_printf("/me -> %s", msg_ + 4);
     251                        } else {
     252                                msg = g_strdup_printf("-> %s", msg_);
     253                        }
     254
     255                        if (g_strcasecmp(setting, "prefix_notice") == 0) {
     256                                message_type = "NOTICE";
     257                        }
     258                }
     259
     260        }
     261
     262        if (dst != dst_iu->nick) {
     263                /* if not messaging directly (control channel), call user by name */
     264                prefix = g_strdup_printf("%s%s%s", dst_iu->nick, set_getstr(&bee->set, "to_char"), ts ? : "");
    221265        } else {
    222266                prefix = ts;
     
    249293
    250294        wrapped = word_wrap(msg, 425);
    251         irc_send_msg(iu, "PRIVMSG", dst, wrapped, prefix);
     295        irc_send_msg(src_iu, message_type, dst, wrapped, prefix);
    252296        g_free(wrapped);
    253297
     
    260304}
    261305
    262 static gboolean bee_irc_user_typing(bee_t *bee, bee_user_t *bu, uint32_t flags)
     306static gboolean bee_irc_user_typing(bee_t *bee, bee_user_t *bu, guint32 flags)
    263307{
    264308        irc_t *irc = (irc_t *) bee->ui_data;
     
    646690}
    647691
    648 static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at)
     692static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, guint32 flags, time_t sent_at)
    649693{
    650694        irc_t *irc = bee->ui_data;
    651         irc_user_t *iu = bu->ui_data;
     695        irc_user_t *iu = flags & OPT_SELFMESSAGE ? irc->user : bu->ui_data;
    652696        irc_channel_t *ic = c->ui_data;
    653697        char *wrapped, *ts = NULL;
     
    683727}
    684728
    685 static gboolean bee_irc_chat_remove_user(bee_t *bee, struct groupchat *c, bee_user_t *bu)
     729static gboolean bee_irc_chat_remove_user(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *reason)
    686730{
    687731        irc_t *irc = bee->ui_data;
     
    695739           using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into
    696740           a broken state around here. */
    697         irc_channel_del_user(ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, NULL);
     741        irc_channel_del_user(ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, reason);
    698742
    699743        return TRUE;
     
    867911            (room = set_getstr(&ic->set, "room")) &&
    868912            (acc = account_get(ic->irc->b, acc_s)) &&
    869             acc->ic && acc->prpl->chat_join) {
     913            acc->ic && (acc->ic->flags & OPT_LOGGED_IN) &&
     914            acc->prpl->chat_join) {
    870915                char *nick;
    871916
     
    893938        }
    894939
    895         /* Remove the reference. We don't need it anymore. */
    896         ic->data = NULL;
     940        if (!(ic->flags & IRC_CHANNEL_TEMP)) {
     941                /* Remove the reference.
     942                 * We only need it for temp channels that are being freed */
     943                ic->data = NULL;
     944        }
    897945
    898946        return TRUE;
Note: See TracChangeset for help on using the changeset viewer.