1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(core): prepare qTox for groupchat saving

This change creates groups on startup of Core. We need this once
https://github.com/TokTok/c-toxcore/pull/1156 is merged to load existing
groups.
This commit is contained in:
sudden6 2018-10-31 00:19:16 +01:00
parent 793d744705
commit a82eb6f36e
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 23 additions and 3 deletions

View File

@ -250,6 +250,7 @@ void Core::onStarted()
emit idSet(id); emit idSet(id);
loadFriends(); loadFriends();
loadGroups();
process(); // starts its own timer process(); // starts its own timer
av->start(); av->start();
@ -990,16 +991,15 @@ void Core::loadFriends()
{ {
QMutexLocker ml{coreLoopLock.get()}; QMutexLocker ml{coreLoopLock.get()};
const uint32_t friendCount = tox_self_get_friend_list_size(tox.get()); const size_t friendCount = tox_self_get_friend_list_size(tox.get());
if (friendCount == 0) { if (friendCount == 0) {
return; return;
} }
// assuming there are not that many friends to fill up the whole stack
uint32_t* ids = new uint32_t[friendCount]; uint32_t* ids = new uint32_t[friendCount];
tox_self_get_friend_list(tox.get(), ids); tox_self_get_friend_list(tox.get(), ids);
uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00}; uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00};
for (uint32_t i = 0; i < friendCount; ++i) { for (size_t i = 0; i < friendCount; ++i) {
if (!tox_friend_get_public_key(tox.get(), ids[i], friendPk, nullptr)) { if (!tox_friend_get_public_key(tox.get(), ids[i], friendPk, nullptr)) {
continue; continue;
} }
@ -1012,6 +1012,25 @@ void Core::loadFriends()
delete[] ids; delete[] ids;
} }
void Core::loadGroups()
{
QMutexLocker ml{coreLoopLock.get()};
const size_t groupCount = tox_conference_get_chatlist_size(tox.get());
if (groupCount == 0) {
return;
}
uint32_t* groupIds = new uint32_t[groupCount];
tox_conference_get_chatlist(tox.get(), groupIds);
for(size_t i = 0; i < groupCount; ++i) {
emit emptyGroupCreated(static_cast<int>(groupIds[i]));
}
delete[] groupIds;
}
void Core::checkLastOnline(uint32_t friendId) void Core::checkLastOnline(uint32_t friendId)
{ {
QMutexLocker ml{coreLoopLock.get()}; QMutexLocker ml{coreLoopLock.get()};

View File

@ -245,6 +245,7 @@ private:
void makeTox(QByteArray savedata, ICoreSettings* s); void makeTox(QByteArray savedata, ICoreSettings* s);
void makeAv(); void makeAv();
void loadFriends(); void loadFriends();
void loadGroups();
void bootstrapDht(); void bootstrapDht();
void checkLastOnline(uint32_t friendId); void checkLastOnline(uint32_t friendId);