Question:
I want to allow users to mark some annotations as public, so any other user can see them. While non-public (private) annotations are not.
How do I do this?
Answer:
The simplest way to accomplish this is to separate a users private and public annotations when you export/import. The idea would be that in your DB you would have two entries for each user/document. One entry contains that users private annotations in XFDF XML format, and the other contains their public annotations in same format.
Then when, for example, user Alice views the document, you query your DB and grab both of Alice's entries (private/public) and import into WebViewer. Then you can query your DB for any other Public annotations from other users for the same document, and lazy load those. Then Alice would see her own private annots, and everyone's public annots (including hers).
Essentially, you only load the annots that you want visible, into WebViewer, and simply don't load the other users private ones.
You would also need to track which of the users annots are public/private.
This code shows how to export these annots with your custom flag. This way at runtime users could toggle private/public on their own annots.
var publicAnnots = annotManager.getAnnotationsList().filter(function(annot) {
if(annot.author === annotManager.getCurrentUser()) {
if(annot.customKeyIsPublic) return annot;
}
});
var privateAnnots = annotManager.getAnnotationsList().filter(function(annot) {
if(annot.author === annotManager.getCurrentUser()) {
if(!annot.customKeyIsPublic) return annot;
}
});
var publicAnnotsXfdfXmlString = annotManager.exportAnnotations({annotList: publicAnnots});
var privateAnnotsXfdfXmlString = annotManager.exportAnnotations({annotList: privateAnnots});
You would Post the last two vars to your server for storage in your DB.
Then later on you would use the following to import. Where the two input strings are from your server in your own Get request.
var importedAnnots annotManager.importAnnotations(xfdfUsersPublicAnnots);
importedAnnots.forEach(function(annot) {
annot.customKeyIsPublic = true;
});
var importedAnnots annotManager.importAnnotations(xfdfUsersPrivateAnnots);
importedAnnots.forEach(function(annot) {
annot.customKeyIsPublic = false;
});
If you want to support real-time collaboration, then there are some slight changes to the above logic. Ask the support team if that case applies to you.