static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) { if (num_friends == 0) return; int f = friendlist_index[num_selected]; if (key == '\n') { /* Jump to chat window if already open */ if (friends[f].chatwin != -1) { set_active_window(friends[f].chatwin); } else if (num_active_windows() < MAX_WINDOWS_NUM) { friends[f].chatwin = add_window(m, new_chat(m, friends[f].num)); set_active_window(friends[f].chatwin); } else { prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_1, true); } } else if (key == KEY_DC) { delete_friend(m, self, f, key); } else { select_friend(self, m, key); } }
static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index) { int id = toxav_get_peer_id(av, call_index, 0); if ( id != av_ErrorUnknown && id >= Friends.max_idx) return; Tox *m = toxav_get_tox(av); if (Friends.list[id].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { if (toxav_get_call_state(av, call_index) == av_CallStarting) { /* Only open windows when call is incoming */ Friends.list[id].chatwin = add_window(m, new_chat(m, Friends.list[id].num)); } } else { char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, Friends.list[id].num); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick); const char *errmsg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg); sound_notify(prompt, error, NT_WNDALERT_1, NULL); } } }
static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index) { int id = toxav_get_peer_id(av, call_index, 0); /*id++;*/ if ( id != ErrorInternal && id >= max_friends_index) return; Tox *m = toxav_get_tox(av); if (friends[id].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[id].chatwin = add_window(m, new_chat(m, friends[id].num)); } else { uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; int n_len = tox_get_name(m, id, nick); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "Audio action from: %s!", nick); line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); uint8_t *errmsg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED); alert_window(prompt, WINDOW_ALERT_0, true); } } }
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t filenum, uint64_t filesize, uint8_t *filename, uint16_t filename_len) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0); uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; tox_get_name(m, num, nick); nick[TOXIC_MAX_NAME_LENGTH] = '\0'; prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* File transfer from %s failed: too many windows are open.\n", nick); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_1, true); } } }
static void friendlist_onAV(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state) { assert(0); if( friend_number >= Friends.max_idx) return; assert(0); Tox *m = toxav_get_tox(av); if (Friends.list[friend_number].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { if(state != TOXAV_FRIEND_CALL_STATE_FINISHED) { Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num)); set_active_window(Friends.list[friend_number].chatwin); } } else { char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, Friends.list[friend_number].num); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick); const char *errmsg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg); sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL); } } }
static void friendlist_onAv(ToxWindow *self, ToxAv *av) { int id = toxav_get_peer_id(av, 0); id++; if ( id >= max_friends_index) return; Tox* m = toxav_get_tox(av); if (friends[id].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[id].chatwin = add_window(m, new_chat(m, friends[id].num)); } else { uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; tox_get_name(m, id, nick); nick[TOXIC_MAX_NAME_LENGTH] = '\0'; wprintw(prompt->window, "Audio action from: %s!\n", nick); prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_0, true); } } }
static void friendlist_onFileRecv(ToxWindow *self, Tox *m, uint32_t num, uint32_t filenum, uint64_t file_size, const char *filename, size_t name_length) { if (num >= Friends.max_idx) { return; } if (Friends.list[num].chatwin != -1) { return; } if (get_num_active_windows() < MAX_WINDOWS_NUM) { Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num)); return; } tox_file_control(m, num, filenum, TOX_FILE_CONTROL_CANCEL, NULL); char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "* File transfer from %s failed: too many windows are open.", nick); sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL); }
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, uint64_t filesize, uint8_t *filename, uint16_t filename_len) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0); uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick); line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED); alert_window(prompt, WINDOW_ALERT_1, true); } } }
static void friendlist_onMessage(ToxWindow *self, Tox *m, uint32_t num, Tox_Message_Type type, const char *str, size_t length) { if (num >= Friends.max_idx) { return; } if (Friends.list[num].chatwin != -1) { return; } if (get_num_active_windows() < MAX_WINDOWS_NUM) { Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num)); return; } char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", str); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Warning: Too many windows are open."); sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL); }
static gboolean fx_send_attention(PurpleConnection *gc, const gchar *who, guint UNUSED(type)) { PurpleBuddy *buddy; PurplePresence *presence; PurpleStatus *status; const gchar *status_id; fetion_account *sec; fetion_account *ac = purple_connection_get_protocol_data(gc); if(!(buddy = purple_find_buddy(ac->account, who))) return 0; presence = purple_buddy_get_presence(buddy); status = purple_presence_get_active_status(presence); status_id = purple_status_get_id(status); /* online,need invite */ if(strcmp(status_id, "Offline") != 0) { if(!(sec = session_find(who))) new_chat(ac, who, (gchar*)0); else fetion_send_nudge(sec, who); return TRUE; } return FALSE; }
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *str, uint16_t len) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { str[len] = '\0'; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; int n_len = tox_get_name(m, num, nick); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt); line_info_add(prompt, timefrmt, nick, NULL, str, IN_MSG, 0, 0); uint8_t *msg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED); alert_window(prompt, WINDOW_ALERT_1, true); } } }
void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len) { if (num < 0 || num >= num_friends) return; if (friends[num].chatwin == -1) friends[num].chatwin = add_window(m, new_chat(m, prompt, friends[num].num)); }
static int fx_im_send(PurpleConnection *gc, const gchar *who, const gchar *what, PurpleMessageFlags UNUSED(flags)) { PurpleBuddy *buddy; PurplePresence *presence; PurpleStatus *status; const gchar *status_id; fetion_account *sec; PurpleConversation *conv; fetion_account *ac = purple_connection_get_protocol_data(gc); Contact *cnt; gint shutdown = 0; if(!(buddy = purple_find_buddy(ac->account, who))) return 0; presence = purple_buddy_get_presence(buddy); status = purple_presence_get_active_status(presence); status_id = purple_status_get_id(status); cnt = fetion_contact_list_find_by_userid(ac->user->contactList, who); if(cnt->relationStatus == RELATION_STATUS_UNAUTHENTICATED) { if(!(conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1; purple_conversation_write(conv, NULL, _("Failed to send message: Unverified Buddy!"), PURPLE_MESSAGE_ERROR, time(NULL)); return -1; } if(cnt->serviceStatus == BASIC_SERVICE_ABNORMAL){ if(cnt->carrierStatus == CARRIER_STATUS_CLOSED){ shutdown = 1; }else{ if((cnt->carrier[0] != '\0' && cnt->mobileno[0] == '\0') || cnt->carrier[0] == '\0') shutdown = 1; } }else if(cnt->carrierStatus == CARRIER_STATUS_DOWN) if(cnt->carrier[0] != '\0') shutdown = 1; if(shutdown) { if(!(conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1; purple_conversation_write(conv, NULL, _("Fail to send message: Buddy has cancled Fetion service!"), PURPLE_MESSAGE_ERROR, time(NULL)); return -1; } /* online,need invite */ if(strcmp(status_id, "Offline") != 0) { if(!(sec = session_find(who))) new_chat(ac, who, what); else fetion_send_sms(sec, who, what); return 1; } fetion_send_sms(ac, who, what); return 1; }
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) { if (key == KEY_UP || key == KEY_DOWN) { select_friend(m, key); } else if (key == '\n') { /* Jump to chat window if already open */ if (friends[num_selected].chatwin != -1) { set_active_window(friends[num_selected].chatwin); } else { friends[num_selected].chatwin = add_window(m, new_chat(m, prompt, friends[num_selected].num)); set_active_window(friends[num_selected].chatwin); } } else if (key == 0x107 || key == 0x8 || key == 0x7f) delete_friend(m, self, num_selected, key); }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t type, const char *group_pub_key, uint16_t length) { if (num >= Friends.max_idx) return; if (Friends.list[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num)); } else { char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Group chat invite from %s failed: too many windows are open.", nick); sound_notify(prompt, error, NT_WNDALERT_1, NULL); } } }
void callback_recv_invite(Tox *m, uint32_t friend_number) { if (friend_number >= Friends.max_idx) return; if (Friends.list[friend_number].chatwin == -1) { if (get_num_active_windows() >= MAX_WINDOWS_NUM) return; Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num)); } ToxWindow *windows = CallControl.prompt; int i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onInvite != NULL && windows[i].num == friend_number) { windows[i].onInvite(&windows[i], CallControl.av, friend_number, CallControl.call_state); } } }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const char *group_pub_key) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS); } else { char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); const char *msg = "* Group chat invite from %s failed: too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick); notify(prompt, error, NT_WNDALERT_1); } } }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *group_pub_key) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; tox_get_name(m, num, nick); nick[TOXIC_MAX_NAME_LENGTH] = '\0'; prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* Group chat invite from %s failed: too many windows are open.\n", nick); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_1, true); } } }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t *group_pub_key) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { uint8_t nick[TOX_MAX_NAME_LENGTH]; int n_len = tox_get_name(m, num, nick); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); nick[n_len] = '\0'; uint8_t msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick); line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED); alert_window(prompt, WINDOW_ALERT_1, true); } } }
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, uint64_t filesize, const char *filename, uint16_t filename_len) { if (num >= Friends.max_idx) return; if (Friends.list[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num)); } else { tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0); char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "* File transfer from %s failed: too many windows are open.", nick); sound_notify(prompt, error, NT_WNDALERT_1, NULL); } } }
static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); } else { uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; tox_get_name(m, num, nick); nick[TOXIC_MAX_NAME_LENGTH] = '\0'; wprintw(prompt->window, "%s: %s\n", nick, str); prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_1, true); } } }
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *str, uint16_t len) { if (num >= max_friends_index) return; if (friends[num].chatwin == -1) { if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[num].chatwin = add_window(m, new_chat(m, friends[num].num)); notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS); } else { char nick[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, nick, num); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, str); const char *msg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg); notify(prompt, error, NT_WNDALERT_1); } } }
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) { if (num_friends == 0) return; int f = friendlist_index[num_selected]; /* lock screen and force decision on deletion popup */ if (pendingdelete.active) { if (key == 'y' || key == 'n') del_friend_deactivate(self, m, key); return; } if (key == '\n') { /* Jump to chat window if already open */ if (friends[f].chatwin != -1) { set_active_window(friends[f].chatwin); } else if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[f].chatwin = add_window(m, new_chat(m, friends[f].num)); set_active_window(friends[f].chatwin); } else { prep_prompt_win(); wattron(prompt->window, COLOR_PAIR(RED)); wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wattron(prompt->window, COLOR_PAIR(RED)); alert_window(prompt, WINDOW_ALERT_1, true); } } else if (key == KEY_DC) { del_friend_activate(self, m, f); } else { select_friend(self, m, key); } }
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) { if (num_friends == 0) return; int f = friendlist_index[num_selected]; /* lock screen and force decision on deletion popup */ if (pendingdelete.active) { if (key == 'y' || key == 'n') del_friend_deactivate(self, m, key); return; } if (key != ltr) { if (key == '\n') { /* Jump to chat window if already open */ if (friends[f].chatwin != -1) { set_active_window(friends[f].chatwin); } else if (get_num_active_windows() < MAX_WINDOWS_NUM) { friends[f].chatwin = add_window(m, new_chat(m, friends[f].num)); set_active_window(friends[f].chatwin); } else { uint8_t *msg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED); alert_window(prompt, WINDOW_ALERT_1, true); } } else if (key == KEY_DC) { del_friend_activate(self, m, f); } else { select_friend(self, m, key); } } }
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) { if (self->help->active) { help_onKey(self, key); return; } if (key == 'h') { help_init_menu(self); return; } if (!blocklist_view && !Friends.num_friends && (key != KEY_RIGHT && key != KEY_LEFT)) return; if (blocklist_view && !Blocked.num_blocked && (key != KEY_RIGHT && key != KEY_LEFT)) return; int f = 0; if (blocklist_view == 1 && Blocked.num_blocked) f = Blocked.index[Blocked.num_selected]; else if (Friends.num_friends) f = Friends.index[Friends.num_selected]; /* lock screen and force decision on deletion popup */ if (PendingDelete.active) { if (key == 'y' || key == 'n') del_friend_deactivate(self, m, key); return; } if (key == ltr) return; switch (key) { case '\n': if (blocklist_view) break; /* Jump to chat window if already open */ if (Friends.list[f].chatwin != -1) { set_active_window(Friends.list[f].chatwin); } else if (get_num_active_windows() < MAX_WINDOWS_NUM) { Friends.list[f].chatwin = add_window(m, new_chat(m, Friends.list[f].num)); set_active_window(Friends.list[f].chatwin); } else { const char *msg = "* Warning: Too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg); sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL); } break; case KEY_DC: del_friend_activate(self, m, f); break; case 'b': if (!blocklist_view) block_friend(m, f); else unblock_friend(m, f); break; case KEY_RIGHT: case KEY_LEFT: blocklist_view ^= 1; break; default: if (blocklist_view == 0) select_friend(self, key, &Friends.num_selected, Friends.num_friends); else select_friend(self, key, &Blocked.num_selected, Blocked.num_blocked); break; } }