Skip to content

Commit aba15ec

Browse files
committed
id set changes
1 parent f725c1a commit aba15ec

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/countly.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,18 @@ void Countly::_sendIndependantLocationRequest() {
288288
#pragma region Device Id
289289
void Countly::setDeviceID(const std::string &value, bool same_user) {
290290
mutex->lock();
291-
configuration->deviceId = value;
292-
log(LogLevel::INFO, "[Countly][changeDeviceIdWithMerge] setDeviceID = '" + value + "'");
291+
log(LogLevel::INFO, "[Countly][setDeviceID] setDeviceID requested = '" + value + "'");
293292

294-
// Checking old and new devices ids are same
295-
if (session_params.contains("device_id") && session_params["device_id"].get<std::string>() == value) {
296-
log(LogLevel::DEBUG, "[Countly][setDeviceID] new device id and old device id are same.");
293+
if (!session_params.contains("device_id")) {
294+
session_params["device_id"] = value;
295+
configuration->deviceId = value;
296+
log(LogLevel::DEBUG, "[Countly][setDeviceID] no previous device id, assigning initial device id");
297297
mutex->unlock();
298298
return;
299299
}
300300

301-
if (!session_params.contains("device_id")) {
302-
session_params["device_id"] = value;
303-
log(LogLevel::DEBUG, "[Countly][setDeviceID] no device was set, setting device id");
301+
if (session_params["device_id"].get<std::string>() == value) {
302+
log(LogLevel::DEBUG, "[Countly][setDeviceID] new device id equals existing device id, ignoring.");
304303
mutex->unlock();
305304
return;
306305
}
@@ -325,6 +324,7 @@ void Countly::_changeDeviceIdWithMerge(const std::string &value) {
325324

326325
session_params["old_device_id"] = session_params["device_id"];
327326
session_params["device_id"] = value;
327+
configuration->deviceId = value;
328328

329329
const std::chrono::system_clock::time_point now = Countly::getTimestamp();
330330
const auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
@@ -340,7 +340,6 @@ void Countly::_changeDeviceIdWithMerge(const std::string &value) {
340340
mutex->unlock();
341341
}
342342

343-
/* Change device ID without merge after SDK has been initialized.*/
344343
void Countly::_changeDeviceIdWithoutMerge(const std::string &value) {
345344
log(LogLevel::DEBUG, "[Countly][changeDeviceIdWithoutMerge] deviceId = '" + value + "'");
346345

@@ -352,6 +351,7 @@ void Countly::_changeDeviceIdWithoutMerge(const std::string &value) {
352351

353352
mutex->lock();
354353
session_params["device_id"] = value;
354+
configuration->deviceId = value;
355355
mutex->unlock();
356356

357357
// start a new session for new user

0 commit comments

Comments
 (0)