static void
infinoted_plugin_document_stream_chat_add_message(
  InfinotedPluginDocumentStreamStream* stream,
  const gchar* message,
  gsize len)
{
  g_assert(stream->user != NULL);

  inf_signal_handlers_block_by_func(
    G_OBJECT(stream->buffer),
    G_CALLBACK(infinoted_plugin_document_stream_chat_add_message_cb),
    stream
  );

  inf_chat_buffer_add_message(
    INF_CHAT_BUFFER(stream->buffer),
    stream->user,
    message,
    len,
    time(NULL),
    0
  );

  inf_signal_handlers_unblock_by_func(
    G_OBJECT(stream->buffer),
    G_CALLBACK(infinoted_plugin_document_stream_chat_add_message_cb),
    stream
  );
}
Esempio n. 2
0
static void
inf_chat_buffer_get_property(GObject* object,
                             guint prop_id,
                             GValue* value,
                             GParamSpec* pspec)
{
  InfChatBuffer* session;
  InfChatBufferPrivate* priv;

  session = INF_CHAT_BUFFER(object);
  priv = INF_CHAT_BUFFER_PRIVATE(session);

  switch(prop_id)
  {
  case PROP_SIZE:
    g_value_set_uint(value, priv->size);
    break;
  case PROP_MODIFIED:
    g_value_set_boolean(value, priv->modified);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}
static gboolean
infinoted_plugin_note_chat_session_write(InfdStorage* storage,
                                         InfSession* session,
                                         const gchar* path,
                                         gpointer user_data,
                                         GError** error)
{
  return infd_chat_filesystem_format_write(
    INFD_FILESYSTEM_STORAGE(storage),
    path,
    INF_CHAT_BUFFER(inf_session_get_buffer(session)),
    error
  );
}
Esempio n. 4
0
static void
inf_chat_test_subscribe_finished_cb(InfcNodeRequest* request,
                                    const InfcBrowserIter* iter,
                                    gpointer user_data)
{
  InfTestChat* test;
  InfSession* session;
  test = (InfTestChat*)user_data;

  printf("Subscription successful, waiting for synchronization...\n");

  session = infc_session_proxy_get_session(
    infc_browser_get_chat_session(test->browser));

  test->buffer = INF_CHAT_BUFFER(inf_session_get_buffer(session));

  /* TODO: Show backlog after during/after synchronization */

  g_signal_connect_after(
    G_OBJECT(session),
    "receive-message",
    G_CALLBACK(inf_chat_test_buffer_receive_message_cb),
    test
  );

  g_signal_connect_after(
    G_OBJECT(session),
    "synchronization-complete",
    G_CALLBACK(inf_chat_test_session_synchronization_complete_cb),
    test
  );

  g_signal_connect_after(
    G_OBJECT(session),
    "synchronization-failed",
    G_CALLBACK(inf_chat_test_session_synchronization_failed_cb),
    test
  );

  /* This can happen when the server disables the chat without being
   * shutdown. */
  g_signal_connect_after(
    G_OBJECT(session),
    "close",
    G_CALLBACK(inf_chat_test_session_close_cb),
    test
  );
}
Esempio n. 5
0
static void
inf_chat_buffer_buffer_set_modified(InfBuffer* buffer,
                                    gboolean modified)
{
  InfChatBuffer* chat_buffer;
  InfChatBufferPrivate* priv;

  chat_buffer = INF_CHAT_BUFFER(buffer);
  priv = INF_CHAT_BUFFER_PRIVATE(chat_buffer);

  if(priv->modified != modified)
  {
    priv->modified = modified;
    g_object_notify(G_OBJECT(buffer), "modified");
  }
}
Esempio n. 6
0
static void
inf_chat_buffer_init(GTypeInstance* instance,
                     gpointer g_class)
{
  InfChatBuffer* buffer;
  InfChatBufferPrivate* priv;

  buffer = INF_CHAT_BUFFER(instance);
  priv = INF_CHAT_BUFFER_PRIVATE(buffer);

  priv->messages = NULL;
  priv->alloc_messages = 0;
  priv->num_messages = 0;
  priv->first_message = 0;
  priv->size = 256;
  priv->modified = FALSE;
}
Esempio n. 7
0
static void
inf_chat_buffer_finalize(GObject* object)
{
  InfChatBuffer* buffer;
  InfChatBufferPrivate* priv;
  guint i;

  buffer = INF_CHAT_BUFFER(object);
  priv = INF_CHAT_BUFFER_PRIVATE(buffer);

  /* Note that the messages array is not necessarily filled from its
   * beginning - we might have preallocated some space for prepending
   * entries. */
  for(i = 0; i < priv->num_messages; ++i)
    g_free(priv->messages[(priv->first_message + i) % priv->size].text);
  g_free(priv->messages);

  G_OBJECT_CLASS(parent_class)->finalize(object);
}
static void
infinoted_plugin_document_stream_sync_chat(
  InfinotedPluginDocumentStreamStream* stream)
{
  InfChatBuffer* buffer;
  guint n_messages;
  guint i;
  const InfChatBufferMessage* message;

  g_assert(INF_IS_CHAT_BUFFER(stream->buffer));
  buffer = INF_CHAT_BUFFER(stream->buffer);
  n_messages = inf_chat_buffer_get_n_messages(buffer);

  for(i = 0; i < n_messages; ++i)
  {
    message = inf_chat_buffer_get_message(buffer, i);
    infinoted_plugin_document_stream_chat_send_message(stream, message);
  }
}