Page MenuHomePhabricator

D5179.id16949.diff
No OneTemporary

D5179.id16949.diff

diff --git a/services/tunnelbroker/src/Database/DatabaseManager.h b/services/tunnelbroker/src/Database/DatabaseManager.h
--- a/services/tunnelbroker/src/Database/DatabaseManager.h
+++ b/services/tunnelbroker/src/Database/DatabaseManager.h
@@ -43,6 +43,9 @@
findSessionItem(const std::string &deviceID);
void removeSessionItem(const std::string &sessionID);
void updateSessionItemIsOnline(const std::string &sessionID, bool isOnline);
+ bool updateSessionItemDeviceToken(
+ const std::string &sessionID,
+ const std::string &newDeviceToken);
void putSessionSignItem(const SessionSignItem &item);
std::shared_ptr<SessionSignItem>
diff --git a/services/tunnelbroker/src/Database/DatabaseManager.cpp b/services/tunnelbroker/src/Database/DatabaseManager.cpp
--- a/services/tunnelbroker/src/Database/DatabaseManager.cpp
+++ b/services/tunnelbroker/src/Database/DatabaseManager.cpp
@@ -115,6 +115,45 @@
}
}
+bool DatabaseManager::updateSessionItemDeviceToken(
+ const std::string &sessionID,
+ const std::string &newDeviceToken) {
+ std::shared_ptr<DeviceSessionItem> item = this->findSessionItem(sessionID);
+ if (item == nullptr) {
+ LOG(ERROR) << "Can't find for update sessionItem for sessionID: "
+ << sessionID;
+ return false;
+ }
+ Aws::DynamoDB::Model::UpdateItemRequest request;
+ request.SetTableName(item->getTableName());
+
+ Aws::DynamoDB::Model::AttributeValue attributeKeyValue;
+ attributeKeyValue.SetS(sessionID);
+ request.AddKey(DeviceSessionItem::FIELD_SESSION_ID, attributeKeyValue);
+ Aws::String update_expression("SET #a = :valueA");
+ request.SetUpdateExpression(update_expression);
+ Aws::Map<Aws::String, Aws::String> expressionAttributeNames;
+ expressionAttributeNames["#a"] = DeviceSessionItem::FIELD_NOTIFY_TOKEN;
+ request.SetExpressionAttributeNames(expressionAttributeNames);
+
+ Aws::DynamoDB::Model::AttributeValue attributeUpdatedValue;
+ attributeUpdatedValue.SetS(newDeviceToken);
+ Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue>
+ expressionAttributeValue;
+ expressionAttributeValue[":valueA"] = attributeUpdatedValue;
+ request.SetExpressionAttributeValues(expressionAttributeValue);
+
+ const Aws::DynamoDB::Model::UpdateItemOutcome &result =
+ getDynamoDBClient()->UpdateItem(request);
+ if (!result.IsSuccess()) {
+ LOG(ERROR)
+ << "Error updating device token at updateSessionItemDeviceToken: "
+ << result.GetError().GetMessage();
+ return false;
+ }
+ return true;
+}
+
void DatabaseManager::putSessionSignItem(const SessionSignItem &item) {
Aws::DynamoDB::Model::PutItemRequest request;
request.SetTableName(item.getTableName());

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 28, 1:26 PM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594093
Default Alt Text
D5179.id16949.diff (2 KB)

Event Timeline