From 8b15ba21b25ea45e21d5a4f10a8c5be108a54f77 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 29 Apr 2008 14:51:50 +0000 Subject: [PATCH] Identify sticky-notes divs by vnote uid, not by msgnum. This will make the ajax calls easier to implement. --- citadel/modules/notes/serv_notes.c | 74 +++++++++++++++++++++++++++--- webcit/notes.c | 24 +++++----- webcit/static/wclib.js | 14 +++--- webcit/static/webcit.css | 1 + 4 files changed, 87 insertions(+), 26 deletions(-) diff --git a/citadel/modules/notes/serv_notes.c b/citadel/modules/notes/serv_notes.c index 18ba3ad1a..56c1e6ee9 100644 --- a/citadel/modules/notes/serv_notes.c +++ b/citadel/modules/notes/serv_notes.c @@ -44,19 +44,37 @@ #include "ctdl_module.h" +/* + * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure + */ +void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp, + void *content, char *cbtype, char *cbcharset, size_t length, + char *encoding, void *cbuserdata) +{ + struct vnote **v = (struct vnote **) cbuserdata; + + if (!strcasecmp(cbtype, "text/vnote")) { + + CtdlLogPrintf(CTDL_DEBUG, "Part %s contains a vNote! Loading...\n", partnum); + if (*v != NULL) { + vnote_free(*v); + } + *v = vnote_new_from_str(content); + } +} + /* - * If we are in a "notes" view room, and the client has sent an RFC822 - * message containing an X-KOrg-Note-Id: field (Aethera does this, as - * do some Kolab clients) then set both the Subject and the Exclusive ID - * of the message to that. It's going to be a UUID so we want to replace - * any existing message containing that UUID. + * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes + * and modern vNote format notes) and does its best to learn the subject (summary) + * and EUID (uid) of the note for Citadel's own nefarious purposes. */ int serv_notes_beforesave(struct CtdlMessage *msg) { char *p; int a, i; - char uuid[SIZ]; + char uuid[512]; + struct vnote *v = NULL; /* First determine if this room has the "notes" view set */ @@ -69,7 +87,13 @@ int serv_notes_beforesave(struct CtdlMessage *msg) return(0); /* You tried to save a non-RFC822 message! */ } - /* Find the X-KOrg-Note-Id: header */ + /* + * If we are in a "notes" view room, and the client has sent an RFC822 + * message containing an X-KOrg-Note-Id: field (Aethera does this, as + * do some Kolab clients) then set both the Subject and the Exclusive ID + * of the message to that. It's going to be a UUID so we want to replace + * any existing message containing that UUID. + */ strcpy(uuid, ""); p = msg->cm_fields['M']; a = strlen(p); @@ -99,6 +123,42 @@ int serv_notes_beforesave(struct CtdlMessage *msg) } p++; } + + /* Modern clients are using vNote format. Check for one... */ + + mime_parser(msg->cm_fields['M'], + NULL, + *notes_extract_vnote, + NULL, NULL, + &v, /* user data ptr - put the vnote here */ + 0 + ); + + if (v == NULL) return(0); /* no vNotes were found in this message */ + + /* Set the message EUID to the vNote UID */ + + if (v->uid) if (!IsEmptyStr(v->uid)) { + CtdlLogPrintf(9, "UID of vNote is: %s\n", v->uid); + if (msg->cm_fields['E'] != NULL) { + free(msg->cm_fields['E']); + } + msg->cm_fields['E'] = strdup(v->uid); + } + + /* Set the message Subject to the vNote Summary */ + + if (v->summary) if (!IsEmptyStr(v->summary)) { + if (msg->cm_fields['U'] != NULL) { + free(msg->cm_fields['U']); + } + msg->cm_fields['U'] = strdup(v->summary); + if (strlen(msg->cm_fields['U']) > 72) { + strcpy(&msg->cm_fields['U'][68], "..."); + } + } + + vnote_free(v); return(0); } diff --git a/webcit/notes.c b/webcit/notes.c index e1e3042a2..cfee05776 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -164,11 +164,11 @@ void updatenote(void) /* * Display a
containing a rendered sticky note. */ -void display_vnote_div(struct vnote *v, long msgnum) { +void display_vnote_div(struct vnote *v) { /* begin outer div */ - wprintf("
uid); wprintf("class=\"stickynote_outer\" "); wprintf("style=\""); wprintf("left: %dpx; ", v->pos_left); @@ -180,15 +180,15 @@ void display_vnote_div(struct vnote *v, long msgnum) { /* begin title bar */ - wprintf("
uid); wprintf("class=\"stickynote_titlebar\" "); - wprintf("onMouseDown=\"NotesDragMouseDown(event,%ld)\" ", msgnum); + wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid); wprintf("style=\""); wprintf("background-color: #%02X%02X%02X ", v->color_red/2, v->color_green/2, v->color_blue/2); wprintf("\">"); wprintf(""); - wprintf("", msgnum); + wprintf(""); // nothing in the title bar, it's just for dragging wprintf("
 "); - wprintf("document.write('L: ' + $('note%ld').style.left + '
');", msgnum); - wprintf("document.write('T: ' + $('note%ld').style.top + '
');", msgnum); - wprintf("document.write('W: ' + $('note%ld').style.width + '
');", msgnum); - wprintf("document.write('H: ' + $('note%ld').style.height + '
');", msgnum); + wprintf("document.write('L: ' + $('note-%s').style.left + '
');", v->uid); + wprintf("document.write('T: ' + $('note-%s').style.top + '
');", v->uid); + wprintf("document.write('W: ' + $('note-%s').style.width + '
');", v->uid); + wprintf("document.write('H: ' + $('note-%s').style.height + '
');", v->uid); wprintf(""); + /* */ + vnote_free(v); } } } diff --git a/webcit/static/wclib.js b/webcit/static/wclib.js index fca12b2fb..e6a57cfaa 100644 --- a/webcit/static/wclib.js +++ b/webcit/static/wclib.js @@ -426,7 +426,7 @@ function CtdlResizeMsgListMouseDown(evt) { // These functions handle moving sticky notes around the screen by dragging them -var msgnum_of_note_being_dragged = 0; +var uid_of_note_being_dragged = 0; var saved_cursor_style = 'default'; var note_was_dragged = 0; @@ -437,7 +437,7 @@ function NotesDragMouseUp(evt) { document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE); } - d = $('note' + msgnum_of_note_being_dragged); + d = $('note-' + uid_of_note_being_dragged); d.style.cursor = saved_cursor_style; // Only submit the change if motion actually happened @@ -445,7 +445,7 @@ function NotesDragMouseUp(evt) { alert('FIXME do ajax call to move position x=' + d.style.left + ' y=' + d.style.top); } - msgnum_of_note_being_dragged = 0; + uid_of_note_being_dragged = ''; return true; } @@ -456,7 +456,7 @@ function NotesDragMouseMove(evt) { y_increment = y - saved_y; // Move the div - d = $('note' + msgnum_of_note_being_dragged); + d = $('note-' + uid_of_note_being_dragged); divTop = parseInt(d.style.top); divLeft = parseInt(d.style.left); @@ -471,7 +471,7 @@ function NotesDragMouseMove(evt) { } -function NotesDragMouseDown(evt, msgnum) { +function NotesDragMouseDown(evt, uid) { saved_x = (ns6 ? evt.clientX : event.clientX); saved_y = (ns6 ? evt.clientY : event.clientY); document.onmouseup = NotesDragMouseUp; @@ -479,8 +479,8 @@ function NotesDragMouseDown(evt, msgnum) { if (document.layers) { document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE); } - msgnum_of_note_being_dragged = msgnum; - d = $('note' + msgnum_of_note_being_dragged); + uid_of_note_being_dragged = uid; + d = $('note-' + uid_of_note_being_dragged); saved_cursor_style = d.style.cursor; d.style.cursor = 'move'; return false; // disable the default action diff --git a/webcit/static/webcit.css b/webcit/static/webcit.css index 537a2ce7f..8c6cb18ef 100644 --- a/webcit/static/webcit.css +++ b/webcit/static/webcit.css @@ -1338,4 +1338,5 @@ li.event_unread span, a.event_read_title { top: 0px; left: 0px; background-color: #888800; + font-size: 6px; } -- 2.30.2