Added profile parameter to TWC_CHECK_FRIEND_NUMBER macro.

This commit is contained in:
Håvard Pettersson 2014-11-19 06:20:02 +01:00
parent 8585b09700
commit 14ca66e394

View File

@ -90,8 +90,7 @@ enum TWC_FRIEND_MATCH
} }
/** /**
* Make sure a profile with the given name exists. If not, warn user and * Make sure a profile with the given name exists. If not, warn user and abort.
* abort.
*/ */
#define TWC_CHECK_PROFILE_EXISTS(profile) \ #define TWC_CHECK_PROFILE_EXISTS(profile) \
if (!profile) \ if (!profile) \
@ -118,7 +117,7 @@ enum TWC_FRIEND_MATCH
/** /**
* Make sure friend exists. * Make sure friend exists.
*/ */
#define TWC_CHECK_FRIEND_NUMBER(number, string) \ #define TWC_CHECK_FRIEND_NUMBER(profile, number, string) \
if (number == TWC_FRIEND_MATCH_NOMATCH) \ if (number == TWC_FRIEND_MATCH_NOMATCH) \
{ \ { \
weechat_printf(profile->buffer, \ weechat_printf(profile->buffer, \
@ -374,7 +373,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "remove") == 0)) else if (argc >= 3 && (weechat_strcasecmp(argv[1], "remove") == 0))
{ {
int32_t friend_number = twc_match_friend(profile, argv[2]); int32_t friend_number = twc_match_friend(profile, argv[2]);
TWC_CHECK_FRIEND_NUMBER(friend_number, argv[2]); TWC_CHECK_FRIEND_NUMBER(profile, friend_number, argv[2]);
char *name = twc_get_name_nt(profile->tox, friend_number); char *name = twc_get_name_nt(profile->tox, friend_number);
if (tox_del_friend(profile->tox, friend_number) == 0) if (tox_del_friend(profile->tox, friend_number) == 0)
@ -595,15 +594,13 @@ twc_cmd_invite(void *data, struct t_gui_buffer *buffer,
if (argc == 1) if (argc == 1)
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
TWC_CHECK_PROFILE(profile);
TWC_CHECK_PROFILE_LOADED(profile);
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
TWC_CHECK_PROFILE_LOADED(chat->profile);
TWC_CHECK_GROUP_CHAT(chat); TWC_CHECK_GROUP_CHAT(chat);
int32_t friend_number = twc_match_friend(profile, argv_eol[1]); int32_t friend_number = twc_match_friend(chat->profile, argv_eol[1]);
TWC_CHECK_FRIEND_NUMBER(friend_number, argv_eol[1]); TWC_CHECK_FRIEND_NUMBER(chat->profile, friend_number, argv_eol[1]);
int rc = tox_invite_friend(chat->profile->tox, int rc = tox_invite_friend(chat->profile->tox,
friend_number, chat->group_number); friend_number, chat->group_number);
@ -676,7 +673,7 @@ twc_cmd_msg(void *data, struct t_gui_buffer *buffer,
} }
int32_t friend_number = twc_match_friend(profile, recipient); int32_t friend_number = twc_match_friend(profile, recipient);
TWC_CHECK_FRIEND_NUMBER(friend_number, recipient); TWC_CHECK_FRIEND_NUMBER(profile, friend_number, recipient);
// create chat buffer if it does not exist // create chat buffer if it does not exist
struct t_twc_chat *chat = twc_chat_search_friend(profile, friend_number, true); struct t_twc_chat *chat = twc_chat_search_friend(profile, friend_number, true);