added delay for autojoin
This commit is contained in:
		
							parent
							
								
									bc00b79aa4
								
							
						
					
					
						commit
						2908d7f824
					
				
					 5 changed files with 123 additions and 93 deletions
				
			
		|  | @ -39,9 +39,9 @@ struct t_config_option *twc_config_friend_request_message; | |||
| struct t_config_option *twc_config_short_id_size; | ||||
| 
 | ||||
| char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] = { | ||||
|     "save_file",     "autoload",   "autojoin",   "max_friend_requests", | ||||
|     "proxy_address", "proxy_port", "proxy_type", "udp", | ||||
|     "ipv6",          "passphrase", "logging", | ||||
|     "save_file", "autoload", "autojoin", "autojoin_delay", | ||||
|     "max_friend_requests", "proxy_address", "proxy_port", "proxy_type", | ||||
|     "udp", "ipv6", "passphrase", "logging", | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -222,6 +222,15 @@ twc_config_init_option(struct t_twc_profile *profile, | |||
|                           "by your friends"; | ||||
|             default_value = "off"; | ||||
|             break; | ||||
|         case TWC_PROFILE_OPTION_AUTOJOIN_DELAY: | ||||
|             type = "integer"; | ||||
|             description = "delay befor do autojoin (in ms) this required to " | ||||
|                           "tox from entering incorrect state and stop processing " | ||||
|                           "group events"; | ||||
|             min = 0; | ||||
|             max = INT_MAX; | ||||
|             default_value = "5000"; | ||||
|             break; | ||||
|         case TWC_PROFILE_OPTION_IPV6: | ||||
|             type = "boolean"; | ||||
|             description = "use IPv6 as well as IPv4 to connect to the Tox " | ||||
|  |  | |||
|  | @ -57,6 +57,11 @@ twc_group_chat_invite_add(struct t_twc_profile *profile, int32_t friend_number, | |||
|     invite->data = data_copy; | ||||
|     invite->data_size = size; | ||||
| 
 | ||||
|     if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN)) | ||||
|         invite->autojoin_delay = TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_AUTOJOIN_DELAY); | ||||
|     else | ||||
|         invite->autojoin_delay = 0; | ||||
| 
 | ||||
|     twc_list_item_new_data_add(profile->group_chat_invites, invite); | ||||
| 
 | ||||
|     return profile->group_chat_invites->count - 1; | ||||
|  |  | |||
|  | @ -37,6 +37,7 @@ struct t_twc_group_chat_invite | |||
|     uint8_t group_chat_type; | ||||
|     uint8_t *data; | ||||
|     size_t data_size; | ||||
|     uint32_t autojoin_delay; | ||||
| }; | ||||
| 
 | ||||
