Skip to content

Commit c22cbfe

Browse files
committed
feat(core): prepare qTox for groupchat saving
This change creates groups on startup of Core. We need this once TokTok/c-toxcore#1156 is merged to load existing groups.
1 parent a1a50b4 commit c22cbfe

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/core/core.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ void Core::onStarted()
250250
emit idSet(id);
251251

252252
loadFriends();
253+
loadGroups();
253254

254255
process(); // starts its own timer
255256
av->start();
@@ -990,16 +991,15 @@ void Core::loadFriends()
990991
{
991992
QMutexLocker ml{coreLoopLock.get()};
992993

993-
const uint32_t friendCount = tox_self_get_friend_list_size(tox.get());
994+
const size_t friendCount = tox_self_get_friend_list_size(tox.get());
994995
if (friendCount == 0) {
995996
return;
996997
}
997998

998-
// assuming there are not that many friends to fill up the whole stack
999999
uint32_t* ids = new uint32_t[friendCount];
10001000
tox_self_get_friend_list(tox.get(), ids);
10011001
uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00};
1002-
for (uint32_t i = 0; i < friendCount; ++i) {
1002+
for (size_t i = 0; i < friendCount; ++i) {
10031003
if (!tox_friend_get_public_key(tox.get(), ids[i], friendPk, nullptr)) {
10041004
continue;
10051005
}
@@ -1012,6 +1012,23 @@ void Core::loadFriends()
10121012
delete[] ids;
10131013
}
10141014

1015+
void Core::loadGroups()
1016+
{
1017+
QMutexLocker ml{coreLoopLock.get()};
1018+
1019+
const size_t groupCnt = tox_conference_get_chatlist_size(tox.get());
1020+
if (groupCnt == 0) {
1021+
return;
1022+
}
1023+
1024+
uint32_t* groupIds = new uint32_t[groupCnt];
1025+
tox_conference_get_chatlist(tox.get(), groupIds);
1026+
1027+
for(size_t i = 0; i < groupCnt; ++i) {
1028+
emit emptyGroupCreated(static_cast<int>(groupIds[i]));
1029+
}
1030+
}
1031+
10151032
void Core::checkLastOnline(uint32_t friendId)
10161033
{
10171034
QMutexLocker ml{coreLoopLock.get()};

src/core/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ public slots:
245245
void makeTox(QByteArray savedata, ICoreSettings* s);
246246
void makeAv();
247247
void loadFriends();
248+
void loadGroups();
248249
void bootstrapDht();
249250

250251
void checkLastOnline(uint32_t friendId);

0 commit comments

Comments
 (0)