loleaflet/reference.html              |   23 ++++++++++++++++++---
 loleaflet/src/layer/tile/TileLayer.js |    4 +++
 loleaflet/src/map/Map.js              |    4 +--
 loleaflet/src/map/handler/Map.WOPI.js |   36 ++++++++++++++++++++--------------
 4 files changed, 48 insertions(+), 19 deletions(-)

New commits:
commit 51a63c0e7618acf6fbb536164030ebb7a9694aa1
Author:     Jan Holesovsky <ke...@collabora.com>
AuthorDate: Tue May 28 13:09:24 2019 +0200
Commit:     Jan Holesovsky <ke...@collabora.com>
CommitDate: Tue May 28 19:58:16 2019 +0200

    Deprecate Views_Added and Views_Removed; implement Views_List instead.
    
    This helps avoiding the situation when the state in the Online and in
    the integration get out of sync.
    
    The integration should always get the most current state via Views_List,
    and if they want to implement eg. notification what view has joined or
    has left, they should just compare the old and the new state.
    
    Change-Id: I841f77419bf86a57f77e16f8c0bd08063f31f68a
    Reviewed-on: https://gerrit.libreoffice.org/73103
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 767293068..7cb520ab9 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -2890,19 +2890,36 @@ Editor to WOPI host
                    <nobr>UserName: &lt;String&gt;</nobr>
                    <nobr>Color: &lt;Number&gt;</nobr>
                    <nobr>ReadOnly: &lt;Boolean&gt;</nobr>
+                   <nobr>Deprecated: true;</nobr>
                </code></td>
                <td>A new member is added. ViewId is unique integer
                identifying a session/view. UserId is user identity. UserName is
                display name of the user. Color is RGB color integer
-               value. ReadOnly tells if the new view is opened as readonly.
+               value. ReadOnly tells if the new view is opened as 
readonly.<br/>
+               This message is <strong>deprecated</strong>, instead implement 
just
+               handling of Views_List which holds the same payload as
+               <code>Get_Views_Resp</code>.
                </td>
        </tr>
        <tr>
                <td><code><b>View_Removed</b></code></td>
                <td><code>
                    <nobr>ViewId: &lt;Number&gt;</nobr>
-               </code></td>
-               <td>View with <code>ViewId</code> has closed the document.
+                   <nobr>Deprecated: true;</nobr>
+               </code></td>
+               <td>View with <code>ViewId</code> has closed the document.<br/>
+               This message is <strong>deprecated</strong>, instead implement 
just
+               handling of Get_Views_Resp and if you need the info which view 
has
+               been added / removed, check against the previous state.<br/>
+               This message is <strong>deprecated</strong>, instead implement 
just
+               handling of Views_List which holds the same payload as
+               <code>Get_Views_Resp</code>.
+               </td>
+       </tr>
+       <tr>
+               <td><code><b>Views_List</b></code></td>
+               <td>See <code>Get_Views_Resp</code>.</td>
+               <td>Complete information about the currently connected views.
                </td>
        </tr>
        </table>
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index a6cccc0a5..6dc66544e 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1067,6 +1067,10 @@ L.TileLayer = L.GridLayer.extend({
                                this._removeView(parseInt(viewInfoIdx));
                        }
                }
