text
stringlengths
0
357
" AND independent=0 "
" ORDER BY timestamp;");
}
else {
sqlite3_reset(stmt_locations);
}
sqlite3_bind_int (stmt_locations, 1, DC_CONTACT_ID_SELF);
sqlite3_bind_int64 (stmt_locations, 2, locations_send_begin);
sqlite3_bind_int64 (stmt_locations, 3, locations_last_sent);
// if there is no new location, there's nothing to send.
// however, maybe we want to bypass this test eg. 15 minutes
if (sqlite3_step(stmt_locations)!=SQLITE_ROW) {
continue;
}
// pending locations are attached automatically to every message,
// so also to this empty text message.
// DC_CMD_LOCATION is only needed to create a nicer subject.
//
// for optimisation and to avoid flooding the sending queue,
// we could sending these messages only if we're really online.
// the easiest way to determine this, is to check for an empty message queue.
// (might not be 100%, however, as positions are sent combined later
// and dc_set_location() is typically called periodically, this is ok)
dc_msg_t* msg = dc_msg_new(context, DC_MSG_TEXT);
msg->hidden = 1;
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_LOCATION_ONLY);
dc_send_msg(context, chat_id, msg);
dc_msg_unref(msg);
}
if (continue_streaming) {
// force scheduing as there is at least one job - the current one
schedule_MAYBE_SEND_LOCATIONS(context, FORCE_SCHEDULE);
}
//cleanup:
sqlite3_finalize(stmt_chats);
sqlite3_finalize(stmt_locations);
}
void dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(dc_context_t* context, dc_job_t* job)
{
// this function is called when location-streaming _might_ have ended for a chat.
// the function checks, if location-streaming is really ended;
// if so, a device-message is added if not yet done.
uint32_t chat_id = job->foreign_id;
time_t locations_send_begin = 0;
time_t locations_send_until = 0;
sqlite3_stmt* stmt = NULL;
char* stock_str = NULL;
stmt = dc_sqlite3_prepare(context->sql,
"SELECT locations_send_begin, locations_send_until "
" FROM chats "
" WHERE id=?");
sqlite3_bind_int (stmt, 1, chat_id);
if (sqlite3_step(stmt)!=SQLITE_ROW) {
goto cleanup;
}
locations_send_begin = sqlite3_column_int64(stmt, 0);
locations_send_until = sqlite3_column_int64(stmt, 1);
sqlite3_finalize(stmt);
stmt = NULL;
if (locations_send_begin!=0 && time(NULL)<=locations_send_until) {
// still streaming -
// may happen as several calls to dc_send_locations_to_chat()
// do not un-schedule pending DC_MAYBE_SEND_LOC_ENDED jobs
goto cleanup;
}
if (locations_send_begin==0 && locations_send_until==0) {
// not streaming, device-message already sent
goto cleanup;
}
// inform the ui that location-streaming has ended
stmt = dc_sqlite3_prepare(context->sql,
"UPDATE chats "
" SET locations_send_begin=0, locations_send_until=0 "
" WHERE id=?");
sqlite3_bind_int (stmt, 1, chat_id);
sqlite3_step(stmt);
stock_str = dc_stock_system_msg(context, DC_STR_MSGLOCATIONDISABLED, NULL, NULL, 0);
dc_add_device_msg(context, chat_id, stock_str);
context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0);
cleanup:
sqlite3_finalize(stmt);
free(stock_str);
}
/*******************************************************************************
* high-level ui-functions
******************************************************************************/