comparison mcabber/src/commands.c @ 1019:9d5f6e0ea7b3

XEP-0145: display note dates Display note creation/modification dates (if available) in /roster note.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 15 Nov 2006 22:24:20 +0100
parents 4d3c48844746
children 60c94b697f61
comparison
equal deleted inserted replaced
1018:45d022fbce3a 1019:9d5f6e0ea7b3
468 } 468 }
469 469
470 static void roster_note(char *arg) 470 static void roster_note(char *arg)
471 { 471 {
472 const char *jid; 472 const char *jid;
473 gchar *msg, *note; 473 gchar *msg, *notetxt;
474 guint type; 474 guint type;
475 475
476 if (!current_buddy) 476 if (!current_buddy)
477 return; 477 return;
478 478
491 else 491 else
492 msg = NULL; 492 msg = NULL;
493 493
494 if (msg) { // Set a note 494 if (msg) { // Set a note
495 if (!strcmp(msg, "-")) 495 if (!strcmp(msg, "-"))
496 note = NULL; // delete note 496 notetxt = NULL; // delete note
497 else 497 else
498 note = msg; 498 notetxt = msg;
499 jb_set_storage_rosternotes(jid, note); 499 jb_set_storage_rosternotes(jid, notetxt);
500 g_free(msg);
500 } else { // Display a note 501 } else { // Display a note
501 note = jb_get_storage_rosternotes(jid); 502 struct annotation *note = jb_get_storage_rosternotes(jid);
502 if (note) 503 if (note) {
503 msg = g_strdup_printf("Note: %s", note); 504 char tbuf[128];
504 else 505 guint msg_flag = HBB_PREFIX_INFO;
505 msg = g_strdup_printf("This item doesn't have a note."); 506 /* We use the flag prefix_info for the first line, and prefix_none
506 scr_WriteIncomingMessage(jid, msg, 0, HBB_PREFIX_INFO); 507 for the other lines, for better readability */
507 } 508
508 g_free(msg); 509 // If we have the creation date, display it
510 if (note->cdate) {
511 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
512 localtime(&note->cdate));
513 msg = g_strdup_printf("Note created %s", tbuf);
514 scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
515 g_free(msg);
516 msg_flag = HBB_PREFIX_NONE;
517 }
518 // If we have the modification date, display it
519 if (note->mdate) {
520 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
521 localtime(&note->mdate));
522 msg = g_strdup_printf("Note modified %s", tbuf);
523 scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
524 g_free(msg);
525 msg_flag = HBB_PREFIX_NONE;
526 }
527 // Note text
528 msg = g_strdup_printf("Note: %s", note->text);
529 scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
530 g_free(note->text);
531 g_free(note);
532 g_free(msg);
533 } else {
534 scr_WriteIncomingMessage(jid, "This item doesn't have a note.", 0,
535 HBB_PREFIX_INFO);
536 }
537 }
509 } 538 }
510 539
511 /* Commands callback functions */ 540 /* Commands callback functions */
512 /* All these do_*() functions will be called with a "arg" parameter */ 541 /* All these do_*() functions will be called with a "arg" parameter */
513 /* (with arg not null) */ 542 /* (with arg not null) */