void Core::requestFriendship(const QString& userId, const QString& message) { CString cMessage(message); int friendId = tox_addfriend(handle, CUserId(userId).data(), cMessage.data(), cMessage.size()); if (friendId == -1) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); friendIdList << friendId; } }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { CString cMessage(message); int friendId = tox_addfriend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); // TODO: better error handling if (friendId < 0) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } }
void line_eval(Tox *m, char *line) { if (line[0] == '/') { char inpt_command = line[1]; char prompt[STRING_LENGTH + 2] = "> "; int prompt_offset = 3; strcat(prompt, line); new_lines(prompt); if (inpt_command == 'f') { // add friend command: /f ID int i; char temp_id[128]; for (i = 0; i < 128; i++) temp_id[i] = line[i + prompt_offset]; unsigned char *bin_string = hex_string_to_bin(temp_id); int num = tox_addfriend(m, bin_string, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); free(bin_string); char numstring[100]; switch (num) { case TOX_FAERR_TOOLONG: sprintf(numstring, "[i] Message is too long."); break; case TOX_FAERR_NOMESSAGE: sprintf(numstring, "[i] Please add a message to your request."); break; case TOX_FAERR_OWNKEY: sprintf(numstring, "[i] That appears to be your own ID."); break; case TOX_FAERR_ALREADYSENT: sprintf(numstring, "[i] Friend request already sent."); break; case TOX_FAERR_UNKNOWN: sprintf(numstring, "[i] Undefined error when adding friend."); break; default: sprintf(numstring, "[i] Added friend as %d.", num); break; } new_lines(numstring); do_refresh(); } else if (inpt_command == 'd') { tox_do(m); } else if (inpt_command == 'm') { //message command: /m friendnumber messsage size_t len = strlen(line); if (len < 3) return; char numstring[len - 3]; char message[len - 3]; int i; for (i = 0; i < len; i++) { if (line[i + 3] != ' ') { numstring[i] = line[i + 3]; } else { int j; for (j = (i + 1); j < (len + 1); j++) message[j - i - 1] = line[j + 3]; break; } } int num = atoi(numstring); if (tox_sendmessage(m, num, (uint8_t *) message, strlen(message) + 1) != 1) { new_lines("[i] could not send message"); } else { new_lines(format_message(m, message, -1)); } } else if (inpt_command == 'n') { uint8_t name[TOX_MAX_NAME_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; name[i - 3] = line[i]; } name[i - 3] = 0; tox_setname(m, name, i - 2); char numstring[100]; sprintf(numstring, "[i] changed nick to %s", (char *)name); new_lines(numstring); } else if (inpt_command == 'l') { print_friendlist(m); } else if (inpt_command == 's') { uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; status[i - 3] = line[i]; } status[i - 3] = 0; tox_set_statusmessage(m, status, strlen((char *)status) + 1); char numstring[100]; sprintf(numstring, "[i] changed status to %s", (char *)status); new_lines(numstring); } else if (inpt_command == 'a') { uint8_t numf = atoi(line + 3); char numchar[100]; if (numf >= num_requests || pending_requests[numf].accepted) { sprintf(numchar, "[i] you either didn't receive that request or you already accepted it"); new_lines(numchar); } else { int num = tox_addfriend_norequest(m, pending_requests[numf].id); if (num != -1) { pending_requests[numf].accepted = 1; sprintf(numchar, "[i] friend request %u accepted", numf); new_lines(numchar); sprintf(numchar, "[i] added friendnumber %d", num); new_lines(numchar); } else { sprintf(numchar, "[i] failed to add friend"); new_lines(numchar); } } do_refresh(); } else if (inpt_command == 'h') { //help new_lines(help); } else if (inpt_command == 'i') { //info char idstring[200]; get_id(m, idstring); new_lines(idstring); } else if (inpt_command == 'q') { //exit endwin(); exit(EXIT_SUCCESS); } else { new_lines("[i] invalid command"); } } else { new_lines("[i] invalid command"); //new_lines(line); } }