lastmsg/lastmsg.c
author Mikael Berthe <mikael@lilotux.net>
Sat, 13 Oct 2012 14:34:18 +0200
changeset 44 3f94f3522960
parent 40 5cd4b42ada91
permissions -rw-r--r--
[killpresence] Add a command /probe to send a presence probe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
/*
37
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     2
 *  Module "lastmsg"    -- adds a /lastmsg command
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     3
 *                         Displays last personal messages
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     4
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     5
 *  This modules stores messages received in a MUC room while
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     6
 *  you are away (or not available) if they contain your nickname.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     7
 *  When you're back, you can display them in the status window with
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     8
 *  the /lastmsg command.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     9
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    10
 * Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net>
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    11
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    12
 * This module is free software; you can redistribute it and/or modify
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    13
 * it under the terms of the GNU General Public License as published by
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    14
 * the Free Software Foundation; either version 2 of the License, or (at
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    15
 * your option) any later version.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    16
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    17
 * This program is distributed in the hope that it will be useful, but
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    18
 * WITHOUT ANY WARRANTY; without even the implied warranty of
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    20
 * General Public License for more details.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    21
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    22
 * You should have received a copy of the GNU General Public License
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    24
 */
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
#include <mcabber/modules.h>
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
#include <mcabber/commands.h>
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
#include <mcabber/hooks.h>
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    29
#include <mcabber/screen.h>
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
static void lastmsg_init(void);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
static void lastmsg_uninit(void);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
/* Module description */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
module_info_t info_lastmsg = {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
        .branch         = MCABBER_BRANCH,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
        .api            = MCABBER_API_VERSION,
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
    38
        .version        = "0.02",
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
        .description    = "Add a command /lastmsg",
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
        .requires       = NULL,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
        .init           = lastmsg_init,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
        .uninit         = lastmsg_uninit,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
        .next           = NULL,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
};
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
40
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    46
#ifdef MCABBER_API_HAVE_CMD_ID
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    47
static gpointer lastmsg_cmdid;
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    48
#endif
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    49
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
static GSList *lastmsg_list;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    52
static guint last_message_hid, last_status_hid;
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    53
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
struct lastm_T {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
    gchar *mucname;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
    gchar *nickname;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
    gchar *msg;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    58
};
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
static void do_lastmsg(char *args)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
{
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    62
  GSList *li;
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    63
  guint count = 0;
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    64
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    65
  if (!lastmsg_list) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    66
    scr_log_print(LPRINT_NORMAL, "You have no new message.");
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    67
    return;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    68
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    69
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    70
  for (li = lastmsg_list; li ; li = g_slist_next(li)) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    71
    struct lastm_T *lastm_item = li->data;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    72
    scr_LogPrint(LPRINT_NORMAL, "In <#%s>, \"%s\" said:\n%s",
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    73
                 lastm_item->mucname, lastm_item->nickname,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    74
                 lastm_item->msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    75
    g_free(lastm_item->mucname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    76
    g_free(lastm_item->nickname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    77
    g_free(lastm_item->msg);
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    78
    count++;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    79
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    80
  g_slist_free(lastmsg_list);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    81
  lastmsg_list = NULL;
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    82
  if (count*2 > scr_getlogwinheight()) {
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    83
    scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    84
    scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE,
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    85
                                   ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max);
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    86
  }
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    87
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    88
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    89
static guint last_message_hh(const gchar *hookname, hk_arg_t *args,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    90
                             gpointer userdata)
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    91
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    92
  enum imstatus status;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    93
  const gchar *bjid, *res, *msg;
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
    94
  gboolean muc = FALSE, urgent = FALSE;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    95
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    96
  status = xmpp_getstatus();
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    97
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    98
  if (status != notavail && status != away)
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
    99
    return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   100
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   101
  bjid = res = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   102
  msg = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   103
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   104
  for ( ; args->name; args++) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   105
    if (!g_strcmp0(args->name, "jid"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   106
      bjid = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   107
    else if (!g_strcmp0(args->name, "resource"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   108
      res = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   109
    else if (!g_strcmp0(args->name, "message"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   110
      msg = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   111
    else if (!g_strcmp0(args->name, "groupchat")) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   112
      if (!g_strcmp0(args->value, "true"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   113
        muc = TRUE;
18
fb84350decc5 [lastmsg] Fix usage of hook-post-message-in parameters
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   114
    } else if (!g_strcmp0(args->name, "attention")) {
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   115
      if (!g_strcmp0(args->value, "true"))
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   116
        urgent = TRUE;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   117
    }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   118
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   119
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   120
  if (muc && urgent && bjid && res && msg) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   121
    struct lastm_T *lastm_item;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   122
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
    lastm_item = g_new(struct lastm_T, 1);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
    lastm_item->mucname  = g_strdup(bjid);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   125
    lastm_item->nickname = g_strdup(res);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
    lastm_item->msg      = g_strdup(msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   127
    lastmsg_list = g_slist_append(lastmsg_list, lastm_item);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   128
  }
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   129
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   132
static guint last_status_hh(const gchar *hookname, hk_arg_t *args,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   133
                            gpointer userdata)
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   134
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   135
  gboolean not_away = FALSE;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   136
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   137
  for ( ; args->name; args++) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   138
    if (!g_strcmp0(args->name, "new_status")) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
      if (args->value &&
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
          (args->value[0] != imstatus2char[away]) &&
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
          (args->value[0] != imstatus2char[notavail])) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   142
        not_away = TRUE;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   143
        break;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   144
      }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
    }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
  }
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   147
  if (!not_away || !lastmsg_list)
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   148
    return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   149
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
  scr_log_print(LPRINT_NORMAL, "Looks like you're back...");
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
  scr_log_print(LPRINT_NORMAL, "I've got news for you, use /lastmsg to "
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
                "read your messages!");
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   153
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   154
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   155
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   156
/* Initialization */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   157
static void lastmsg_init(void)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   158
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   159
  /* Add command */
40
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   160
#ifdef MCABBER_API_HAVE_CMD_ID
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   161
  lastmsg_cmdid = cmd_add("lastmsg", "Display last missed messages", 0, 0,
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   162
                          do_lastmsg, NULL);
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   163
#else
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   164
  cmd_add("lastmsg", "Display last missed messages", 0, 0, do_lastmsg, NULL);
40
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   165
#endif
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   166
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   167
  /* Add hook handlers */
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   168
  last_message_hid = hk_add_handler(last_message_hh, HOOK_POST_MESSAGE_IN,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   169
                                    G_PRIORITY_DEFAULT_IDLE, NULL);
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   170
  last_status_hid  = hk_add_handler(last_status_hh, HOOK_MY_STATUS_CHANGE,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   171
                                    G_PRIORITY_DEFAULT_IDLE, NULL);
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   172
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   173
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   174
/* Uninitialization */
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   175
static void lastmsg_uninit(void)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   176
{
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   177
  GSList *li;
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   178
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   179
  /* Unregister command */
40
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   180
#ifdef MCABBER_API_HAVE_CMD_ID
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   181
  cmd_del(lastmsg_cmdid);
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   182
#else
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   183
  cmd_del("lastmsg");
40
5cd4b42ada91 Sync with current mcabber API
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
   184
#endif
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   185
  /* Unregister handlers */
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   186
  hk_del_handler(HOOK_POST_MESSAGE_IN, last_message_hid);
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   187
  hk_del_handler(HOOK_MY_STATUS_CHANGE, last_status_hid);
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   188
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   189
  /* Clean up data */
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   190
  for (li = lastmsg_list; li ; li = g_slist_next(li)) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   191
    struct lastm_T *lastm_item = li->data;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   192
    g_free(lastm_item->mucname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   193
    g_free(lastm_item->nickname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   194
    g_free(lastm_item->msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   195
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   196
  g_slist_free(lastmsg_list);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   197
  lastmsg_list = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   198
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   199
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   200
/* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */