Преглед на файлове

[add] add native static data getter

B Thibault преди 8 години
родител
ревизия
ae51ee858e
променени са 4 файла, в които са добавени 28 реда и са изтрити 5 реда
  1. 9 1
      cli/externs/native.js
  2. 13 1
      cli/ui.js
  3. 2 0
      cli/workflow.js
  4. 4 3
      srv/public/mimouchat.min.js

+ 9 - 1
cli/externs/native.js

@@ -1,7 +1,15 @@
 
 var __native = {
     /** @type {function()} */
-    "login": function() {}
+    logout: function() {},
+    /** @type {function(string)} */
+    readSmsPermission: function(onResult) {},
+    /** @type {function():string} */
+    getSms: function() {},
+    /** @type {function():string} */
+    getSmsConversations: function() {},
+    /** @type {function():string} */
+    getStatic: function() {},
 };
 /** @type {boolean} */
 var IS_LOCAL;

+ 13 - 1
cli/ui.js

@@ -681,9 +681,21 @@ document.addEventListener('DOMContentLoaded', function() {
             });
     });
 
-    startPolling();
+    if ("__native" in window)
+        __native.readSmsPermission("onSmsPermissionUpdated");
+    if (!IS_LOCAL)
+        startPolling();
 });
 
+window["onSmsPermissionUpdated"] = function(enabled) {
+    if ("__native" in window && enabled) {
+        var response = JSON.parse(__native.getStatic());
+        if (response) {
+            DATA.update(response);
+        }
+    }
+};
+
 function onMsgFormSubmit() {
     var input = document.getElementById(R.id.message.input);
     if (SELECTED_ROOM && input.value) {

+ 2 - 0
cli/workflow.js

@@ -364,6 +364,8 @@ function logout() {
     new HttpRequest(HttpRequestMethod.POST, "api/logout").send();
     document.cookie = "sessID=;Path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
     document.location.reload();
+    if ("__native" in window)
+        __native.logout();
 }
 
 /**

+ 4 - 3
srv/public/mimouchat.min.js

@@ -70,8 +70,8 @@ if(0<=d){b=b.substr(d+1);if(d=D(C.context,b)){Kb.fb(d,d.j[b]).show(a);return}a:{
 function(a){a.preventDefault();Q&&(Q.A?O(new K("POST","api/unstarChannel?room="+Q.id)):O(new K("POST","api/starChannel?room="+Q.id)));return!1});document.getElementById("fileUploadCancel").addEventListener("click",function(a){a.preventDefault();document.getElementById("fileUploadError").classList.add("hidden");document.getElementById("fileUploadContainer").classList.add("hidden");document.getElementById("fileUploadInput").value="";return!1});document.getElementById("ctxMenuLogout").addEventListener("click",
 Lb);document.getElementById("ctxMenuSettings").addEventListener("click",function(a){a.preventDefault();Mb.display()});document.getElementById("fileUploadForm").addEventListener("submit",function(a){a.preventDefault();a=document.getElementById("fileUploadInput");var b=a.value;b&&(b=b.substr(b.lastIndexOf("\\")+1),Nb(b,a.files[0],function(a){var b=document.getElementById("fileUploadError");a?(b.textContent=a,b.classList.remove("hidden")):(b.classList.add("hidden"),document.getElementById("fileUploadInput").value=
 "",document.getElementById("fileUploadContainer").classList.add("hidden"))}));return!1});document.getElementById("attachFile").addEventListener("click",function(a){a.preventDefault();Q&&document.getElementById("fileUploadContainer").classList.remove("hidden");return!1});document.getElementById("msgFormSubmit").addEventListener("click",function(a){a.preventDefault();fb();return!1});document.getElementById("msgForm").addEventListener("submit",function(a){a.preventDefault();fb();return!1});window.addEventListener("blur",
-function(){window.hasFocus=!1});window.addEventListener("focus",function(){window.hasFocus=!0;hb=0;Q&&vb();T()});document.getElementById("chatWindow").addEventListener("scroll",Cb);window.hasFocus=!0;document.getElementById("emojiButton").addEventListener("click",function(){P&&Eb.qa(document.body,P,function(a){a&&(document.getElementById("msgInput").value+=":"+a+":");T()})});Ob()});
-function fb(){var a=document.getElementById("msgInput");Q&&a.value&&ab(a.value)&&(a.value="",S&&(S=null,V()),R&&(R=null,V()),document.getElementById("slashList").textContent="",db(a));T()};var Mb=function(){function a(){document.getElementById("settings").classList.add("hidden");c=!1}function b(a){d&&(document.getElementById("settings").classList.remove("display-"+d),document.getElementById("setting-menu-"+d).classList.remove("selected"),document.getElementById("settings-serviceAddSection").classList.add("hidden"));document.getElementById("settings").classList.add("display-"+a);document.getElementById("setting-menu-"+a).classList.add("selected");d=a}var c=!1,d=null,e={U:"services",
+function(){window.hasFocus=!1});window.addEventListener("focus",function(){window.hasFocus=!0;hb=0;Q&&vb();T()});document.getElementById("chatWindow").addEventListener("scroll",Cb);window.hasFocus=!0;document.getElementById("emojiButton").addEventListener("click",function(){P&&Eb.qa(document.body,P,function(a){a&&(document.getElementById("msgInput").value+=":"+a+":");T()})});"__native"in window&&__native.readSmsPermission("onSmsPermissionUpdated");IS_LOCAL||Ob()});
+window.onSmsPermissionUpdated=function(a){"__native"in window&&a&&(a=JSON.parse(__native.getStatic()))&&C.update(a)};function fb(){var a=document.getElementById("msgInput");Q&&a.value&&ab(a.value)&&(a.value="",S&&(S=null,V()),R&&(R=null,V()),document.getElementById("slashList").textContent="",db(a));T()};var Mb=function(){function a(){document.getElementById("settings").classList.add("hidden");c=!1}function b(a){d&&(document.getElementById("settings").classList.remove("display-"+d),document.getElementById("setting-menu-"+d).classList.remove("selected"),document.getElementById("settings-serviceAddSection").classList.add("hidden"));document.getElementById("settings").classList.add("display-"+a);document.getElementById("setting-menu-"+a).classList.add("selected");d=a}var c=!1,d=null,e={U:"services",
 display:"display",Qb:"privacy"};document.getElementById("settingMenuItems").addEventListener("click",function(a){for(var c=a.target;a.currentTarget!==c&&c;c=c.parentNode)if(c.dataset&&c.dataset.target)for(var d in e)if(e[d]===c.dataset.target){b(e[d]);return}});document.getElementById("settingDiscardClose").addEventListener("click",a);document.getElementById("settings-serviceAddButton").addEventListener("click",function(a){a.preventDefault();document.getElementById("settings-serviceAddSection").classList.remove("hidden");
 return!1});document.getElementById("settings-serviceAddConfirm").addEventListener("click",function(a){a.preventDefault();document.location.href=document.getElementById("settings-serviceAddServiceList").value;return!1});document.getElementById("settingCommit").addEventListener("click",function(){var b={};document.getElementById("settings-displayEmojiProvider").value!==X.h&&(b.emojiProvider=document.getElementById("settings-displayEmojiProvider").value);var c=!!document.getElementById("settings-displayDisplayAvatar").checked;
 c!==(!1!==X.a)&&(b.displayAvatar=c);c=!!document.getElementById("settings-displayColorfulNames").checked;c!==(!0===X.b)&&(b.colorfulNames=c);var c=X,d;for(d in b){Pb(c,b);Qb();O(new K("POST","api/settings?service=null&device=null"),JSON.stringify(b));break}a()});return{display:function(a){if(!c){document.getElementById("settings").classList.remove("hidden");var d=document.createDocumentFragment(),f=!1,g;for(g in X.U){var n=X.U[g];for(m in n){var f=document.createElement("li"),p=document.createElement("span"),
@@ -117,7 +117,8 @@ function Ob(){var a=gc;IS_LOCAL||O(Ea(Fa(Ca(new K("api?v="+C.b),function(b,c,d){
 function ic(a){Q&&(document.getElementById("room_"+Q.id).classList.remove("selected"),document.getElementById("chatSystemContainer").classList.add("no-room-selected"));document.getElementById("room_"+a.id).classList.add("selected");document.body.classList.remove("no-room-selected");Q=a;P=D(C.context,a.id);tb();Kb.sb();ob(P.a.id,P.i,function(a){document.getElementById("chatCtx").style.backgroundImage="url("+a+")"});(!C.a[Q.id]||100>C.a[Q.id].a.length)&&cc();document.getElementById("chatSystemContainer").classList.remove("no-room-selected");
 document.getElementById("chatCtx").classList.remove("opened")}function mb(){var a=document.location.hash.substr(1),b=wa(a);b&&b!==Q?ic(b):(a=F(a))&&a.O&&ic(a.O)}function Nb(a,b,c){var d=Q;new FileReader;var e=new FormData;e.append("file",b);e.append("filename",a);O(Da(N(new K("POST","api/file?room="+d.id),function(){c(null)}),function(a,b){c(b)}),e)}
 function cb(a,b,c,d){b="api/msg?room="+a.id+"&text="+encodeURIComponent(b);d&&(b+="&attachments="+encodeURIComponent(JSON.stringify([{fallback:d.text,author_name:F(d.K).getName(),text:d.text,footer:a.h?J.message:a.name,ts:d.m}])));O(N(Fa(new K("POST",b),"json"),function(a,b,d){d&&void 0!==d.pendingId&&(c.na=d.pendingId)}))}function Fb(a,b){O(new K("DELETE","api/pinMsg?room="+a.id+"&msgId="+b.id))}
-function xb(a,b,c){O(new K("POST","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c)))}function Lb(){O(new K("POST","api/logout"));document.cookie="sessID=;Path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.location.reload()}function lb(){var a={},b=[],c=this.value;ua(C.context,function(b){a[b.id]=ia(b,c)});for(var d in a){var e=document.getElementById("room_"+d);e&&(a[d].name+a[d].ma+a[d].ta+a[d].pa?(e.classList.remove("hidden"),b.push(d)):e.classList.add("hidden"))}};var Rb={noemoji:{Da:"noemoji.js",ia:null,name:"None"},emojione_v2_3:{Da:"emojione_v2.3.sprites.js",ia:"emojione_v2.3.sprites.css",name:"Emojione v2.3"},emojione_v3:{Da:"emojione_v3.sprites.js",ia:"emojione_v3.sprites.css",name:"Emojione v3"}},ec=Rb.emojione_v2_3,Ya;
+function xb(a,b,c){O(new K("POST","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c)))}function Lb(){O(new K("POST","api/logout"));document.cookie="sessID=;Path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.location.reload();"__native"in window&&__native.logout()}
+function lb(){var a={},b=[],c=this.value;ua(C.context,function(b){a[b.id]=ia(b,c)});for(var d in a){var e=document.getElementById("room_"+d);e&&(a[d].name+a[d].ma+a[d].ta+a[d].pa?(e.classList.remove("hidden"),b.push(d)):e.classList.add("hidden"))}};var Rb={noemoji:{Da:"noemoji.js",ia:null,name:"None"},emojione_v2_3:{Da:"emojione_v2.3.sprites.js",ia:"emojione_v2.3.sprites.css",name:"Emojione v2.3"},emojione_v3:{Da:"emojione_v3.sprites.js",ia:"emojione_v3.sprites.css",name:"Emojione v3"}},ec=Rb.emojione_v2_3,Ya;
 function dc(a){Ya!==a&&(console.log("Loading emoji pack "+a.name),O(Ea(N(new K(a.Da),function(b,c,d){b=document.createElement("script");b.innerHTML=d;b.language="text/javascript";document.body.appendChild(b);a.ia&&(d=document.createElement("link"),d.href=a.ia,d.rel="stylesheet",document.head.appendChild(d));d=document.getElementById("emojiButton");for(var e in C.a)jc(C.a[e]);Q&&ub();Eb.reset();"makeEmoji"in window?(d.style.backgroundImage='url("smile.svg")',d.classList.remove("hidden")):d.classList.add("hidden")}))),
 Ya=a)};var Kb=function(){function a(){c();r instanceof t?(f.style.backgroundImage="url(api/avatar?size=l&user="+r.a.id+")",n.textContent=(r.a.ib||(r.a.Xa||"")+" "+r.a.$a).trim(),h.classList.add("presence-indicator"),r.a.N?h.classList.remove("presence-away"):h.classList.add("presence-away"),g.classList.remove("hidden"),l.classList.remove("hidden"),l.textContent=r.a.zb||"",u.textContent=r.a.rb||"",m.classList.remove("hidden"),e.classList.remove("roominfo-channel"),e.classList.add("roominfo-user")):b()}function b(){var a=
 E;a.aa.topic?(g.classList.remove("hidden"),n.textContent=r.ta||"",p.textContent=r.G?J.Ga(r.G,r.ea):""):g.classList.add("hidden");a.aa.purpose?(m.classList.remove("hidden"),u.textContent=r.pa||"",A.textContent=r.o?J.Ga(r.o,r.da):""):m.classList.add("hidden");f.style.backgroundImage="";h.classList.remove("presence-indicator");M.textContent=J.kb(r.i?Object.keys(r.i).length:0);a=[];if(r.i)for(var b in r.i)a.push(r.i[b]);a.sort(function(a,b){return a.N&&!b.N?-1:b.N&&!a.N?1:a.getName().localeCompare(b.getName())});