aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-18 15:21:22 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-18 15:21:22 +0100
commitf57863e8ddbf60a034071101ba6af40eee5a4797 (patch)
treef6a7638c2bc1c4291d719515a0a6aca9168b1e2f
parentfc3e6095465c119e9b58777ccb385ae91181eafe (diff)
downloadlibgnunetchat-f57863e8ddbf60a034071101ba6af40eee5a4797.tar.gz
libgnunetchat-f57863e8ddbf60a034071101ba6af40eee5a4797.zip
Allowed delayed callbacks for messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_handle_intern.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index f4ec2e9..96a8d0f 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -375,6 +375,43 @@ on_handle_identity(void *cls,
375} 375}
376 376
377void 377void
378on_handle_message_callback(void *cls)
379{
380 struct GNUNET_CHAT_Message *message = (struct GNUNET_CHAT_Message*) cls;
381
382 if ((!message) || (!(message->msg)))
383 return;
384
385 struct GNUNET_CHAT_Context *context = message->context;
386
387 if (!context)
388 return;
389
390 switch (message->msg->header.kind)
391 {
392 case GNUNET_MESSENGER_KIND_DELETE:
393 {
394 struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get(
395 context->messages, &(message->msg->body.deletion.hash)
396 );
397
398 if (target)
399 target->msg = NULL;
400 break;
401 }
402 default:
403 break;
404 }
405
406 struct GNUNET_CHAT_Handle *handle = context->handle;
407
408 if ((!handle) || (!(handle->msg_cb)))
409 return;
410
411 handle->msg_cb(handle->msg_cls, context, message);
412}
413
414void
378on_handle_message (void *cls, 415on_handle_message (void *cls,
379 struct GNUNET_MESSENGER_Room *room, 416 struct GNUNET_MESSENGER_Room *room,
380 const struct GNUNET_MESSENGER_Contact *sender, 417 const struct GNUNET_MESSENGER_Contact *sender,
@@ -444,6 +481,8 @@ on_handle_message (void *cls,
444 if (message) 481 if (message)
445 return; 482 return;
446 483
484 struct GNUNET_SCHEDULER_Task* task = NULL;
485
447 message = message_create_from_msg(context, hash, flags, msg); 486 message = message_create_from_msg(context, hash, flags, msg);
448 487
449 switch (msg->header.kind) 488 switch (msg->header.kind)
@@ -491,12 +530,15 @@ on_handle_message (void *cls,
491 } 530 }
492 case GNUNET_MESSENGER_KIND_DELETE: 531 case GNUNET_MESSENGER_KIND_DELETE:
493 { 532 {
494 struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get( 533 struct GNUNET_TIME_Relative delay = GNUNET_TIME_relative_ntoh(
495 context->messages, &(msg->body.deletion.hash) 534 msg->body.deletion.delay
496 ); 535 );
497 536
498 if (target) 537 task = GNUNET_SCHEDULER_add_delayed(
499 target->msg = NULL; 538 delay,
539 on_handle_message_callback,
540 message
541 );
500 break; 542 break;
501 } 543 }
502 default: 544 default:
@@ -507,12 +549,15 @@ on_handle_message (void *cls,
507 context->messages, hash, message, 549 context->messages, hash, message,
508 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 550 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
509 { 551 {
552 if (task)
553 GNUNET_SCHEDULER_cancel(task);
554
510 message_destroy(message); 555 message_destroy(message);
511 return; 556 return;
512 } 557 }
513 558
514 if (handle->msg_cb) 559 if (!task)
515 handle->msg_cb(handle->msg_cls, context, message); 560 on_handle_message_callback(message);
516} 561}
517 562
518int 563int