Added SQLite persistent storage for friend requests.

This commit is contained in:
Håvard Pettersson
2014-10-04 19:42:30 +02:00
parent b0e91b7b5b
commit 225e576d57
10 changed files with 578 additions and 77 deletions

View File

@ -33,6 +33,7 @@
#include "twc-message-queue.h"
#include "twc-chat.h"
#include "twc-tox-callbacks.h"
#include "twc-sqlite.h"
#include "twc-utils.h"
#include "twc-profile.h"
@ -176,7 +177,6 @@ twc_profile_new(const char *name)
profile->tox_online = false;
profile->chats = twc_list_new();
profile->friend_requests = twc_list_new();
profile->message_queues = weechat_hashtable_new(32,
WEECHAT_HASHTABLE_INTEGER,
WEECHAT_HASHTABLE_POINTER,
@ -213,15 +213,6 @@ twc_profile_load(struct t_twc_profile *profile)
weechat_prefix("network"), weechat_plugin->name,
profile->name);
// TODO: this does nothing
if (profile->friend_requests->count > 0)
{
weechat_printf(profile->buffer,
"%sYou have %d pending friend requests.",
weechat_prefix("network"),
profile->friend_requests->count);
}
// create Tox
profile->tox = tox_new(NULL);
if (!(profile->tox))
@ -233,6 +224,7 @@ twc_profile_load(struct t_twc_profile *profile)
}
// try loading Tox saved data
// TODO: this can return -1 even if it does not fail
if (twc_profile_load_data(profile) == -1)
{
// we failed to load - set some defaults
@ -247,6 +239,18 @@ twc_profile_load(struct t_twc_profile *profile)
(uint8_t *)name, strlen(name));
}
// register with sqlite
twc_sqlite_add_profile(profile);
int friend_request_count = twc_sqlite_friend_request_count(profile);
if (friend_request_count > 0)
{
weechat_printf(profile->buffer,
"%sYou have %d pending friend requests.",
weechat_prefix("network"),
friend_request_count);
}
// bootstrap DHT
// TODO: add count to config
int bootstrap_node_count = 5;
@ -404,6 +408,7 @@ twc_profile_delete(struct t_twc_profile *profile,
{
char *data_path = twc_profile_expanded_data_path(profile);
twc_sqlite_delete_profile(profile);
twc_profile_free(profile);
if (delete_data)
@ -427,7 +432,6 @@ twc_profile_free(struct t_twc_profile *profile)
}
// free things
twc_friend_request_free_profile(profile);
twc_chat_free_profile(profile);
twc_message_queue_free_profile(profile);
free(profile->name);