/* Jungle Monkey
 * Copyright (C) 1999-2001  The Regents of the University of Michigan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _JMCHAT_H
#define _JMCHAT_H

#include <glib.h>
#include "btp/btp.h"
#include "util/util.h"

#define JMCHAT_UPDATE_TIME	  180000
#define JMCHAT_UPDATE_TIME_MAX     10000
#define JMCHAT_TIMEOUT_TIME	  (3 * JMCHAT_UPDATE_TIME)
#define JMCHAT_MAX_MEMBERS	  4096  /* TODO: This isn't enforced... */

typedef struct _JMChat JMChat;
typedef struct _JMChatMember JMChatMember;

typedef enum 
{
  JMCHAT_JOIN,
  JMCHAT_LEAVE,
  JMCHAT_LEAVE_TIMEOUT,
  JMCHAT_UPDATE,
  JMCHAT_SAY

} JMChatType;


typedef void (*JMChatInfoFunc)(JMChat* chat, JMChatMember* member,
			       JMChatType type, gchar* text1, gchar* text2,
			       gpointer user_data);
typedef void (*JMChatErrorFunc)(JMChat* chat, gpointer user_data);


struct _JMChat
{
  BPeer*   peer;
  Btp*     btp;
  GURL*    url;
  gboolean is_local;
  gboolean is_down;

  gchar*   nick;
  GSList*  members;
  guint    num_members;

  guint    update_timer;
  Timeval  update_tv;

  guint    gc_timer;

  JMChatInfoFunc  info_func;
  JMChatErrorFunc error_func;
  gpointer 	  user_data;
};


struct _JMChatMember
{
  gchar*    nick;
  gboolean  is_me;
  Timeval   last_update;

};



JMChat*   jmchat_create (BPeer* bpeer, const gchar* name, const gchar* nick);
JMChat*	  jmchat_join (BPeer* bpeer, const GURL* url, const gchar* nick);
JMChat*	  jmchat_setup (BPeer* bpeer, const GURL* url, const gchar* nick);
gboolean  jmchat_rejoin (JMChat* chat);	/* FALSE = success */
void 	  jmchat_leave (JMChat* chat);
void      jmchat_delete (JMChat* jmchat);

void	  jmchat_say (JMChat* chat, gchar* message, gboolean emote);
JMChatMember* jmchat_get_member (JMChat* chat, const gchar* nick);

#define   jmchat_is_up(C)   ((C)->btp != NULL)
#define   jmchat_is_down(C) ((C)->is_down)

#endif /* _JMCHAT_H */


syntax highlighted by Code2HTML, v. 0.9.1