[Libreoffice-commits] online.git: loleaflet/src

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jun 1 10:39:51 UTC 2017


 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 402c2ce2ad36ce7a1cf2e7964cf114818e37541e
Author: Ashod Nakashian <ashod.nakashian at 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/38292
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/layer/AnnotationManager.js b/loleaflet/src/layer/AnnotationManager.js
index 7dc2e5c6..a32ed91c 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -123,6 +123,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) {
@@ -148,6 +151,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) {
@@ -519,6 +525,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 891386b7..1e06bae5 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: L.LOUtil.rgbToHex(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


More information about the Libreoffice-commits mailing list