| int | ||||
|  |  | |||
|  | @ -30,6 +30,7 @@ enum t_twc_profile_option | |||
|     TWC_PROFILE_OPTION_SAVEFILE = 0, | ||||
|     TWC_PROFILE_OPTION_AUTOLOAD, | ||||
|     TWC_PROFILE_OPTION_AUTOJOIN, | ||||
|     TWC_PROFILE_OPTION_AUTOJOIN_DELAY, | ||||
|     TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS, | ||||
|     TWC_PROFILE_OPTION_PROXY_ADDRESS, | ||||
|     TWC_PROFILE_OPTION_PROXY_PORT, | ||||
|  |  | |||
|  | @ -40,12 +40,18 @@ | |||
| int | ||||
| twc_do_timer_cb(const void *pointer, void *data, int remaining_calls) | ||||
| { | ||||
|     uint32_t interval; | ||||
|     int i; | ||||
|     int64_t rc; | ||||
|     char *tags; | ||||
| 
 | ||||
|     /* TODO: don't strip the const */ | ||||
|     struct t_twc_profile *profile = (void *)pointer; | ||||
| 
 | ||||
|     interval = tox_iteration_interval(profile->tox); | ||||
|     tox_iterate(profile->tox, profile); | ||||
|     struct t_hook *hook = | ||||
|         weechat_hook_timer(tox_iteration_interval(profile->tox), 0, 1, | ||||
|         weechat_hook_timer(interval, 0, 1, | ||||
|                            twc_do_timer_cb, profile, NULL); | ||||
|     profile->tox_do_timer = hook; | ||||
| 
 | ||||
|  | @ -55,6 +61,75 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls) | |||
|         connection == TOX_CONNECTION_TCP || connection == TOX_CONNECTION_UDP; | ||||
|     twc_profile_set_online_status(profile, is_connected); | ||||
| 
 | ||||
|     if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN)) | ||||
|     { | ||||
|         struct t_twc_group_chat_invite *invite; | ||||
|         for(i = 0; (invite = twc_group_chat_invite_with_index(profile, i)); i++) | ||||
|             if(invite->autojoin_delay <= 0) | ||||
|             { | ||||
|                 struct t_twc_chat *friend_chat = | ||||
|                     twc_chat_search_friend(profile, invite->friend_number, false); | ||||
|                 char *friend_name = twc_get_name_nt(profile->tox, invite->friend_number); | ||||
|                 char *type_str; | ||||
|                 switch (invite->group_chat_type) | ||||
|                 { | ||||
|                 case TOX_CONFERENCE_TYPE_TEXT: | ||||
|                     type_str = "a text-only group chat"; | ||||
|                     break; | ||||
|                 case TOX_CONFERENCE_TYPE_AV: | ||||
|                     type_str = "an audio/vikdeo group chat"; | ||||
|                     break; | ||||
|                 default: | ||||
|                     type_str = "a group chat"; | ||||
|                     break; | ||||
|                 } | ||||
| 
 | ||||
|                 rc = twc_group_chat_invite_join(invite); | ||||
|                 // item will be deleted, backtrack
 | ||||
|                 i--; | ||||
|                 if (rc >= 0) | ||||
|                 { | ||||
|                     tags = "notify_private"; | ||||
|                     if (friend_chat) | ||||
|                     { | ||||
|                         weechat_printf_date_tags( | ||||
|                                 friend_chat->buffer, 0, tags, | ||||
|                                 "%sWe joined the %s%s%s's invite to %s.", | ||||
|                                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                                 friend_name, weechat_color("reset"), type_str); | ||||
|                         tags = ""; | ||||
|                     } | ||||
|                     weechat_printf_date_tags( | ||||
|                             profile->buffer, 0, tags, | ||||
|                             "%sWe joined the %s%s%s's invite to %s.", | ||||
|                             weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                             friend_name, weechat_color("reset"), type_str); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     tags = "notify_highlight"; | ||||
|                     if (friend_chat) | ||||
|                     { | ||||
|                         weechat_printf_date_tags( | ||||
|                                 friend_chat->buffer, 0, tags, | ||||
|                                 "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                                 "process the invite. Please try again.", | ||||
|                                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                                 friend_name, weechat_color("reset")); | ||||
|                         tags = ""; | ||||
|                     } | ||||
|                     weechat_printf_date_tags( | ||||
|                             profile->buffer, 0, tags, | ||||
|                             "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                             "process the invite. Please try again.", | ||||
|                             weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                             friend_name, weechat_color("reset")); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|                 invite->autojoin_delay -= interval; | ||||
|     } | ||||
| 
 | ||||
|     return WEECHAT_RC_OK; | ||||
| } | ||||
| 
 | ||||
|  | @ -248,109 +323,48 @@ twc_group_invite_callback(Tox *tox, uint32_t friend_number, | |||
|             break; | ||||
|     } | ||||
| 
 | ||||
|     if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN)) | ||||
|     { | ||||
|         switch (type) | ||||
|         { | ||||
|             case TOX_CONFERENCE_TYPE_TEXT: | ||||
|                 rc = tox_conference_join(tox, friend_number, invite_data, | ||||
|                                          length, &err); | ||||
|                 break; | ||||
| #ifdef TOXAV_ENABLED | ||||
|             case TOX_CONFERENCE_TYPE_AV: | ||||
|                 rc = toxav_join_av_groupchat(tox, friend_number, invite_data, | ||||
|                                              length, NULL, NULL); | ||||
|                 break; | ||||
| #endif | ||||
|             default: | ||||
|                 rc = -1; | ||||
|                 break; | ||||
|         } | ||||
|     rc = twc_group_chat_invite_add(profile, friend_number, type, | ||||
|                                    (uint8_t *)invite_data, length); | ||||
| 
 | ||||
|         if (rc >= 0 && err == TOX_ERR_CONFERENCE_JOIN_OK) | ||||
|         { | ||||
|             tags = "notify_private"; | ||||
|             if (friend_chat) | ||||
|             { | ||||
|                 weechat_printf_date_tags( | ||||
|                     friend_chat->buffer, 0, tags, | ||||
|                     "%sWe joined the %s%s%s's invite to %s.", | ||||
|                     weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                     friend_name, weechat_color("reset"), type_str); | ||||
|                 tags = ""; | ||||
|             } | ||||
|             weechat_printf_date_tags( | ||||
|                 profile->buffer, 0, tags, | ||||
|                 "%sWe joined the %s%s%s's invite to %s.", | ||||
|                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                 friend_name, weechat_color("reset"), type_str); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             tags = "notify_highlight"; | ||||
|             if (friend_chat) | ||||
|             { | ||||
|                 weechat_printf_date_tags( | ||||
|                     friend_chat->buffer, 0, tags, | ||||
|                     "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                     "process the invite. Please try again.", | ||||
|                     weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                     friend_name, weechat_color("reset")); | ||||
|                 tags = ""; | ||||
|             } | ||||
|             weechat_printf_date_tags( | ||||
|                 profile->buffer, 0, tags, | ||||
|                 "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                 "process the invite. Please try again.", | ||||
|                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                 friend_name, weechat_color("reset")); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     if (rc >= 0) | ||||
|     { | ||||
|         rc = twc_group_chat_invite_add(profile, friend_number, type, | ||||
|                                        (uint8_t *)invite_data, length); | ||||
| 
 | ||||
|         if (rc >= 0) | ||||
|         tags = "notify_highlight"; | ||||
|         if (friend_chat) | ||||
|         { | ||||
|             tags = "notify_highlight"; | ||||
|             if (friend_chat) | ||||
|             { | ||||
|                 weechat_printf_date_tags( | ||||
|                     friend_chat->buffer, 0, tags, | ||||
|                     "%s%s%s%s invites you to join %s. Type " | ||||
|                     "\"/group join %d\" to accept.", | ||||
|                     weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                     friend_name, weechat_color("reset"), type_str, rc); | ||||
|                 tags = ""; | ||||
|             } | ||||
|             weechat_printf_date_tags( | ||||
|                 profile->buffer, 0, tags, | ||||
|                 friend_chat->buffer, 0, tags, | ||||
|                 "%s%s%s%s invites you to join %s. Type " | ||||
|                 "\"/group join %d\" to accept.", | ||||
|                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                 friend_name, weechat_color("reset"), type_str, rc); | ||||
|             tags = ""; | ||||
|         } | ||||
|         else | ||||
|         weechat_printf_date_tags( | ||||
|             profile->buffer, 0, tags, | ||||
|             "%s%s%s%s invites you to join %s. Type " | ||||
|             "\"/group join %d\" to accept.", | ||||
|             weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|             friend_name, weechat_color("reset"), type_str, rc); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         tags = "notify_highlight"; | ||||
|         if (friend_chat) | ||||
|         { | ||||
|             tags = "notify_highlight"; | ||||
|             if (friend_chat) | ||||
|             { | ||||
|                 weechat_printf_date_tags( | ||||
|                     friend_chat->buffer, 0, tags, | ||||
|                     "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                     "process the invite with error %d. Please try again.", | ||||
|                     weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                     friend_name, weechat_color("reset"), rc, err); | ||||
|                 tags = ""; | ||||
|             } | ||||
|             weechat_printf_date_tags( | ||||
|                 profile->buffer, 0, tags, | ||||
|                 friend_chat->buffer, 0, tags, | ||||
|                 "%s%s%s%s invites you to join %s, but we failed to " | ||||
|                 "process the invite. Please try again.", | ||||
|                 "process the invite with error %d. Please try again.", | ||||
|                 weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|                 friend_name, weechat_color("reset"), rc); | ||||
|                 friend_name, weechat_color("reset"), rc, err); | ||||
|             tags = ""; | ||||
|         } | ||||
|         weechat_printf_date_tags( | ||||
|             profile->buffer, 0, tags, | ||||
|             "%s%s%s%s invites you to join %s, but we failed to " | ||||
|             "process the invite. Please try again.", | ||||
|             weechat_prefix("network"), weechat_color("chat_nick_other"), | ||||
|             friend_name, weechat_color("reset"), rc); | ||||
|     } | ||||
|     free(friend_name); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gordon Quad
						Gordon Quad