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

add a function to delete all locations

This commit is contained in:
B. Petersen 2019-03-11 12:12:30 +01:00
parent e4d2cf99e9
commit ad878a8c33
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
3 changed files with 42 additions and 0 deletions

View file

@ -458,6 +458,7 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline)
"chatinfo\n" "chatinfo\n"
"sendlocations <seconds>\n" "sendlocations <seconds>\n"
"setlocation <lat> <lng>\n" "setlocation <lat> <lng>\n"
"dellocations\n"
"getlocations\n" "getlocations\n"
"send <text>\n" "send <text>\n"
"sendimage <file> [<text>]\n" "sendimage <file> [<text>]\n"
@ -954,6 +955,10 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline)
ret = dc_strdup("ERROR: Latitude or longitude not given."); ret = dc_strdup("ERROR: Latitude or longitude not given.");
} }
} }
else if (strcmp(cmd, "dellocations")==0) {
dc_delete_all_locations(context);
ret = COMMAND_SUCCEEDED;
}
else if (strcmp(cmd, "send")==0) else if (strcmp(cmd, "send")==0)
{ {
if (sel_chat) { if (sel_chat) {

View file

@ -401,6 +401,9 @@ cleanup:
* The location is sent to all chats where location streaming is enabled * The location is sent to all chats where location streaming is enabled
* using dc_send_locations_to_chat(). * using dc_send_locations_to_chat().
* *
* Typically results in the event #DC_EVENT_LOCATION_CHANGED with
* contact_id set to DC_CONTACT_ID_SELF.
*
* @memberof dc_context_t * @memberof dc_context_t
* @param context The context object. * @param context The context object.
* @param latitude North-south position of the location. * @param latitude North-south position of the location.
@ -530,5 +533,36 @@ dc_array_t* dc_get_locations(dc_context_t* context, uint32_t chat_id, uint32_t
} }
cleanup: cleanup:
sqlite3_finalize(stmt);
return ret; return ret;
} }
/**
* Delete all locations on the current device.
* Locations already sent cannot be deleted.
*
* Typically results in the event #DC_EVENT_LOCATION_CHANGED
* with contact_id set to 0.
*
* @memberof dc_context_t
* @param context The context object.
* @return None.
*/
void dc_delete_all_locations(dc_context_t* context)
{
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
stmt = dc_sqlite3_prepare(context->sql,
"DELETE FROM locations;");
sqlite3_step(stmt);
context->cb(context, DC_EVENT_LOCATION_CHANGED, 0, 0);
cleanup:
sqlite3_finalize(stmt);
}

View file

@ -365,6 +365,7 @@ void dc_send_locations_to_chat (dc_context_t*, uint32_t chat_id, in
int dc_is_sending_locations_to_chat (dc_context_t*, uint32_t chat_id); int dc_is_sending_locations_to_chat (dc_context_t*, uint32_t chat_id);
int dc_set_location (dc_context_t*, double latitude, double longitude, double accuracy); int dc_set_location (dc_context_t*, double latitude, double longitude, double accuracy);
dc_array_t* dc_get_locations (dc_context_t*, uint32_t chat_id, uint32_t contact_id); dc_array_t* dc_get_locations (dc_context_t*, uint32_t chat_id, uint32_t contact_id);
void dc_delete_all_locations (dc_context_t*);
/** /**
@ -1000,6 +1001,8 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
* Location of one or more contact has changed. * Location of one or more contact has changed.
* *
* @param data1 (int) contact_id of the contact for which the location has changed. * @param data1 (int) contact_id of the contact for which the location has changed.
* If the locations of several contacts have been changed,
* eg. after calling dc_delete_all_locations(), this parameter is set to 0.
* @param data2 0 * @param data2 0
* @return 0 * @return 0
*/ */