text
stringlengths
0
357
sqlite3_bind_int (stmt, 1, chat_id==0? 1 : 0);
sqlite3_bind_int (stmt, 2, chat_id);
sqlite3_bind_int64(stmt, 3, time(NULL));
if (sqlite3_step(stmt)!=SQLITE_ROW) {
goto cleanup;
}
is_sending_locations = 1;
cleanup:
sqlite3_finalize(stmt);
return is_sending_locations;
}
/**
* Set current location.
* The location is sent to all chats where location streaming is enabled
* using dc_send_locations_to_chat().
*
* Typically results in the event #DC_EVENT_LOCATION_CHANGED with
* contact_id set to DC_CONTACT_ID_SELF.
*
* The UI should call this function on all location changes.
* The locations set by this function are not sent immediately,
* instead a message with the last locations is sent out every some minutes
* or when the user sends out a normal message,
* the last locations are attached.
*
* @memberof dc_context_t
* @param context The context object.
* @param latitude North-south position of the location.
* Set to 0.0 if the latitude is not known.
* @param longitude East-west position of the location.
* Set to 0.0 if the longitude is not known.
* @param accuracy Estimated accuracy of the location, radial, in meters.
* Set to 0.0 if the accuracy is not known.
* @return 1: location streaming is still enabled for at least one chat,
* this dc_set_location() should be called as soon as the location changes;
* 0: location streaming is no longer needed,
* dc_is_sending_locations_to_chat() is false for all chats.
*/
int dc_set_location(dc_context_t* context,
double latitude, double longitude, double accuracy)
{
sqlite3_stmt* stmt_chats = NULL;
sqlite3_stmt* stmt_insert = NULL;
int continue_streaming = 0;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC
|| (latitude==0.0 && longitude==0.0)) {
continue_streaming = 1;
goto cleanup;
}
stmt_chats = dc_sqlite3_prepare(context->sql,
"SELECT id FROM chats WHERE locations_send_until>?;");
sqlite3_bind_int64(stmt_chats, 1, time(NULL));
while (sqlite3_step(stmt_chats)==SQLITE_ROW)
{
uint32_t chat_id = sqlite3_column_int(stmt_chats, 0);
stmt_insert = dc_sqlite3_prepare(context->sql,
"INSERT INTO locations "
" (latitude, longitude, accuracy, timestamp, chat_id, from_id)"
" VALUES (?,?,?,?,?,?);");
sqlite3_bind_double(stmt_insert, 1, latitude);
sqlite3_bind_double(stmt_insert, 2, longitude);
sqlite3_bind_double(stmt_insert, 3, accuracy);
sqlite3_bind_int64 (stmt_insert, 4, time(NULL));
sqlite3_bind_int (stmt_insert, 5, chat_id);
sqlite3_bind_int (stmt_insert, 6, DC_CONTACT_ID_SELF);
sqlite3_step(stmt_insert);
continue_streaming = 1;
}
if (continue_streaming) {
context->cb(context, DC_EVENT_LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0);
schedule_MAYBE_SEND_LOCATIONS(context, 0);
}
cleanup:
sqlite3_finalize(stmt_chats);
sqlite3_finalize(stmt_insert);
return continue_streaming;
}
static int is_marker(const char* txt)
{
if (txt) {
int len = dc_utf8_strlen(txt);
if (len==1 && txt[0]!=' ') {
return 1;
}
}
return 0;
}