/* puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number */ static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum) { if (max_friends_index >= MAX_FRIENDS_NUM) return; int i; for (i = 0; i <= max_friends_index; ++i) { if (friends[i].active) continue; friends[i].num = fnum; friends[i].active = true; friends[i].chatwin = -1; friends[i].status = TOX_USERSTATUS_NONE; friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON; 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].pub_key, Blocked_Contacts.list[bnum].pub_key, TOX_CLIENT_ID_SIZE); num_friends = tox_count_friendlist(m); if (i == max_friends_index) ++max_friends_index; sort_blocklist_index(); sort_friendlist_index(); return; } }
/* puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number */ static void friendlist_add_blocked(Tox *m, uint32_t fnum, uint32_t bnum) { realloc_friends(Friends.max_idx + 1); memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend)); int i; for (i = 0; i <= Friends.max_idx; ++i) { if (Friends.list[i].active) continue; ++Friends.num_friends; Friends.list[i].num = fnum; Friends.list[i].active = true; Friends.list[i].chatwin = -1; Friends.list[i].status = TOX_USER_STATUS_NONE; Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON; Friends.list[i].namelength = Blocked.list[bnum].namelength; update_friend_last_online(i, Blocked.list[bnum].last_on); memcpy(Friends.list[i].name, Blocked.list[bnum].name, Friends.list[i].namelength + 1); memcpy(Friends.list[i].pub_key, Blocked.list[bnum].pub_key, TOX_PUBLIC_KEY_SIZE); if (i == Friends.max_idx) ++Friends.max_idx; sort_blocklist_index(); sort_friendlist_index(); return; } }
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort) { realloc_friends(Friends.max_idx + 1); memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend)); uint32_t i; for (i = 0; i <= Friends.max_idx; ++i) { if (Friends.list[i].active) { continue; } ++Friends.num_friends; Friends.list[i].num = num; Friends.list[i].active = true; Friends.list[i].chatwin = -1; Friends.list[i].connection_status = TOX_CONNECTION_NONE; Friends.list[i].status = TOX_USER_STATUS_NONE; Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON; Tox_Err_Friend_Get_Public_Key pkerr; tox_friend_get_public_key(m, num, (uint8_t *) Friends.list[i].pub_key, &pkerr); if (pkerr != TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK) { fprintf(stderr, "tox_friend_get_public_key failed (error %d)\n", pkerr); } Tox_Err_Friend_Get_Last_Online loerr; time_t t = tox_friend_get_last_online(m, num, &loerr); if (loerr != TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) { t = 0; } update_friend_last_online(i, t); char tempname[TOX_MAX_NAME_LENGTH] = {0}; get_nick_truncate(m, tempname, num); snprintf(Friends.list[i].name, sizeof(Friends.list[i].name), "%s", tempname); Friends.list[i].namelength = strlen(Friends.list[i].name); if (i == Friends.max_idx) { ++Friends.max_idx; } if (sort) { sort_friendlist_index(); } #ifdef AUDIO init_friend_AV(i); #endif return; } }
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status) { if (num >= Friends.max_idx) return; Friends.list[num].online = status; update_friend_last_online(num, get_unix_time()); store_data(m, DATA_FILE); sort_friendlist_index(); }
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort) { if (Friends.max_idx < 0) return; Friends.num_friends = tox_count_friendlist(m); realloc_friends(Friends.max_idx + 1); memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend)); int i; for (i = 0; i <= Friends.max_idx; ++i) { if (Friends.list[i].active) continue; Friends.list[i].num = num; Friends.list[i].active = true; Friends.list[i].chatwin = -1; Friends.list[i].online = false; Friends.list[i].status = TOX_USERSTATUS_NONE; Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON; tox_get_client_id(m, num, (uint8_t *) Friends.list[i].pub_key); update_friend_last_online(i, tox_get_last_online(m, i)); char tempname[TOX_MAX_NAME_LENGTH] = {0}; int len = get_nick_truncate(m, tempname, num); if (len == -1 || tempname[0] == '\0') { strcpy(Friends.list[i].name, UNKNOWN_NAME); Friends.list[i].namelength = strlen(UNKNOWN_NAME); } else { /* Enforce toxic's maximum name length */ snprintf(Friends.list[i].name, sizeof(Friends.list[i].name), "%s", tempname); Friends.list[i].namelength = strlen(Friends.list[i].name); } if (i == Friends.max_idx) ++Friends.max_idx; if (sort) sort_friendlist_index(); return; } }
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, TOX_CONNECTION connection_status) { if (num >= Friends.max_idx) return; if (connection_status == TOX_CONNECTION_NONE) { --Friends.num_online; } else if (Friends.list[num].connection_status == TOX_CONNECTION_NONE) { ++Friends.num_online; if (avatar_send(m, num) == -1) fprintf(stderr, "avatar_send failed for friend %d\n", num); } Friends.list[num].connection_status = connection_status; update_friend_last_online(num, get_unix_time()); store_data(m, DATA_FILE); sort_friendlist_index(); }
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort) { if (max_friends_index < 0 || max_friends_index >= MAX_FRIENDS_NUM) return; int i; for (i = 0; i <= max_friends_index; ++i) { if (!friends[i].active) { friends[i].num = num; friends[i].active = true; friends[i].chatwin = -1; friends[i].online = false; friends[i].status = TOX_USERSTATUS_NONE; friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON; tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key); update_friend_last_online(i, tox_get_last_online(m, i)); char tempname[TOX_MAX_NAME_LENGTH] = {0}; int len = get_nick_truncate(m, tempname, num); if (len == -1 || tempname[0] == '\0') { strcpy(friends[i].name, UNKNOWN_NAME); friends[i].namelength = strlen(UNKNOWN_NAME); } else { /* Enforce toxic's maximum name length */ friends[i].namelength = len; snprintf(friends[i].name, sizeof(friends[i].name), "%s", tempname); } num_friends = tox_count_friendlist(m); if (i == max_friends_index) ++max_friends_index; if (sort) sort_friendlist_index(); return; } } }