Changeset 830864d for irc_channel.c


Ignore:
Timestamp:
2015-03-15T09:31:18Z (6 years ago)
Author:
dequis <dx@…>
Children:
ac6855b3
Parents:
c0e4c22
git-author:
dequis <dx@…> (05-03-15 10:31:24)
git-committer:
dequis <dx@…> (15-03-15 09:31:18)
Message:

WIP placeholder channels with hipchat implementation

i was going to clean this up and split in two commits but uhhh...
maybe some other day, i'm tired now

not very tested and i'm not 100% happy about the design, but sucks way
less than what i had in the hip-cat branch

feedback still appreciated.

this adds channels to the channel list without creating groupchats for
them, allowing users to /join them. what the hip-cat branch did before
but with proper api and hopefully less dumb behavior

it still 'leaks' them intentionally, just like it did before, but now it
prevents saving them to the xml so yay

also slightly improved channel name generation, refactored
bee_irc_chat_name_hint into three or four functions, and so on

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_channel.c

    rc0e4c22 r830864d  
    276276                if (ic->irc->status & USTATUS_SHUTDOWN) {
    277277                        /* Don't do anything fancy when we're shutting down anyway. */
    278                 } else if (ic->flags & IRC_CHANNEL_TEMP) {
     278                } else if (ic->flags & IRC_CHANNEL_TEMP && !(ic->flags & IRC_CHANNEL_KEEP_PLACEHOLDER)) {
    279279                        irc_channel_free_soon(ic);
    280280                } else {
     
    556556}
    557557
     558gboolean irc_channel_is_unused(bee_t *bee, char *name)
     559{
     560        char *type, *chat_type;
     561        irc_channel_t *oic;
     562
     563        if (!irc_channel_name_ok(name)) {
     564                return FALSE;
     565        }
     566
     567        if (!(oic = irc_channel_by_name(bee->ui_data, name))) {
     568                return TRUE;
     569        }
     570
     571        type = set_getstr(&oic->set, "type");
     572        chat_type = set_getstr(&oic->set, "chat_type");
     573
     574        if (type && chat_type && oic->data == FALSE &&
     575            strcmp(type, "chat") == 0 &&
     576            strcmp(chat_type, "groupchat") == 0) {
     577                /* There's a channel with this name already, but it looks
     578                   like it's not in use yet. Most likely the IRC client
     579                   rejoined the channel after a reconnect. Remove it so
     580                   we can reuse its name. */
     581                irc_channel_free(oic);
     582                return TRUE;
     583        }
     584
     585        return FALSE;
     586}
     587
     588char *irc_channel_name_gen(bee_t *bee, const char *hint)
     589{
     590        char name[MAX_NICK_LENGTH + 1] = { 0 };
     591
     592        name[0] = '#';
     593        strncpy(name + 1, hint, MAX_NICK_LENGTH - 1);
     594        name[MAX_NICK_LENGTH] = '\0';
     595
     596        irc_channel_name_strip(name);
     597
     598        if (set_getbool(&bee->set, "lcnicks")) {
     599                nick_lc(bee->ui_data, name + 1);
     600        }
     601
     602        while (!irc_channel_is_unused(bee, name)) {
     603                underscore_dedupe(name);
     604        }
     605
     606        return g_strdup(name);
     607}
     608
     609gboolean irc_channel_name_hint(irc_channel_t *ic, const char *name)
     610{
     611        irc_t *irc = ic->irc;
     612        char *full_name;
     613
     614        /* Don't rename a channel if the user's in it already. */
     615        if (ic->flags & IRC_CHANNEL_JOINED) {
     616                return FALSE;
     617        }
     618
     619        if (!(full_name = irc_channel_name_gen(irc->b, name))) {
     620                return FALSE;
     621        }
     622
     623        g_free(ic->name);
     624        ic->name = full_name;
     625
     626        return TRUE;
     627}
     628
    558629static gint irc_channel_user_cmp(gconstpointer a_, gconstpointer b_)
    559630{
Note: See TracChangeset for help on using the changeset viewer.