1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Moved chat state handling code to chat_state.c

This commit is contained in:
James Booth 2016-07-24 13:56:11 +01:00
parent 7c593c2780
commit 8d8f2f290d
6 changed files with 45 additions and 42 deletions

View File

@ -33,11 +33,14 @@
*/
#include <stdlib.h>
#include <assert.h>
#include <glib.h>
#include "chat_state.h"
#include "chat_session.h"
#include "window_list.h"
#include "ui/win_types.h"
#include "xmpp/xmpp.h"
#include "config/preferences.h"
@ -149,6 +152,40 @@ chat_state_gone(const char *const barejid, ChatState *state)
}
}
void
chat_state_idle(void)
{
jabber_conn_status_t status = connection_get_status();
if (status == JABBER_CONNECTED) {
GSList *recipients = wins_get_chat_recipients();
GSList *curr = recipients;
while (curr) {
char *barejid = curr->data;
ProfChatWin *chatwin = wins_get_chat(barejid);
chat_state_handle_idle(chatwin->barejid, chatwin->state);
curr = g_slist_next(curr);
}
if (recipients) {
g_slist_free(recipients);
}
}
}
void
chat_state_activity(void)
{
jabber_conn_status_t status = connection_get_status();
ProfWin *current = wins_get_current();
if ((status == JABBER_CONNECTED) && (current->type == WIN_CHAT)) {
ProfChatWin *chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
chat_state_handle_typing(chatwin->barejid, chatwin->state);
}
}
static void
_send_if_supported(const char *const barejid, void (*send_func)(const char *const))
{

View File

@ -53,6 +53,9 @@ typedef struct prof_chat_state_t {
ChatState* chat_state_new(void);
void chat_state_free(ChatState *state);
void chat_state_idle(void);
void chat_state_activity(void);
void chat_state_handle_idle(const char *const barejid, ChatState *state);
void chat_state_handle_typing(const char *const barejid, ChatState *state);
void chat_state_active(ChatState *state);

View File

@ -35,6 +35,8 @@
#ifndef CLIENT_EVENTS_H
#define CLIENT_EVENTS_H
#include "xmpp/xmpp.h"
jabber_conn_status_t cl_ev_connect_jid(const char *const jid, const char *const passwd, const char *const altdomain, const int port, const char *const tls_policy);
jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);

View File

@ -44,7 +44,6 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
@ -145,40 +144,6 @@ prof_set_quit(void)
force_quit = TRUE;
}
void
prof_handle_idle(void)
{
jabber_conn_status_t status = connection_get_status();
if (status == JABBER_CONNECTED) {
GSList *recipients = wins_get_chat_recipients();
GSList *curr = recipients;
while (curr) {
char *barejid = curr->data;
ProfChatWin *chatwin = wins_get_chat(barejid);
chat_state_handle_idle(chatwin->barejid, chatwin->state);
curr = g_slist_next(curr);
}
if (recipients) {
g_slist_free(recipients);
}
}
}
void
prof_handle_activity(void)
{
jabber_conn_status_t status = connection_get_status();
ProfWin *current = wins_get_current();
if ((status == JABBER_CONNECTED) && (current->type == WIN_CHAT)) {
ProfChatWin *chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
chat_state_handle_typing(chatwin->barejid, chatwin->state);
}
}
static void
_connect_default(const char *const account)
{

View File

@ -37,13 +37,8 @@
#include <pthread.h>
#include "resource.h"
#include "xmpp/xmpp.h"
void prof_run(char *log_level, char *account_name);
void prof_handle_idle(void);
void prof_handle_activity(void);
gboolean prof_process_input(char *inp);
void prof_set_quit(void);

View File

@ -54,6 +54,7 @@
#endif
#include "command/cmd_ac.h"
#include "chat_state.h"
#include "common.h"
#include "config/accounts.h"
#include "config/preferences.h"
@ -164,7 +165,7 @@ inp_readline(void)
rl_line_buffer[0] != '/' &&
rl_line_buffer[0] != '\0' &&
rl_line_buffer[0] != '\n') {
prof_handle_activity();
chat_state_activity();
}
ui_reset_idle_time();
@ -174,7 +175,7 @@ inp_readline(void)
inp_nonblocking(TRUE);
} else {
inp_nonblocking(FALSE);
prof_handle_idle();
chat_state_idle();
}
if (inp_line) {