MCPcopy Create free account
hub / github.com/blizzard4591/openMittsu / menuDatabaseImportLegacyContactsAndGroupsOnClick

Method menuDatabaseImportLegacyContactsAndGroupsOnClick

src/Client.cpp:1252–1312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1250}
1251
1252void Client::menuDatabaseImportLegacyContactsAndGroupsOnClick(QString const& legacyContactsFileName) {
1253 if (!m_databaseWrapper.hasDatabase()) {
1254 QMessageBox::warning(this, "No database loaded", "Before you can use this feature you need to load a database from file (see main screen) or create one using a backup of your existing ID (see Identity -> Load Backup).");
1255 } else {
1256 QString fileName;
1257 if (!legacyContactsFileName.isNull() && !legacyContactsFileName.isEmpty()) {
1258 fileName = legacyContactsFileName;
1259 } else {
1260 fileName = QFileDialog::getOpenFileName(this, tr("Select the legacy contacts and group file"));
1261 if (fileName.isNull() || fileName.isEmpty()) {
1262 return;
1263 }
1264 }
1265
1266 try {
1267 openmittsu::utility::LegacyContactImporter lci(openmittsu::utility::LegacyContactImporter::fromFile(fileName));
1268
1269 {
1270 QVector<openmittsu::database::NewContactData> newContacts;
1271 QHash<openmittsu::protocol::ContactId, std::pair<openmittsu::crypto::PublicKey, QString>> const& contacts = lci.getContacts();
1272 auto it = contacts.constBegin();
1273 auto end = contacts.constEnd();
1274 for (; it != end; ++it) {
1275 openmittsu::database::NewContactData newContact;
1276 newContact.id = it.key();
1277 newContact.publicKey = it.value().first;
1278 newContact.verificationStatus = openmittsu::protocol::ContactIdVerificationStatus::VERIFICATION_STATUS_SERVER_VERIFIED;
1279 newContact.nickName = it.value().second;
1280
1281 newContacts.append(newContact);
1282 }
1283 m_databaseWrapper.storeNewContact(newContacts);
1284 }
1285
1286 {
1287 QVector<openmittsu::database::NewGroupData> newGroups;
1288 QHash<openmittsu::protocol::GroupId, std::pair<QSet<openmittsu::protocol::ContactId>, QString>> const& groups = lci.getGroups();
1289 auto it = groups.constBegin();
1290 auto end = groups.constEnd();
1291 for (; it != end; ++it) {
1292 openmittsu::database::NewGroupData newGroup;
1293 newGroup.id = it.key();
1294 newGroup.members = it.value().first;
1295 newGroup.name = it.value().second;
1296 newGroup.createdAt = openmittsu::protocol::MessageTime::now();
1297 newGroup.isAwaitingSync = false;
1298 newGroup.isDeleted = false;
1299
1300 newGroups.append(newGroup);
1301 }
1302 m_databaseWrapper.storeNewGroup(newGroups);
1303 }
1304
1305 contactRegistryOnIdentitiesChanged();
1306
1307 QMessageBox::information(this, tr("Success!"), tr("Successfully imported %1 legacy contacts and %2 legacy groups.").arg(lci.getContactCount()).arg(lci.getGroupCount()));
1308 } catch (...) {
1309 QMessageBox::warning(this, tr("Could not import legacy contact file"), tr("Could not import legacy contact and group file!"));

Callers

nothing calls this directly

Calls 8

hasDatabaseMethod · 0.80
isEmptyMethod · 0.80
valueMethod · 0.80
isNullMethod · 0.45
storeNewContactMethod · 0.45
storeNewGroupMethod · 0.45
getContactCountMethod · 0.45
getGroupCountMethod · 0.45

Tested by

no test coverage detected