mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 21:03:27 +01:00
save last online data in blocked list
This commit is contained in:
parent
0254596c73
commit
5da789cc37
@ -98,6 +98,12 @@ static int save_blocklist(char *path)
|
|||||||
tmp.namelength = Blocked_Contacts.list[i].namelength;
|
tmp.namelength = Blocked_Contacts.list[i].namelength;
|
||||||
memcpy(tmp.name, Blocked_Contacts.list[i].name, Blocked_Contacts.list[i].namelength + 1);
|
memcpy(tmp.name, Blocked_Contacts.list[i].name, Blocked_Contacts.list[i].namelength + 1);
|
||||||
memcpy(tmp.pub_key, Blocked_Contacts.list[i].pub_key, TOX_CLIENT_ID_SIZE);
|
memcpy(tmp.pub_key, Blocked_Contacts.list[i].pub_key, TOX_CLIENT_ID_SIZE);
|
||||||
|
|
||||||
|
uint8_t lastonline[sizeof(uint64_t)];
|
||||||
|
memcpy(lastonline, &Blocked_Contacts.list[i].last_on, sizeof(uint64_t));
|
||||||
|
host_to_net(lastonline, sizeof(uint64_t));
|
||||||
|
memcpy(&tmp.last_on, lastonline, sizeof(uint64_t));
|
||||||
|
|
||||||
memcpy(data + count * sizeof(BlockedFriend), &tmp, sizeof(BlockedFriend));
|
memcpy(data + count * sizeof(BlockedFriend), &tmp, sizeof(BlockedFriend));
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
@ -166,6 +172,12 @@ int load_blocklist(char *path)
|
|||||||
Blocked_Contacts.list[i].namelength = tmp.namelength;
|
Blocked_Contacts.list[i].namelength = tmp.namelength;
|
||||||
memcpy(Blocked_Contacts.list[i].name, tmp.name, tmp.namelength + 1);
|
memcpy(Blocked_Contacts.list[i].name, tmp.name, tmp.namelength + 1);
|
||||||
memcpy(Blocked_Contacts.list[i].pub_key, tmp.pub_key, TOX_CLIENT_ID_SIZE);
|
memcpy(Blocked_Contacts.list[i].pub_key, tmp.pub_key, TOX_CLIENT_ID_SIZE);
|
||||||
|
|
||||||
|
uint8_t lastonline[sizeof(uint64_t)];
|
||||||
|
memcpy(lastonline, &tmp.last_on, sizeof(uint64_t));
|
||||||
|
net_to_host(lastonline, sizeof(uint64_t));
|
||||||
|
memcpy(&Blocked_Contacts.list[i].last_on, lastonline, sizeof(uint64_t));
|
||||||
|
|
||||||
++Blocked_Contacts.num_blocked;
|
++Blocked_Contacts.num_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +372,7 @@ static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
|
|||||||
friends[i].status = TOX_USERSTATUS_NONE;
|
friends[i].status = TOX_USERSTATUS_NONE;
|
||||||
friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON;
|
friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON;
|
||||||
friends[i].namelength = Blocked_Contacts.list[bnum].namelength;
|
friends[i].namelength = Blocked_Contacts.list[bnum].namelength;
|
||||||
|
update_friend_last_online(i, Blocked_Contacts.list[bnum].last_on);
|
||||||
memcpy(friends[i].name, Blocked_Contacts.list[bnum].name, friends[i].namelength + 1);
|
memcpy(friends[i].name, Blocked_Contacts.list[bnum].name, friends[i].namelength + 1);
|
||||||
memcpy(friends[i].pub_key, Blocked_Contacts.list[bnum].pub_key, TOX_CLIENT_ID_SIZE);
|
memcpy(friends[i].pub_key, Blocked_Contacts.list[bnum].pub_key, TOX_CLIENT_ID_SIZE);
|
||||||
|
|
||||||
@ -516,7 +529,7 @@ static void delete_blocked_friend(int32_t bnum)
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = Blocked_Contacts.max_index; i >= 0; --i) {
|
for (i = Blocked_Contacts.max_index; i > 0; --i) {
|
||||||
if (Blocked_Contacts.list[i - 1].active)
|
if (Blocked_Contacts.list[i - 1].active)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -544,6 +557,7 @@ void block_friend(Tox *m, int32_t fnum)
|
|||||||
Blocked_Contacts.list[i].active = true;
|
Blocked_Contacts.list[i].active = true;
|
||||||
Blocked_Contacts.list[i].num = i;
|
Blocked_Contacts.list[i].num = i;
|
||||||
Blocked_Contacts.list[i].namelength = friends[fnum].namelength;
|
Blocked_Contacts.list[i].namelength = friends[fnum].namelength;
|
||||||
|
Blocked_Contacts.list[i].last_on = friends[fnum].last_online.last_on;
|
||||||
memcpy(Blocked_Contacts.list[i].pub_key, friends[fnum].pub_key, TOX_CLIENT_ID_SIZE);
|
memcpy(Blocked_Contacts.list[i].pub_key, friends[fnum].pub_key, TOX_CLIENT_ID_SIZE);
|
||||||
memcpy(Blocked_Contacts.list[i].name, friends[fnum].name, friends[fnum].namelength + 1);
|
memcpy(Blocked_Contacts.list[i].name, friends[fnum].name, friends[fnum].namelength + 1);
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ typedef struct {
|
|||||||
char pub_key[TOX_CLIENT_ID_SIZE];
|
char pub_key[TOX_CLIENT_ID_SIZE];
|
||||||
int32_t num;
|
int32_t num;
|
||||||
bool active;
|
bool active;
|
||||||
|
uint64_t last_on;
|
||||||
} BlockedFriend;
|
} BlockedFriend;
|
||||||
|
|
||||||
ToxWindow new_friendlist(void);
|
ToxWindow new_friendlist(void);
|
||||||
|
@ -37,6 +37,21 @@ extern struct user_settings *user_settings_;
|
|||||||
|
|
||||||
static uint64_t current_unix_time;
|
static uint64_t current_unix_time;
|
||||||
|
|
||||||
|
void host_to_net(uint8_t *num, uint16_t numbytes)
|
||||||
|
{
|
||||||
|
#ifndef WORDS_BIGENDIAN
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t buff[numbytes];
|
||||||
|
|
||||||
|
for (i = 0; i < numbytes; ++i) {
|
||||||
|
buff[i] = num[numbytes - i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(num, buff, numbytes);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void update_unix_time(void)
|
void update_unix_time(void)
|
||||||
{
|
{
|
||||||
current_unix_time = (uint64_t) time(NULL);
|
current_unix_time = (uint64_t) time(NULL);
|
||||||
|
@ -33,6 +33,12 @@
|
|||||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef net_to_host
|
||||||
|
#define net_to_host(x, y) host_to_net(x, y)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void host_to_net(uint8_t *num, uint16_t numbytes);
|
||||||
|
|
||||||
/* convert a hex string to binary */
|
/* convert a hex string to binary */
|
||||||
char *hex_string_to_bin(const char *hex_string);
|
char *hex_string_to_bin(const char *hex_string);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user