Skip to content

Commit

Permalink
add more NGC callbacks and save when they are called
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Sep 23, 2023
1 parent ccf8220 commit e5bf84a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,70 @@ Core::~Core()
tox.reset();
}

void Core::on_tox_group_connection_status_cb(Tox *tox, uint32_t group_number, int32_t status,
void* vCore)
{
std::ignore = tox;
Core* core = static_cast<Core*>(vCore);
std::ignore = core;

std::ignore = group_number;
std::ignore = status;
emit core->saveRequest();
}

void Core::on_tox_group_peer_status_cb(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_User_Status status,
void* vCore)
{
std::ignore = tox;
Core* core = static_cast<Core*>(vCore);
std::ignore = core;

std::ignore = group_number;
std::ignore = peer_id;
std::ignore = status;
emit core->saveRequest();
}

void Core::on_tox_group_privacy_state_cb(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state,
void* vCore)
{
std::ignore = tox;
Core* core = static_cast<Core*>(vCore);
std::ignore = core;

std::ignore = group_number;
std::ignore = privacy_state;
emit core->saveRequest();
}

void Core::on_tox_group_password_cb(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length,
void* vCore)
{
std::ignore = tox;
Core* core = static_cast<Core*>(vCore);
std::ignore = core;

std::ignore = group_number;
std::ignore = password;
std::ignore = length;
emit core->saveRequest();
}

void Core::on_tox_group_moderation_cb(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id,
Tox_Group_Mod_Event mod_type, void* vCore)
{
std::ignore = tox;
Core* core = static_cast<Core*>(vCore);
std::ignore = core;

std::ignore = group_number;
std::ignore = source_peer_id;
std::ignore = target_peer_id;
std::ignore = mod_type;
emit core->saveRequest();
}

/**
* @brief Registers all toxcore callbacks
* @param tox Tox instance to register the callbacks on
Expand All @@ -132,6 +196,13 @@ void Core::registerCallbacks(Tox* tox)
tox_callback_group_peer_join(tox, onNgcPeerJoin);
tox_callback_group_peer_exit(tox, onNgcPeerExit);
tox_callback_group_peer_name(tox, onNgcPeerName);

tox_callback_group_connection_status(tox, on_tox_group_connection_status_cb);
tox_callback_group_peer_status(tox, on_tox_group_peer_status_cb);
tox_callback_group_privacy_state(tox, on_tox_group_privacy_state_cb);
tox_callback_group_password(tox, on_tox_group_password_cb);
tox_callback_group_moderation(tox, on_tox_group_moderation_cb);

tox_callback_group_message(tox, onNgcGroupMessage);
tox_callback_group_private_message(tox, onNgcGroupPrivateMessage);
tox_callback_group_custom_packet(tox, onNgcGroupCustomPacket);
Expand Down Expand Up @@ -1060,6 +1131,7 @@ void Core::onGroupPeerListChange(Tox* tox, uint32_t groupId, void* vCore)
qDebug() << QString("Group %1 peerlist changed").arg(groupId);
// no saveRequest, this callback is called on every connection to group peer, not just on brand new peers
emit core->groupPeerlistChanged(groupId);
emit core->saveRequest();
}

void Core::onGroupPeerNameChange(Tox* tox, uint32_t groupId, uint32_t peerId, const uint8_t* name,
Expand All @@ -1071,6 +1143,7 @@ void Core::onGroupPeerNameChange(Tox* tox, uint32_t groupId, uint32_t peerId, co
auto* core = static_cast<Core*>(vCore);
auto peerPk = core->getGroupPeerPk(groupId, peerId);
emit core->groupPeerNameChanged(groupId, peerPk, newName);
emit core->saveRequest();
}

void Core::onGroupTitleChange(Tox* tox, uint32_t groupId, uint32_t peerId, const uint8_t* cTitle,
Expand Down
13 changes: 13 additions & 0 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ public slots:
void sendGroupMessageWithType(int groupId, const QString& message, Tox_Message_Type type);
bool sendMessageWithType(uint32_t friendId, const QString& message, const QString& id_or_hash, const QDateTime& timestamp,
Tox_Message_Type type, ReceiptNum& receipt);

static void on_tox_group_connection_status_cb(Tox *tox, uint32_t group_number, int32_t status,
void* vCore);
static void on_tox_group_peer_status_cb(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_User_Status status,
void* vCore);
static void on_tox_group_privacy_state_cb(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state,
void* vCore);
static void on_tox_group_password_cb(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length,
void* vCore);
static void on_tox_group_moderation_cb(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id,
Tox_Group_Mod_Event mod_type, void* vCore);


bool checkConnection();

void makeTox(QByteArray savedata, ICoreSettings* s);
Expand Down

0 comments on commit e5bf84a

Please sign in to comment.