1
- /* Copyright (C) 2020-2021 k4be
1
+ /* Copyright (C) 2020-2021, 2023 k4be
2
2
** Copyright (C) 2023 Valentin Lorentz
3
3
** License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
4
4
*/
@@ -164,8 +164,8 @@ struct metadata_moddata_user {
164
164
struct metadata_unsynced * us ;
165
165
};
166
166
167
- struct metadata_unsynced { /* we're listing users (nicknames ) that should be synced but were not */
168
- char * name ;
167
+ struct metadata_unsynced { /* we're listing users (UIDs ) that should be synced but were not */
168
+ char * id ;
169
169
char * key ;
170
170
struct metadata_unsynced * next ;
171
171
};
@@ -548,11 +548,24 @@ int metadata_notify_or_queue(Client *client, const char *who, const char *key, c
548
548
metadata_send_change (client , who , key , value , changer );
549
549
} else
550
550
{ /* store for the SYNC */
551
+ Client * who_client ;
552
+ const char * uid_or_channel ;
553
+ if (* who == '#' ) {
554
+ uid_or_channel = who ;
555
+ } else {
556
+ who_client = find_client (who , NULL ); /* FIXME the caller should already have this figured out */
557
+ if (!who_client ) {
558
+ unreal_log (ULOG_DEBUG , "metadata" , "METADATA_DEBUG" , changer , "metadata_notify_or_queue called with nonexistent client!" );
559
+ return 0 ; /* shouldn't happen */
560
+ }
561
+ uid_or_channel = who_client -> id ;
562
+ }
563
+
551
564
trylater = 1 ;
552
565
while (* us )
553
566
us = & (* us )-> next ; /* find last list element */
554
567
* us = safe_alloc (sizeof (struct metadata_unsynced ));
555
- (* us )-> name = strdup (who );
568
+ (* us )-> id = strdup (uid_or_channel );
556
569
(* us )-> key = strdup (key );
557
570
(* us )-> next = NULL ;
558
571
}
@@ -690,7 +703,7 @@ void metadata_user_free(ModData *md)
690
703
metadata_free_list (metadata , NULL , NULL );
691
704
while (us )
692
705
{
693
- safe_free (us -> name );
706
+ safe_free (us -> id );
694
707
safe_free (us -> key );
695
708
prev_us = us ;
696
709
us = us -> next ;
@@ -1375,23 +1388,41 @@ int metadata_join(Client *client, Channel *channel, MessageTag *mtags)
1375
1388
1376
1389
void metadata_sync (Client * client )
1377
1390
{
1378
- Client * acptr ;
1391
+ Client * acptr = NULL ;
1379
1392
Channel * channel = NULL ;
1393
+ int do_send = 0 ;
1394
+ char * who ;
1380
1395
1381
1396
struct metadata_moddata_user * my_moddata = USER_METADATA (client );
1382
1397
if (!my_moddata )
1383
1398
return ; /* nothing queued */
1384
1399
struct metadata_unsynced * us = my_moddata -> us ;
1385
1400
struct metadata_unsynced * prev_us ;
1386
-
1401
+
1387
1402
while (us )
1388
1403
{
1389
1404
if (!IsSendable (client ))
1390
1405
break ;
1391
- acptr = hash_find_nickatserver (us -> name , NULL );
1392
- if (acptr && has_common_channels (acptr , client ))
1393
- { /* if not, the user has vanished since or one of us parted the channel */
1394
- struct metadata_moddata_user * moddata = USER_METADATA (acptr );
1406
+ if (* us -> id == '#' ) {
1407
+ channel = find_channel (us -> id );
1408
+ if (channel && IsMember (client , channel )) {
1409
+ do_send = 1 ;
1410
+ who = us -> id ;
1411
+ }
1412
+ } else {
1413
+ acptr = find_client (us -> id , NULL );
1414
+ if (acptr && has_common_channels (acptr , client )) { /* if not, the user has vanished since or one of us parted the channel */
1415
+ do_send = 1 ;
1416
+ who = acptr -> name ;
1417
+ }
1418
+ }
1419
+
1420
+ if (do_send ) {
1421
+ struct metadata_moddata_user * moddata ;
1422
+ if (acptr )
1423
+ moddata = USER_METADATA (acptr );
1424
+ else
1425
+ moddata = CHANNEL_METADATA (channel );
1395
1426
if (moddata )
1396
1427
{
1397
1428
struct metadata * metadata = moddata -> metadata ;
@@ -1401,7 +1432,7 @@ void metadata_sync(Client *client)
1401
1432
{ /* has it */
1402
1433
const char * value = metadata_get_user_key_value (acptr , us -> key );
1403
1434
if (value )
1404
- metadata_send_change (client , us -> name , us -> key , value , NULL );
1435
+ metadata_send_change (client , us -> id , us -> key , value , NULL );
1405
1436
}
1406
1437
metadata = metadata -> next ;
1407
1438
}
@@ -1410,7 +1441,7 @@ void metadata_sync(Client *client)
1410
1441
/* now remove the processed entry */
1411
1442
prev_us = us ;
1412
1443
us = us -> next ;
1413
- safe_free (prev_us -> name );
1444
+ safe_free (prev_us -> id );
1414
1445
safe_free (prev_us );
1415
1446
my_moddata -> us = us ; /* we're always removing the first list item */
1416
1447
}
0 commit comments