+
+               // Sending postMessage about View_Added / View_Removed is
+               // deprecated, going forward we prefer sending the entire 
information.
+               this._map.fire('updateviewslist');
        },
 
        _onRenderFontMsg: function (textMsg, img) {
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 30d81fa86..272f7fe1c 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -265,7 +265,7 @@ L.Map = L.Evented.extend({
                if (viewInfo.userextrainfo !== undefined && 
viewInfo.userextrainfo.avatar !== undefined) {
                        this._viewInfoByUserName[viewInfo.username] = 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}});
+               this.fire('postMessage', {msgId: 'View_Added', args: 
{Deprecated: true, 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)});
@@ -277,7 +277,7 @@ L.Map = L.Evented.extend({
                var username = this._viewInfo[viewid].username;
                delete 
this._viewInfoByUserName[this._viewInfo[viewid].username];
                delete this._viewInfo[viewid];
-               this.fire('postMessage', {msgId: 'View_Removed', args: {ViewId: 
viewid}});
+               this.fire('postMessage', {msgId: 'View_Removed', args: 
{Deprecated: true, ViewId: viewid}});
 
                // Fire last, otherwise not all events are handled correctly.
                this.fire('removeview', {viewId: viewid, username: username});
diff --git a/loleaflet/src/map/handler/Map.WOPI.js 
b/loleaflet/src/map/handler/Map.WOPI.js
index 5269cbe51..be108a108 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -50,6 +50,8 @@ L.Map.WOPI = L.Handler.extend({
 
                this._map.on('wopiprops', this._setWopiProps, this);
                L.DomEvent.on(window, 'message', this._postMessageListener, 
this);
+
+               this._map.on('updateviewslist', function() { 
this._postViewsMessage('Views_List'); }, this);
        },
 
        removeHooks: function() {
@@ -62,6 +64,8 @@ L.Map.WOPI = L.Handler.extend({
 
                this._map.off('wopiprops', this._setWopiProps, this);
                L.DomEvent.off(window, 'message', this._postMessageListener, 
this);
+
+               this._map.off('updateviewslist');
        },
 
        _setWopiProps: function(wopiInfo) {
@@ -244,20 +248,7 @@ L.Map.WOPI = L.Handler.extend({
                        }
                }
                else if (msg.MessageId === 'Get_Views') {
-                       var getMembersRespVal = [];
-                       for (var viewInfoIdx in this._map._viewInfo) {
-                               getMembersRespVal.push({
-                                       ViewId: viewInfoIdx,
-                                       UserName: 
this._map._viewInfo[viewInfoIdx].username,
-                                       UserId: 
this._map._viewInfo[viewInfoIdx].userid,
-                                       UserExtraInfo: 
this._map._viewInfo[viewInfoIdx].userextrainfo,
-                                       Color: 
this._map._viewInfo[viewInfoIdx].color,
-                                       ReadOnly: 
this._map._viewInfo[viewInfoIdx].readonly,
-                                       IsCurrentView: 
this._map._docLayer._viewId === parseInt(viewInfoIdx, 10)
-                               });
-                       }
-
-                       this._postMessage({msgId: 'Get_Views_Resp', args: 
getMembersRespVal});
+                       this._postViewsMessage('Get_Views_Resp');
                }
                else if (msg.MessageId === 'Action_Save') {
                        var dontTerminateEdit = msg.Values && 
msg.Values['DontTerminateEdit'];
@@ -356,6 +347,23 @@ L.Map.WOPI = L.Handler.extend({
                        };
                        window.parent.postMessage(JSON.stringify(msg), 
this.PostMessageOrigin);
                }
+       },
+
+       _postViewsMessage: function(messageId) {
+               var getMembersRespVal = [];
+               for (var viewInfoIdx in this._map._viewInfo) {
+                       getMembersRespVal.push({
+                               ViewId: viewInfoIdx,
+                               UserName: 
this._map._viewInfo[viewInfoIdx].username,
+                               UserId: this._map._viewInfo[viewInfoIdx].userid,
+                               UserExtraInfo: 
this._map._viewInfo[viewInfoIdx].userextrainfo,
+                               Color: this._map._viewInfo[viewInfoIdx].color,
+                               ReadOnly: 
this._map._viewInfo[viewInfoIdx].readonly,
+                               IsCurrentView: this._map._docLayer._viewId === 
parseInt(viewInfoIdx, 10)
+                       });
+               }
+
+               this._postMessage({msgId: messageId, args: getMembersRespVal});
        }
 });
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to