about summary refs log tree commit diff stats
path: root/html
ModeNameSize
-rw-r--r--000organization.cc.html17887log stats plain blame
-rw-r--r--001help.cc.html47478log stats plain blame
-rw-r--r--002test.cc.html22246log stats plain blame
-rw-r--r--003trace.cc.html72980log stats plain blame
-rw-r--r--003trace.test.cc.html29409log stats plain blame
-rw-r--r--010vm.cc.html154560log stats plain blame
-rw-r--r--011load.cc.html71786log stats plain blame
-rw-r--r--012transform.cc.html18570log stats plain blame
-rw-r--r--013update_operation.cc.html8903log stats plain blame
-rw-r--r--014literal_string.cc.html35940log stats plain blame
-rw-r--r--015literal_noninteger.cc.html10759log stats plain blame
-rw-r--r--016dilated_reagent.cc.html28964log stats plain blame
-rw-r--r--017parse_tree.cc.html18760log stats plain blame
-rw-r--r--018type_abbreviations.cc.html37086log stats plain blame
-rw-r--r--020run.cc.html82782log stats plain blame
-rw-r--r--021check_instruction.cc.html55056log stats plain blame
-rw-r--r--022arithmetic.cc.html165182log stats plain blame
-rw-r--r--023boolean.cc.html34817log stats plain blame
-rw-r--r--024jump.cc.html35334log stats plain blame
-rw-r--r--025compare.cc.html105617log stats plain blame
-rw-r--r--026call.cc.html25645log stats plain blame
-rw-r--r--027call_ingredient.cc.html37830log stats plain blame
-rw-r--r--028call_return.cc.html39114log stats plain blame
-rw-r--r--029tools.cc.html52905log stats plain blame
-rw-r--r--030container.cc.html175760log stats plain blame
-rw-r--r--031merge.cc.html49689log stats plain blame
-rw-r--r--032array.cc.html129197log stats plain blame
-rw-r--r--033exclusive_container.cc.html78409log stats plain blame
-rw-r--r--034address.cc.html72671log stats plain blame
-rw-r--r--035lookup.cc.html86832log stats plain blame
-rw-r--r--036refcount.cc.html214016log stats plain blame
-rw-r--r--037abandon.cc.html43240log stats plain blame
-rw-r--r--038new_text.cc.html41280log stats plain blame
-rw-r--r--039location_array.cc.html11908log stats plain blame
-rw-r--r--040brace.cc.html78612log stats plain blame
-rw-r--r--041jump_target.cc.html35414log stats plain blame
-rw-r--r--042name.cc.html64515log stats plain blame
-rw-r--r--043space.cc.html77411log stats plain blame
-rw-r--r--044space_surround.cc.html13619log stats plain blame
-rw-r--r--045closure_name.cc.html38947log stats plain blame
-rw-r--r--046check_type_by_name.cc.html29508log stats plain blame
-rw-r--r--050scenario.cc.html160326log stats plain blame
-rw-r--r--051scenario_test.mu.html7980log stats plain blame
-rw-r--r--052tangle.cc.html67150log stats plain blame
-rw-r--r--053recipe_header.cc.html121495log stats plain blame
-rw-r--r--054static_dispatch.cc.html125243log stats plain blame
-rw-r--r--055shape_shifting_container.cc.html135899log stats plain blame
-rw-r--r--056shape_shifting_recipe.cc.html187631log stats plain blame
-rw-r--r--057immutable.cc.html91318log stats plain blame
-rw-r--r--058to_text.cc.html6140log stats plain blame
-rw-r--r--059to_text.mu.html6534log stats plain blame
-rw-r--r--060rewrite_literal_string.cc.html18490log stats plain blame
-rw-r--r--061text.mu.html162283log stats plain blame
-rw-r--r--062convert_ingredients_to_text.cc.html32217log stats plain blame
-rw-r--r--063array.mu.html23203log stats plain blame
-rw-r--r--064list.mu.html49835log stats plain blame
-rw-r--r--065duplex_list.mu.html107336log stats plain blame
-rw-r--r--066stream.mu.html11266log stats plain blame
-rw-r--r--067random.cc.html6265log stats plain blame
-rw-r--r--068random.mu.html12003log stats plain blame
-rw-r--r--069hash.cc.html63703log stats plain blame
-rw-r--r--070table.mu.html15147log stats plain blame
-rw-r--r--071deep_copy.cc.html80914log stats plain blame
-rw-r--r--072recipe.cc.html80430log stats plain blame
-rw-r--r--073scheduler.cc.html106759log stats plain blame
-rw-r--r--074wait.cc.html110950log stats plain blame
-rw-r--r--075channel.
/*
 * chat_state.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity 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 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity 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 Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include <stdlib.h>
#include <assert.h>

#include <glib.h>

#include "config/preferences.h"
#include "ui/window_list.h"
#include "ui/win_types.h"
#include "xmpp/xmpp.h"
#include "xmpp/chat_state.h"
#include "xmpp/chat_session.h"

#define PAUSED_TIMEOUT   10.0
#define INACTIVE_TIMEOUT 30.0

static void _send_if_supported(const char* const barejid, void (*send_func)(const char* const));

ChatState*
chat_state_new(void)
{
    ChatState* new_state = malloc(sizeof(struct prof_chat_state_t));
    new_state->type = CHAT_STATE_GONE;
    new_state->timer = g_timer_new();

    return new_state;
}

void
chat_state_free(ChatState* state)
{
    if (state && state->timer != NULL) {
        g_timer_destroy(state->timer);
    }
    free(state);
}

void
chat_state_handle_idle(const char* const barejid, ChatState* state)
{
    gdouble elapsed = g_timer_elapsed(state->timer, NULL);

    // TYPING -> PAUSED
    if (state->type == CHAT_STATE_COMPOSING && elapsed > PAUSED_TIMEOUT) {
        state->type = CHAT_STATE_PAUSED;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
            _send_if_supported(barejid, message_send_paused);
        }
        return;
    }

    // PAUSED|ACTIVE -> INACTIVE
    if ((state->type == CHAT_STATE_PAUSED || state->type == CHAT_STATE_ACTIVE) && elapsed > INACTIVE_TIMEOUT) {
        state->type = CHAT_STATE_INACTIVE;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES)) {
            _send_if_supported(barejid, message_send_inactive);
        }
        return;
    }

    // INACTIVE -> GONE
    if (state->type == CHAT_STATE_INACTIVE) {
        if (prefs_get_gone() != 0 && (elapsed > (prefs_get_gone() * 60.0))) {
            ChatSession* session = chat_session_get(barejid);
            if (session) {
                // never move to GONE when resource override
                if (!session->resource_override) {
                    if (prefs_get_boolean(PREF_STATES)) {
                        _send_if_supported(barejid, message_send_gone);
                    }
                    chat_session_remove(barejid);
                    state->type = CHAT_STATE_GONE;
                    g_timer_start(state->timer);
                }
            } else {
                if (prefs_get_boolean(PREF_STATES)) {
                    message_send_gone(barejid);
                }
                state->type = CHAT_STATE_GONE;
                g_timer_start(state->timer);
            }
            return;
        }
    }
}

void
chat_state_handle_typing(const char* const barejid, ChatState* state)
{
    // ACTIVE|INACTIVE|PAUSED|GONE -> COMPOSING
    if (state->type != CHAT_STATE_COMPOSING) {
        state->type = CHAT_STATE_COMPOSING;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
            _send_if_supported(barejid, message_send_composing);
        }
    }
}

void
chat_state_active(ChatState* state)
{
    state->type = CHAT_STATE_ACTIVE;
    g_timer_start(state->timer);
}

void
chat_state_gone(const char* const barejid, ChatState* state)
{
    if (state->type != CHAT_STATE_GONE) {
        if (prefs_get_boolean(PREF_STATES)) {
            _send_if_supported(barejid, message_send_gone);
        }
        state->type = CHAT_STATE_GONE;
        g_timer_start(state->timer);
    }
}

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))
{
    gboolean send = TRUE;
    GString* jid = g_string_new(barejid);
    ChatSession* session = chat_session_get(barejid);
    if (session) {
        if (session->send_states) {
            g_string_append(jid, "/");
            g_string_append(jid, session->resource);
        } else {
            send = FALSE;
        }
    }

    if (send) {
        send_func(jid->str);
    }

    g_string_free(jid, TRUE);
}
51015e851e32400'>plain blame -rw-r--r--real-files.mu.html3850log stats plain blame -rw-r--r--resources.mu203log stats plain blame -rw-r--r--resources.png21555log stats plain blame -rw-r--r--screen.mu.html5545log stats plain blame -rw-r--r--static-dispatch.mu.html4000log stats plain blame d---------subx446log stats plain -rw-r--r--tangle.mu.html5541log stats plain blame -rw-r--r--tangle.png42367log stats plain blame -rw-r--r--tmux-vim-sandbox.png95749log stats plain blame -rw-r--r--tracing-test.mu204log stats plain blame -rw-r--r--tracing-test.png25666log stats plain blame -rw-r--r--unexpected-result.png9357log stats plain blame -rw-r--r--x.mu.html2495log stats plain blame