dcorking / google-wave-resources

Automatically exported from code.google.com/p/google-wave-resources
0 stars 0 forks source link

API: setAnnotation should do nothing if annotation exists (wishlist) #192

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Many bots call setAnnotation "blindly", without checking for existing
annotations. Right now, this causes extra annotation events to be sent to
the server. The server _appears_ to pass these events straight back to the
bots, increasing the risk of bot loops.

Instead, it would be nice if setAnnotation refrained from sending any edit
events when the annotations already exist.

I'm guessing this will be implemented automatically once bots start to use
the federation protocol.

But in the meantime, here's my best attempt at a workaround:

  /**
   * Add an annotation if it isn't already present.
   * 
   * The Wave Robot API does not currently filter out duplicate annotation
   * requests, which causes extra network traffic and more possibilities for
   * nasty bot loops.  So we do this screening on our end.
   */
  private void maybeAnnotate(TextView doc, Range range, String name,
      String value) {
    // If this annotation is already present, give up now.  Note that
    // we allow the existing annotation to be bigger than the one we're
    // creating, because in that case, setting the new annotation won't
    // do anything useful.
    for (Annotation annotation : doc.getAnnotations(range, name)) {
      if (annotation.getValue().equals(value) &&
          annotation.getRange().getStart() <= range.getStart() &&
          range.getEnd() <= annotation.getRange().getEnd())
        return;
    }
    doc.setAnnotation(range, name, value);
  }

Original issue reported on code.google.com by eric.k...@gmail.com on 29 Aug 2009 at 2:04

GoogleCodeExporter commented 9 years ago
Thanks, we'll look into this.

Original comment by pamela.fox on 6 Oct 2009 at 4:45

GoogleCodeExporter commented 9 years ago
woot. work in progress. I like! how can I help?

Original comment by goleph...@gmail.com on 8 Nov 2009 at 3:55

Attachments: