diff -ru bitlbee-3.4.1/protocols/jabber/conference.c bitlbee-3.4.1~/protocols/jabber/conference.c
|
old
|
new
|
|
| 26 | 26 | |
| 27 | 27 | static xt_status jabber_chat_join_failed(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); |
| 28 | 28 | |
| | 29 | void jabber_chat_update_last_message(struct groupchat *chat, time_t date) |
| | 30 | { |
| | 31 | char path[512]; |
| | 32 | FILE *fp; |
| | 33 | |
| | 34 | g_snprintf(path, sizeof(path) - 1, "%slast_message_%s_%s", global.conf->configdir, chat->ic->acc->tag, chat->title); |
| | 35 | |
| | 36 | if ((fp = fopen(path, "w"))) { |
| | 37 | fprintf(fp, "%ld", (long)date); |
| | 38 | fclose(fp); |
| | 39 | } |
| | 40 | } |
| | 41 | |
| | 42 | char *jabber_chat_get_last_message(struct groupchat *chat) |
| | 43 | { |
| | 44 | char path[512]; |
| | 45 | char *buf = NULL; |
| | 46 | time_t date; |
| | 47 | FILE *fp; |
| | 48 | |
| | 49 | g_snprintf(path, sizeof(path) - 1, "%slast_message_%s_%s", global.conf->configdir, chat->ic->acc->tag, chat->title); |
| | 50 | |
| | 51 | if ((fp = fopen(path, "r"))) { |
| | 52 | fscanf(fp, "%ld", &date); |
| | 53 | /* receive messages starting one second after this date */ |
| | 54 | date += 1; |
| | 55 | buf = g_malloc(64); |
| | 56 | strftime(buf, 63, "%Y-%m-%dT%H:%M:%SZ", gmtime(&date)); |
| | 57 | fclose(fp); |
| | 58 | } |
| | 59 | |
| | 60 | return buf; |
| | 61 | } |
| | 62 | |
| 29 | 63 | struct groupchat *jabber_chat_join(struct im_connection *ic, const char *room, const char *nick, const char *password) |
| 30 | 64 | { |
| 31 | 65 | struct jabber_chat *jc; |
| 32 | 66 | struct xt_node *node; |
| 33 | 67 | struct groupchat *c; |
| 34 | 68 | char *roomjid; |
| | 69 | char *last_message_date; |
| | 70 | |
| | 71 | c = imcb_chat_new(ic, room); |
| 35 | 72 | |
| 36 | 73 | roomjid = g_strdup_printf("%s/%s", room, nick); |
| 37 | 74 | node = xt_new_node("x", NULL, NULL); |
| … |
… |
|
| 39 | 76 | if (password) { |
| 40 | 77 | xt_add_child(node, xt_new_node("password", password, NULL)); |
| 41 | 78 | } |
| | 79 | |
| | 80 | last_message_date = jabber_chat_get_last_message(c); |
| | 81 | if (last_message_date) { |
| | 82 | struct xt_node *history; |
| | 83 | history = xt_new_node("history", NULL, NULL); |
| | 84 | xt_add_attr(history, "since", last_message_date); |
| | 85 | xt_add_child(node, history); |
| | 86 | g_free(last_message_date); |
| | 87 | } |
| | 88 | |
| 42 | 89 | node = jabber_make_packet("presence", NULL, roomjid, node); |
| 43 | 90 | jabber_cache_add(ic, node, jabber_chat_join_failed); |
| 44 | 91 | |
| … |
… |
|
| 61 | 108 | of the nick to send a proper presence update. */ |
| 62 | 109 | jc->my_full_jid = roomjid; |
| 63 | 110 | |
| 64 | | c = imcb_chat_new(ic, room); |
| 65 | 111 | c->data = jc; |
| 66 | 112 | |
| 67 | 113 | return c; |
| … |
… |
|
| 359 | 405 | char *nick = NULL; |
| 360 | 406 | char *final_from = NULL; |
| 361 | 407 | char *bare_jid = NULL; |
| | 408 | time_t date; |
| 362 | 409 | |
| 363 | 410 | from = (bud) ? bud->full_jid : xt_find_attr(node, "from"); |
| 364 | 411 | |
| … |
… |
|
| 433 | 480 | } else { |
| 434 | 481 | final_from = nick; |
| 435 | 482 | } |
| 436 | | |
| 437 | | imcb_chat_msg(chat, final_from, body->text, 0, jabber_get_timestamp(node)); |
| | 483 | |
| | 484 | date = jabber_get_timestamp(node); |
| | 485 | jabber_chat_update_last_message(chat, date); |
| | 486 | imcb_chat_msg(chat, final_from, body->text, 0, date); |
| 438 | 487 | |
| 439 | 488 | g_free(bare_jid); |
| 440 | 489 | } |