loleaflet/src/layer/AnnotationManager.js |   10 ++++++++++
 loleaflet/src/layer/marker/Annotation.js |    2 ++
 loleaflet/src/map/Map.js                 |   16 ++++++++++++++++
 3 files changed, 28 insertions(+)

New commits:
commit 508c31396e2a668dce97d3580d02dd0e4404afe4
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Wed May 31 23:57:23 2017 -0400

    loleaflet: show avatar in comments
    
    Change-Id: I97a781a2faf626c2ac6f4b178127aaa77c7775d0
    Reviewed-on: https://gerrit.libreoffice.org/38303
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/loleaflet/src/layer/AnnotationManager.js 
b/loleaflet/src/layer/AnnotationManager.js
index cd55ae15..6adb5cad 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -122,6 +122,9 @@ L.AnnotationManager = L.Class.extend({
                for (var index in comments) {
                        comment = comments[index];
                        this.adjustComment(comment);
+                       if (this._map._viewInfoByUser[comment.author]) {
+                               comment.avatar = 
this._map._viewInfoByUser[comment.author].userextrainfo.avatar;
+                       }
                        
this._items.push(L.annotation(this._map.options.maxBounds.getSouthEast(), 
comment).addTo(this._map));
                }
                if (this._items.length > 0) {
@@ -139,6 +142,9 @@ L.AnnotationManager = L.Class.extend({
                                // something wrong in this redline, skip this 
one
                                continue;
                        }
+                       if (this._map._viewInfoByUser[changecomment.author]) {
+                               changecomment.avatar = 
this._map._viewInfoByUser[changecomment.author].userextrainfo.avatar;
+                       }
                        
this._items.push(L.annotation(this._map.options.maxBounds.getSouthEast(), 
changecomment).addTo(this._map));
                }
                if (this._items.length > 0) {
@@ -504,6 +510,10 @@ L.AnnotationManager = L.Class.extend({
                var id;
                var changetrack = obj.redline ? true : false;
                var action = changetrack ? obj.redline.action : 
obj.comment.action;
+               if (this._map._viewInfoByUser[obj.comment.author]) {
+                       obj.comment.avatar = 
this._map._viewInfoByUser[obj.comment.author].userextrainfo.avatar;
+               }
+
                if (action === 'Add') {
                        if (changetrack) {
                                if (!this.adjustRedLine(obj.redline)) {
diff --git a/loleaflet/src/layer/marker/Annotation.js 
b/loleaflet/src/layer/marker/Annotation.js
index 5c577289..8b3e0653 100644
--- a/loleaflet/src/layer/marker/Annotation.js
+++ b/loleaflet/src/layer/marker/Annotation.js
@@ -153,6 +153,7 @@ L.Annotation = L.Layer.extend({
                imgAuthor.setAttribute('src', L.Icon.Default.imagePath + 
'/user.png');
                imgAuthor.setAttribute('width', this.options.imgSize.x);
                imgAuthor.setAttribute('height', this.options.imgSize.y);
+               this._authorAvatarImg = imgAuthor;
                L.DomUtil.create(tagDiv, 'loleaflet-annotation-userline', 
tdImg);
                this._contentAuthor = L.DomUtil.create(tagDiv, 
'loleaflet-annotation-content-author', tdAuthor);
                this._contentDate = L.DomUtil.create(tagDiv, 
'loleaflet-annotation-date', tdAuthor);
@@ -291,6 +292,7 @@ L.Annotation = L.Layer.extend({
                this._contentText.origText = this._data.text;
                $(this._nodeModifyText).text(this._data.text);
                $(this._contentAuthor).text(this._data.author);
+               $(this._authorAvatarImg).attr('src', this._data.avatar);
 
                var d = new Date(this._data.dateTime.replace(/,.*/, 'Z'));
                $(this._contentDate).text((isNaN(d.getTime()) || 
this._map.getDocType() === 'spreadsheet')? this._data.dateTime: 
d.toDateString());
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index c809980e..5d8fae67 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -134,6 +134,7 @@ L.Map = L.Evented.extend({
 
                // View info (user names and view ids)
                this._viewInfo = {};
+               this._viewInfoByUser = {};
 
                // View color map
                this._viewColors = {};
@@ -160,14 +161,18 @@ L.Map = L.Evented.extend({
 
        addView: function(viewInfo) {
                this._viewInfo[viewInfo.id] = viewInfo;
+               this._viewInfoByUser[viewInfo.userid] = viewInfo;
                this.fire('postMessage', {msgId: 'View_Added', args: {ViewId: 
viewInfo.id, UserId: viewInfo.userid, UserName: viewInfo.username, 
UserExtraInfo: viewInfo.userextrainfo, Color: viewInfo.color, ReadOnly: 
viewInfo.readonly}});
 
                // Fire last, otherwise not all events are handled correctly.
                this.fire('addview', {viewId: viewInfo.id, username: 
viewInfo.username, extraInfo: viewInfo.userextrainfo, readonly: 
this.isViewReadOnly(viewInfo.id)});
+
+               this.updateAvatars();
        },
 
        removeView: function(viewid) {
                var username = this._viewInfo[viewid].username;
+               delete this._viewInfoByUser[this._viewInfo[viewid].userid];
                delete this._viewInfo[viewid];
                this.fire('postMessage', {msgId: 'View_Removed', args: {ViewId: 
viewid}});
 
@@ -183,6 +188,17 @@ L.Map = L.Evented.extend({
                return this;
        },
 
+       updateAvatars: function() {
+               if (this._docLayer && this._docLayer._annotations && 
this._docLayer._annotations._items) {
+                       for (var idxAnno in this._docLayer._annotations._items) 
{
+                               var userid = 
this._docLayer._annotations._items[idxAnno]._data.author;
+                               if (this._viewInfoByUser[userid]) {
+                                       
$(this._docLayer._annotations._items[idxAnno]._authorAvatarImg).attr('src', 
this._viewInfoByUser[userid].userextrainfo.avatar);
+                               }
+                       }
+               }
+       },
+
        showBusy: function(label, bar) {
                // If document is already loaded, ask the toolbar widget to 
show busy
                // status on the bottom statusbar
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to