@@ -243,10 +243,12 @@ void populateReply(TwitchChannel *channel, Communi::IrcMessage *message,
243
243
TwitchMessageBuilder &builder)
244
244
{
245
245
const auto &tags = message->tags ();
246
- if (const auto it = tags.find (" reply-parent-msg-id" ); it != tags.end ())
246
+ if (const auto it = tags.find (" reply-thread-parent-msg-id" );
247
+ it != tags.end ())
247
248
{
248
249
const QString replyID = it.value ().toString ();
249
250
auto threadIt = channel->threads ().find (replyID);
251
+ std::shared_ptr<MessageThread> rootThread;
250
252
if (threadIt != channel->threads ().end ())
251
253
{
252
254
auto owned = threadIt->second .lock ();
@@ -256,43 +258,80 @@ void populateReply(TwitchChannel *channel, Communi::IrcMessage *message,
256
258
updateReplyParticipatedStatus (tags, message->nick (), builder,
257
259
owned, false );
258
260
builder.setThread (owned);
259
- return ;
261
+ rootThread = owned ;
260
262
}
261
263
}
262
264
263
- MessagePtr foundMessage;
264
-
265
- // Thread does not yet exist, find root reply and create thread.
266
- // Linear search is justified by the infrequent use of replies
267
- for (const auto &otherMsg : otherLoaded)
265
+ if (!rootThread)
268
266
{
269
- if (otherMsg->id == replyID)
267
+ MessagePtr foundMessage;
268
+
269
+ // Thread does not yet exist, find root reply and create thread.
270
+ // Linear search is justified by the infrequent use of replies
271
+ for (const auto &otherMsg : otherLoaded)
270
272
{
271
- // Found root reply message
272
- foundMessage = otherMsg;
273
- break ;
273
+ if (otherMsg->id == replyID)
274
+ {
275
+ // Found root reply message
276
+ foundMessage = otherMsg;
277
+ break ;
278
+ }
274
279
}
275
- }
276
280
277
- if (!foundMessage)
278
- {
279
- // We didn't find the reply root message in the otherLoaded messages
280
- // which are typically the already-parsed recent messages from the
281
- // Recent Messages API. We could have a really old message that
282
- // still exists being replied to, so check for that here.
283
- foundMessage = channel->findMessage (replyID);
281
+ if (!foundMessage)
282
+ {
283
+ // We didn't find the reply root message in the otherLoaded messages
284
+ // which are typically the already-parsed recent messages from the
285
+ // Recent Messages API. We could have a really old message that
286
+ // still exists being replied to, so check for that here.
287
+ foundMessage = channel->findMessage (replyID);
288
+ }
289
+
290
+ if (foundMessage)
291
+ {
292
+ std::shared_ptr<MessageThread> newThread =
293
+ std::make_shared<MessageThread>(foundMessage);
294
+ updateReplyParticipatedStatus (tags, message->nick (), builder,
295
+ newThread, true );
296
+
297
+ builder.setThread (newThread);
298
+ rootThread = newThread;
299
+ // Store weak reference to thread in channel
300
+ channel->addReplyThread (newThread);
301
+ }
284
302
}
285
303
286
- if (foundMessage)
304
+ if (const auto parentIt = tags.find (" reply-parent-msg-id" );
305
+ parentIt != tags.end ())
287
306
{
288
- std::shared_ptr<MessageThread> newThread =
289
- std::make_shared<MessageThread>(foundMessage);
290
- updateReplyParticipatedStatus (tags, message->nick (), builder,
291
- newThread, true );
292
-
293
- builder.setThread (newThread);
294
- // Store weak reference to thread in channel
295
- channel->addReplyThread (newThread);
307
+ const QString parentID = parentIt.value ().toString ();
308
+ if (replyID == parentID)
309
+ {
310
+ if (rootThread)
311
+ {
312
+ builder.setParent (rootThread->root ());
313
+ }
314
+ }
315
+ else
316
+ {
317
+ auto parentThreadIt = channel->threads ().find (parentID);
318
+ if (parentThreadIt != channel->threads ().end ())
319
+ {
320
+ auto thread = parentThreadIt->second .lock ();
321
+ if (thread)
322
+ {
323
+ builder.setParent (thread->root ());
324
+ }
325
+ }
326
+ else
327
+ {
328
+ auto parent = channel->findMessage (parentID);
329
+ if (parent)
330
+ {
331
+ builder.setParent (parent);
332
+ }
333
+ }
334
+ }
296
335
}
297
336
}
298
337
}
@@ -1283,17 +1322,20 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
1283
1322
TwitchMessageBuilder builder (chan.get (), message, args, content, isAction);
1284
1323
builder.setMessageOffset (messageOffset);
1285
1324
1286
- if (const auto it = tags.find (" reply-parent-msg-id" ); it != tags.end ())
1325
+ if (const auto it = tags.find (" reply-thread-parent-msg-id" );
1326
+ it != tags.end ())
1287
1327
{
1288
1328
const QString replyID = it.value ().toString ();
1289
- auto threadIt = channel->threads_ .find (replyID);
1290
- if (threadIt != channel->threads_ .end () && !threadIt->second .expired ())
1329
+ auto threadIt = channel->threads ().find (replyID);
1330
+ std::shared_ptr<MessageThread> rootThread;
1331
+ if (threadIt != channel->threads ().end () && !threadIt->second .expired ())
1291
1332
{
1292
1333
// Thread already exists (has a reply)
1293
1334
auto thread = threadIt->second .lock ();
1294
1335
updateReplyParticipatedStatus (tags, message->nick (), builder,
1295
1336
thread, false );
1296
1337
builder.setThread (thread);
1338
+ rootThread = thread;
1297
1339
}
1298
1340
else
1299
1341
{
@@ -1307,10 +1349,44 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
1307
1349
newThread, true );
1308
1350
1309
1351
builder.setThread (newThread);
1352
+ rootThread = newThread;
1310
1353
// Store weak reference to thread in channel
1311
1354
channel->addReplyThread (newThread);
1312
1355
}
1313
1356
}
1357
+
1358
+ if (const auto parentIt = tags.find (" reply-parent-msg-id" );
1359
+ parentIt != tags.end ())
1360
+ {
1361
+ const QString parentID = parentIt.value ().toString ();
1362
+ if (replyID == parentID)
1363
+ {
1364
+ if (rootThread)
1365
+ {
1366
+ builder.setParent (rootThread->root ());
1367
+ }
1368
+ }
1369
+ else
1370
+ {
1371
+ auto parentThreadIt = channel->threads ().find (parentID);
1372
+ if (parentThreadIt != channel->threads ().end ())
1373
+ {
1374
+ auto thread = parentThreadIt->second .lock ();
1375
+ if (thread)
1376
+ {
1377
+ builder.setParent (thread->root ());
1378
+ }
1379
+ }
1380
+ else
1381
+ {
1382
+ auto parent = channel->findMessage (parentID);
1383
+ if (parent)
1384
+ {
1385
+ builder.setParent (parent);
1386
+ }
1387
+ }
1388
+ }
1389
+ }
1314
1390
}
1315
1391
1316
1392
if (isSub || !builder.isIgnored ())
0 commit comments