Changeset 830864d for irc_im.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_im.c

    rc0e4c22 r830864d  
    609609}
    610610
     611static gboolean bee_irc_chat_placeholder_new(bee_t *bee, struct im_connection *ic, const char *handle,
     612                                             const char *name, const char *topic)
     613{
     614        irc_t *irc = bee->ui_data;
     615        irc_channel_t *ircc;
     616        char *full_name = irc_channel_name_gen(bee, name);
     617
     618        ircc = irc_channel_new(irc, full_name);
     619
     620        set_setstr(&ircc->set, "type", "chat");
     621        set_setstr(&ircc->set, "chat_type", "placeholder");
     622        set_setstr(&ircc->set, "account", ic->acc->tag);
     623        set_setstr(&ircc->set, "room", (char *) handle);
     624
     625        irc_channel_set_topic(ircc, topic, NULL);
     626
     627        g_free(full_name);
     628
     629        return TRUE;
     630}
     631
    611632static gboolean bee_irc_chat_log(bee_t *bee, struct groupchat *c, const char *text)
    612633{
     
    701722static gboolean bee_irc_chat_name_hint(bee_t *bee, struct groupchat *c, const char *name)
    702723{
    703         irc_t *irc = bee->ui_data;
    704         irc_channel_t *ic = c->ui_data, *oic;
    705         char stripped[MAX_NICK_LENGTH + 1], *full_name;
    706 
    707         if (ic == NULL) {
    708                 return FALSE;
    709         }
    710 
    711         /* Don't rename a channel if the user's in it already. */
    712         if (ic->flags & IRC_CHANNEL_JOINED) {
    713                 return FALSE;
    714         }
    715 
    716         strncpy(stripped, name, MAX_NICK_LENGTH);
    717         stripped[MAX_NICK_LENGTH] = '\0';
    718         irc_channel_name_strip(stripped);
    719         if (set_getbool(&bee->set, "lcnicks")) {
    720                 nick_lc(irc, stripped);
    721         }
    722 
    723         if (stripped[0] == '\0') {
    724                 return FALSE;
    725         }
    726 
    727         full_name = g_strdup_printf("#%s", stripped);
    728         if ((oic = irc_channel_by_name(irc, full_name))) {
    729                 char *type, *chat_type;
    730 
    731                 type = set_getstr(&oic->set, "type");
    732                 chat_type = set_getstr(&oic->set, "chat_type");
    733 
    734                 if (type && chat_type && oic->data == FALSE &&
    735                     strcmp(type, "chat") == 0 &&
    736                     strcmp(chat_type, "groupchat") == 0) {
    737                         /* There's a channel with this name already, but it looks
    738                            like it's not in use yet. Most likely the IRC client
    739                            rejoined the channel after a reconnect. Remove it so
    740                            we can reuse its name. */
    741                         irc_channel_free(oic);
    742                 } else {
    743                         g_free(full_name);
    744                         return FALSE;
    745                 }
    746         }
    747 
    748         g_free(ic->name);
    749         ic->name = full_name;
    750 
    751         return TRUE;
     724        return irc_channel_name_hint(c->ui_data, name);
    752725}
    753726
     
    877850static gboolean bee_irc_channel_chat_join(irc_channel_t *ic)
    878851{
    879         char *acc_s, *room;
     852        char *acc_s, *room, *chat_type;
    880853        account_t *acc;
    881854
    882         if (strcmp(set_getstr(&ic->set, "chat_type"), "room") != 0) {
     855        chat_type = set_getstr(&ic->set, "chat_type");
     856
     857        if (strcmp(chat_type, "room") != 0 && strcmp(chat_type, "placeholder") != 0) {
    883858                return TRUE;
    884859        }
     
    10361011        struct irc_channel *ic = set->data;
    10371012
     1013        ic->flags &= ~(IRC_CHANNEL_TEMP | IRC_CHANNEL_KEEP_PLACEHOLDER);
     1014
    10381015        if (strcmp(value, "groupchat") == 0) {
    10391016                ic->flags |= IRC_CHANNEL_TEMP;
    10401017        } else if (strcmp(value, "room") == 0) {
    1041                 ic->flags &= ~IRC_CHANNEL_TEMP;
     1018                // beep boop
     1019        } else if (strcmp(value, "placeholder") == 0) {
     1020                ic->flags |= IRC_CHANNEL_TEMP | IRC_CHANNEL_KEEP_PLACEHOLDER;
    10421021        } else {
    10431022                return NULL;
     
    11231102        bee_irc_chat_new,
    11241103        bee_irc_chat_free,
     1104        bee_irc_chat_placeholder_new,
    11251105        bee_irc_chat_log,
    11261106        bee_irc_chat_msg,
Note: See TracChangeset for help on using the changeset viewer.