Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(core): prepare qTox for groupchat saving
Browse files Browse the repository at this point in the history
This change creates groups on startup of Core. We need this once
TokTok/c-toxcore#1156 is merged to load existing
groups.
  • Loading branch information
sudden6 committed Nov 22, 2018
1 parent 793d744 commit a82eb6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ void Core::onStarted()
emit idSet(id);

loadFriends();
loadGroups();

process(); // starts its own timer
av->start();
Expand Down Expand Up @@ -990,16 +991,15 @@ void Core::loadFriends()
{
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) {
return;
}

// assuming there are not that many friends to fill up the whole stack
uint32_t* ids = new uint32_t[friendCount];
tox_self_get_friend_list(tox.get(), ids);
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)) {
continue;
}
Expand All @@ -1012,6 +1012,25 @@ void Core::loadFriends()
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)
{
QMutexLocker ml{coreLoopLock.get()};
Expand Down
1 change: 1 addition & 0 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public slots:
void makeTox(QByteArray savedata, ICoreSettings* s);
void makeAv();
void loadFriends();
void loadGroups();
void bootstrapDht();

void checkLastOnline(uint32_t friendId);
Expand Down

0 comments on commit a82eb6f

Please sign in to comment.