1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 19:42:04 +02:00

convert self-not-in-group-error-code to an event

This commit is contained in:
B. Petersen 2018-11-15 21:55:48 +01:00
parent 99b99cbc46
commit 32ca326d58
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
4 changed files with 29 additions and 20 deletions

View file

@ -1630,7 +1630,8 @@ int dc_set_chat_name(dc_context_t* context, uint32_t chat_id, const char* new_na
}
if (!IS_SELF_IN_GROUP) {
dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL);
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot set chat name; self not in group");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
@ -1694,7 +1695,8 @@ int dc_set_chat_profile_image(dc_context_t* context, uint32_t chat_id, const cha
}
if (!IS_SELF_IN_GROUP) {
dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL);
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot set chat profile image; self not in group.");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
@ -1798,7 +1800,8 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t
}
if (!IS_SELF_IN_GROUP) {
dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL);
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot add contact to group; self not in group.");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
@ -1914,7 +1917,8 @@ int dc_remove_contact_from_chat(dc_context_t* context, uint32_t chat_id, uint32_
}
if (!IS_SELF_IN_GROUP) {
dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL);
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot remove contact from chat; self not in group.");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
@ -2053,7 +2057,8 @@ static uint32_t send_msg_raw(dc_context_t* context, dc_chat_t* chat, const dc_ms
}
if (DC_CHAT_TYPE_IS_MULTI(chat->type) && !dc_is_contact_in_chat(context, chat->id, DC_CONTACT_ID_SELF)) {
dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL);
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot send message; self not in group.");
goto cleanup;
}

View file

@ -20,11 +20,7 @@ static void log_vprintf(dc_context_t* context, int event, int code, const char*
return;
}
if (code==DC_ERROR_SELF_NOT_IN_GROUP) // TODO: this should also be better a separate event
{
msg = dc_stock_str(context, DC_STR_SELFNOTINGRP);
}
else if (msg_format)
if (msg_format)
{
#define BUFSIZE 1024
char tempbuf[BUFSIZE+1];

View file

@ -29,7 +29,6 @@ static char* default_string(int id)
case DC_STR_MSGADDMEMBER: return dc_strdup("Member %1$s added.");
case DC_STR_MSGDELMEMBER: return dc_strdup("Member %1$s removed.");
case DC_STR_MSGGROUPLEFT: return dc_strdup("Left group.");
case DC_STR_SELFNOTINGRP: return dc_strdup("You must be a member of the group to perform this action.");
case DC_STR_E2E_AVAILABLE: return dc_strdup("End-to-end encryption available.");
case DC_STR_ENCR_TRANSP: return dc_strdup("Transport-encryption.");
case DC_STR_ENCR_NONE: return dc_strdup("No encryption.");

View file

@ -825,6 +825,22 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
#define DC_EVENT_ERROR_NETWORK 401
/**
* An action cannot be performed because the user is not in the group.
* Reported eg. after a call to
* dc_set_chat_name(), dc_set_chat_profile_image(),
* dc_add_contact_to_chat(), dc_remove_contact_from_chat(),
* dc_send_text_msg() or another sending function.
*
* @param data1 0
* @param data2 (const char*) Info string in english language.
* Must not be free()'d or modified
* and is valid only until the callback returns.
* @return 0
*/
#define DC_EVENT_ERROR_SELF_NOT_IN_GROUP 410
/**
* Messages or chats changed. One or more messages or chats changed for various
* reasons in the database:
@ -1016,6 +1032,8 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
#define DC_EVENT_FILE_COPIED 2055 // deprecated
#define DC_EVENT_IS_OFFLINE 2081 // deprecated
#define DC_ERROR_SELF_NOT_IN_GROUP 1 // deprecated
#define DC_STR_SELFNOTINGRP 21 // deprecated
#define DC_EVENT_DATA1_IS_STRING(e) ((e)==DC_EVENT_HTTP_GET || (e)==DC_EVENT_IMEX_FILE_WRITTEN || (e)==DC_EVENT_FILE_COPIED)
#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_INFO || (e) == DC_EVENT_WARNING || (e) == DC_EVENT_ERROR || (e) == DC_EVENT_SMTP_CONNECTED || (e) == DC_EVENT_SMTP_MESSAGE_SENT || (e) == DC_EVENT_IMAP_CONNECTED)
#define DC_EVENT_RETURNS_INT(e) ((e)==DC_EVENT_IS_OFFLINE)
@ -1041,14 +1059,6 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
#define DC_ERROR_SEE_STRING 0
/**
* The action cannot be performed because the user is not in the group.
* Reported by #DC_EVENT_ERROR eg. after a call to dc_set_chat_name(), dc_set_chat_profile_image(),
* dc_add_contact_to_chat(), dc_remove_contact_from_chat(), dc_send_text_msg() or another sending function.
*/
#define DC_ERROR_SELF_NOT_IN_GROUP 1
/**
* @}
*/
@ -1082,7 +1092,6 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
#define DC_STR_MSGADDMEMBER 17
#define DC_STR_MSGDELMEMBER 18
#define DC_STR_MSGGROUPLEFT 19
#define DC_STR_SELFNOTINGRP 21
#define DC_STR_GIF 23
#define DC_STR_ENCRYPTEDMSG 24
#define DC_STR_E2E_AVAILABLE 25