1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

add function to bind any location to a message object

This commit is contained in:
B. Petersen 2019-04-25 13:46:18 +02:00
parent b9fcace18e
commit 76250798ba
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
5 changed files with 86 additions and 0 deletions

View file

@ -449,6 +449,7 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline)
"send <text>\n" "send <text>\n"
"sendimage <file> [<text>]\n" "sendimage <file> [<text>]\n"
"sendfile <file>\n" "sendfile <file>\n"
"sendpoi <lat> <lang> <text>\n"
"draft [<text>]\n" "draft [<text>]\n"
"listmedia\n" "listmedia\n"
"archive <chat-id>\n" "archive <chat-id>\n"
@ -1035,6 +1036,31 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline)
ret = dc_strdup("No chat selected."); ret = dc_strdup("No chat selected.");
} }
} }
else if (strcmp(cmd, "sendpoi")==0)
{
if (sel_chat) {
char* arg2 = arg1? strchr(arg1, ' ') : NULL;
if (arg2) { *arg2 = 0; arg2++; }
char* arg3 = arg2? strchr(arg2, ' ') : NULL;
if (arg3) { *arg3 = 0; arg3++; }
if (arg1 && arg2 && arg3) {
dc_msg_t* msg = dc_msg_new(context,DC_MSG_TEXT);
dc_msg_set_text(msg, arg3);
dc_msg_set_location(msg, dc_atof(arg1), dc_atof(arg2), 2.0);
dc_send_msg(context, dc_chat_get_id(sel_chat), msg);
dc_msg_unref(msg);
ret = COMMAND_SUCCEEDED;
}
else {
ret = dc_strdup("ERROR: Usage: sendpoi <lat> <lng> <text>");
}
}
else {
ret = dc_strdup("No chat selected.");
}
}
else if (strcmp(cmd, "listmsgs")==0) else if (strcmp(cmd, "listmsgs")==0)
{ {
if (arg1) { if (arg1) {

View file

@ -1165,6 +1165,37 @@ void dc_msg_set_duration(dc_msg_t* msg, int duration)
} }
/**
* Set any location that should be bound to the message object.
* The function is useful to add a marker to the map
* at a position different from the self-location.
* You should not call this function
* if you want to bind the current self-location to a message;
* this is done by dc_set_location() and 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_msg_t
* @param context The message object.
* @param latitude North-south position of the location.
* @param longitude East-west position of the location.
* @param accuracy Estimated accuracy of the location, radial, in meters.
* Set to 0.0 if the accuracy is not known.
* @return None.
*/
void dc_msg_set_location(dc_msg_t* msg, double latitude, double longitude, double accuracy)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || (latitude==0.0 && longitude==0.0)) {
return;
}
dc_param_set_float(msg->param, DC_PARAM_SET_LATITUDE, latitude);
dc_param_set_float(msg->param, DC_PARAM_SET_LONGITUDE, longitude);
dc_param_set_float(msg->param, DC_PARAM_SET_ACCURACY, accuracy);
}
/** /**
* Late filing information to a message. * Late filing information to a message.
* In contrast to the dc_msg_set_*() functions, this function really stores the information in the database. * In contrast to the dc_msg_set_*() functions, this function really stores the information in the database.

View file

@ -304,3 +304,27 @@ void dc_param_set_int(dc_param_t* param, int key, int32_t value)
dc_param_set(param, key, value_str); dc_param_set(param, key, value_str);
free(value_str); free(value_str);
} }
/**
* Set parameter to a float.
*
* @memberof dc_param_t
* @param param Parameter object to modify.
* @param key Key of the parameter to modify, one of the DC_PARAM_* constants.
* @param value Value to store for key.
* @return None.
*/
void dc_param_set_float(dc_param_t* param, int key, double value)
{
if (param==NULL || key==0) {
return;
}
char* value_str = dc_ftoa(value);
if (value_str==NULL) {
return;
}
dc_param_set(param, key, value_str);
free(value_str);
}

View file

@ -43,6 +43,9 @@ struct _dc_param
#define DC_PARAM_CMD_ARG4 'H' /* for msgs */ #define DC_PARAM_CMD_ARG4 'H' /* for msgs */
#define DC_PARAM_ERROR 'L' /* for msgs */ #define DC_PARAM_ERROR 'L' /* for msgs */
#define DC_PARAM_PREP_FORWARDS 'P' /* for msgs in PREPARING: space-separated list of message IDs of forwarded copies */ #define DC_PARAM_PREP_FORWARDS 'P' /* for msgs in PREPARING: space-separated list of message IDs of forwarded copies */
#define DC_PARAM_SET_LATITUDE 'l' /* for msgs */
#define DC_PARAM_SET_LONGITUDE 'n' /* for msgs */
#define DC_PARAM_SET_ACCURACY 'y' /* for msgs */
#define DC_PARAM_SERVER_FOLDER 'Z' /* for jobs */ #define DC_PARAM_SERVER_FOLDER 'Z' /* for jobs */
#define DC_PARAM_SERVER_UID 'z' /* for jobs */ #define DC_PARAM_SERVER_UID 'z' /* for jobs */
@ -65,6 +68,7 @@ char* dc_param_get (const dc_param_t*, int key, const char*
int32_t dc_param_get_int (const dc_param_t*, int key, int32_t def); int32_t dc_param_get_int (const dc_param_t*, int key, int32_t def);
void dc_param_set (dc_param_t*, int key, const char* value); void dc_param_set (dc_param_t*, int key, const char* value);
void dc_param_set_int (dc_param_t*, int key, int32_t value); void dc_param_set_int (dc_param_t*, int key, int32_t value);
void dc_param_set_float (dc_param_t*, int key, double value);
/* library-private */ /* library-private */
dc_param_t* dc_param_new (); dc_param_t* dc_param_new ();

View file

@ -550,6 +550,7 @@ void dc_msg_set_text (dc_msg_t*, const char* text);
void dc_msg_set_file (dc_msg_t*, const char* file, const char* filemime); void dc_msg_set_file (dc_msg_t*, const char* file, const char* filemime);
void dc_msg_set_dimension (dc_msg_t*, int width, int height); void dc_msg_set_dimension (dc_msg_t*, int width, int height);
void dc_msg_set_duration (dc_msg_t*, int duration); void dc_msg_set_duration (dc_msg_t*, int duration);
void dc_msg_set_location (dc_msg_t*, double latitude, double longitude, double accuracy);
void dc_msg_latefiling_mediasize (dc_msg_t*, int width, int height, int duration); void dc_msg_latefiling_mediasize (dc_msg_t*, int width, int height, int duration);