Skip to content

Commit a5d4a8c

Browse files
committed
remove message hashes/ids from notifications
1 parent e9d6dc6 commit a5d4a8c

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/widget/widget.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,23 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
12171217
chatListWidget->addFriendWidget(widget);
12181218

12191219

1220-
auto notifyReceivedCallback = [this, friendPk](const ToxPk& author, const Message& message) {
1220+
auto notifyReceivedCallback = [this, friendPk](const ToxPk& author, const Message& message, const int hasIdType) {
12211221
std::ignore = author;
1222-
newFriendMessageAlert(friendPk, message.content);
1222+
1223+
auto strip_len = (TOX_MSGV3_MSGID_LENGTH * 2) + 1;
1224+
if ((hasIdType == static_cast<int>(Widget::MessageHasIdType::MSGV3_ID)) && (message.content.size() > strip_len))
1225+
{
1226+
// remove hex of msgV3_hash and "_" -> strip_len
1227+
QString message_text_only = message.content.mid(strip_len);
1228+
// qDebug() << "friendMessageDispatcher:notifyReceivedCallback:hasIdType=" << hasIdType << "message.content="
1229+
// << message.content << "message.content.size=" << message.content.size()
1230+
// << "message_text_only=" << message_text_only;
1231+
newFriendMessageAlert(friendPk, message_text_only);
1232+
}
1233+
else
1234+
{
1235+
newFriendMessageAlert(friendPk, message.content);
1236+
}
12231237
};
12241238

12251239
auto notifyReceivedConnection =
@@ -2276,13 +2290,27 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
22762290
std::make_shared<ChatHistory>(*newgroup, history, *core, settings,
22772291
*messageDispatcher, *friendList, *groupList);
22782292

2279-
auto notifyReceivedCallback = [this, groupId](const ToxPk& author, const Message& message) {
2293+
auto notifyReceivedCallback = [this, groupId, groupnumber](const ToxPk& author, const Message& message) {
22802294
auto isTargeted = std::any_of(message.metadata.begin(), message.metadata.end(),
22812295
[](MessageMetadata metadata) {
22822296
return metadata.type == MessageMetadataType::selfMention;
22832297
});
2284-
newGroupMessageAlert(groupId, author, message.content,
2298+
2299+
auto strip_len = 8 + 1; // 8 -> 4 bytes as hex + 1 -> ':'
2300+
if ((groupnumber >= Settings::NGC_GROUPNUM_OFFSET) && (message.content.size() > strip_len))
2301+
{
2302+
QString message_text_only = message.content.mid(strip_len);
2303+
// qDebug() << "GroupMessageDispatcher:notifyReceivedCallback:groupnumber=" << groupnumber
2304+
// << "message.content=" << message.content << "message_text_only=" << message_text_only
2305+
// << "message.content.len=" << message.content.size();
2306+
newGroupMessageAlert(groupId, author, message_text_only,
22852307
isTargeted || settings.getGroupAlwaysNotify());
2308+
}
2309+
else
2310+
{
2311+
newGroupMessageAlert(groupId, author, message.content,
2312+
isTargeted || settings.getGroupAlwaysNotify());
2313+
}
22862314
};
22872315

22882316
auto notifyReceivedConnection =

0 commit comments

Comments
 (0)