text stringlengths 0 357 |
|---|
/** |
* Enable or disable location streaming for a chat. |
* Locations are sent to all members of the chat for the given number of seconds; |
* after that, location streaming is automatically disabled for the chat. |
* The current location streaming state of a chat |
* can be checked using dc_is_sending_locations_to_chat(). |
* |
* The locations that should be sent to the chat can be set using |
* dc_set_location(). |
* |
* @memberof dc_context_t |
* @param context The context object. |
* @param chat_id Chat id to enable location streaming for. |
* @param seconds >0: enable location streaming for the given number of seconds; |
* 0: disable location streaming. |
* @return None. |
*/ |
void dc_send_locations_to_chat(dc_context_t* context, uint32_t chat_id, |
int seconds) |
{ |
sqlite3_stmt* stmt = NULL; |
time_t now = time(NULL); |
dc_msg_t* msg = NULL; |
char* stock_str = NULL; |
int is_sending_locations_before = 0; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || seconds<0 |
|| chat_id<=DC_CHAT_ID_LAST_SPECIAL) { |
goto cleanup; |
} |
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id); |
stmt = dc_sqlite3_prepare(context->sql, |
"UPDATE chats " |
" SET locations_send_begin=?, " |
" locations_send_until=? " |
" WHERE id=?"); |
sqlite3_bind_int64(stmt, 1, seconds? now : 0); |
sqlite3_bind_int64(stmt, 2, seconds? now+seconds : 0); |
sqlite3_bind_int (stmt, 3, chat_id); |
sqlite3_step(stmt); |
// add/sent status message. |
// as disable also happens after a timeout, this is not sent explicitly. |
if (seconds && !is_sending_locations_before) { |
msg = dc_msg_new(context, DC_MSG_TEXT); |
msg->text = dc_stock_system_msg(context, DC_STR_MSGLOCATIONENABLED, NULL, NULL, 0); |
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_LOCATION_STREAMING_ENABLED); |
dc_send_msg(context, chat_id, msg); |
} |
else if(!seconds && is_sending_locations_before) { |
stock_str = dc_stock_system_msg(context, DC_STR_MSGLOCATIONDISABLED, NULL, NULL, 0); |
dc_add_device_msg(context, chat_id, stock_str); |
} |
// update eg. the "location-sending"-icon |
context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); |
if (seconds) { |
schedule_MAYBE_SEND_LOCATIONS(context, 0); |
dc_job_add(context, DC_JOB_MAYBE_SEND_LOC_ENDED, chat_id, NULL, seconds+1); |
} |
cleanup: |
free(stock_str); |
dc_msg_unref(msg); |
sqlite3_finalize(stmt); |
} |
/** |
* Check if location streaming is enabled. |
* Location stream can be enabled or disabled using dc_send_locations_to_chat(). |
* If you have already a dc_chat_t object, |
* dc_chat_is_sending_locations() may be more handy. |
* |
* @memberof dc_context_t |
* @param context The context object. |
* @param chat_id >0: Check if location streaming is enabled for the given chat. |
* 0: Check of location streaming is enabled for any chat. |
* @return 1: location streaming is enabled for the given chat(s); |
* 0: location streaming is disabled for the given chat(s). |
*/ |
int dc_is_sending_locations_to_chat(dc_context_t* context, uint32_t chat_id) |
{ |
int is_sending_locations = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT id " |
" FROM chats " |
" WHERE (? OR id=?)" |
" AND locations_send_until>?;"); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.