diff --git a/gulpfile.js b/gulpfile.js index d4892ba..f97f2f7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,14 +3,18 @@ let concat = require('gulp-concat'); let rename = require("gulp-rename"); let uglify = require('gulp-uglify-es').default; +js_files = [ + 'js/devel/app.js', + 'js/devel/settings.js', + 'js/devel/contactlist.js', + 'js/devel/conversation.js', + 'js/devel/helpers.js', + 'js/devel/notifications.js' +]; + gulp.task("uglify", function () { - return gulp.src("js/devel/app.js") - .pipe(concat('js/devel/settings.js')) - .pipe(concat('js/devel/contactlist.js')) - .pipe(concat('js/devel/conversation.js')) - .pipe(concat('js/devel/helpers.js')) - .pipe(concat('js/devel/notifications.js')) - .pipe(rename("app.min.js")) + return gulp.src(js_files) + .pipe(concat("app.min.js")) .pipe(uglify(/* options */)) .pipe(gulp.dest("js/")); -}); \ No newline at end of file +}); diff --git a/js/app.min.js b/js/app.min.js index f8cd446..d70f0ea 100644 --- a/js/app.min.js +++ b/js/app.min.js @@ -1 +1 @@ -var Sms={selectedConversation:null,unreadCountCurrentConv:0,unreadCountNotifStep:12,lastContactListMsgDate:0,originalTitle:document.title,photoVersion:1,_winRegexp:/(.*)\/ocsms.*/,generateURL:function(e){var t=this._winRegexp.exec(window.location.href);return 2!==t.length&&console.log("A very bad error happened when parsing window location"),t[1]+"/ocsms"+e},selectConversation:function(e){"undefined"!==e&&null!=e&&(null!=this.selectedConversation&&this.selectedConversation.parent().removeClass("selected"),this.selectedConversation=e,this.selectedConversation.parent().addClass("selected"),this.selectedConversation.css("font-weight","normal"),this.selectedConversation.html(this.selectedConversation.attr("mailbox-label")))}},ContactRenderer={generateColor:function(e){if(void 0===e)return"";if("function"==typeof e.toHsl){var t=e.toHsl();return"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)"}var n=md5(e).substring(0,4),o=parseInt("ffff",16);return"hsl("+parseInt(n,16)/o*256+", 90%, 65%)"},generateFirstCharacter:function(e){return"string"!=typeof e?"?":"+"===e.charAt(0)?"#":e.charAt(0)}};$.urlParam=function(e){var t=new RegExp("[?&]"+e+"=([^&#]*)").exec(window.location.href);return null==t?null:t[1]||0},Vue.filter("firstCharacter",ContactRenderer.generateFirstCharacter);const Dialog=Vue.extend({template:"#modal-template"});Vue.directive("confirm",{bind(e,t,n){const o=t.value[1],r=t.value[0];e.handleClick=(e=>{const t={doYes:function(){o(),t.show=!1},show:!0,bodyMessage:r};let n=new Dialog({data:t}).$mount();document.getElementById("app").appendChild(n.$el)}),e.addEventListener("click",e.handleClick)},unbind(e){e.removeEventListener("click",e.handleClick)}}),jQuery,OC,window.onfocus=function(){Sms.unreadCountCurrentConv=0,document.title=Sms.originalTitle}; \ No newline at end of file +var Sms={selectedConversation:null,unreadCountCurrentConv:0,unreadCountNotifStep:12,lastContactListMsgDate:0,originalTitle:document.title,photoVersion:1,_winRegexp:/(.*)\/ocsms.*/,generateURL:function(t){var e=this._winRegexp.exec(window.location.href);return 2!==e.length&&console.log("A very bad error happened when parsing window location"),e[1]+"/ocsms"+t},selectConversation:function(t){"undefined"!==t&&null!=t&&(null!=this.selectedConversation&&this.selectedConversation.parent().removeClass("selected"),this.selectedConversation=t,this.selectedConversation.parent().addClass("selected"),this.selectedConversation.css("font-weight","normal"),this.selectedConversation.html(this.selectedConversation.attr("mailbox-label")))}},ContactRenderer={generateColor:function(t){if(void 0===t)return"";if("function"==typeof t.toHsl){var e=t.toHsl();return"hsl("+e[0]+", "+e[1]+"%, "+e[2]+"%)"}var n=md5(t).substring(0,4),s=parseInt("ffff",16);return"hsl("+parseInt(n,16)/s*256+", 90%, 65%)"},generateFirstCharacter:function(t){return"string"!=typeof t?"?":"+"===t.charAt(0)?"#":t.charAt(0)}};$.urlParam=function(t){var e=new RegExp("[?&]"+t+"=([^&#]*)").exec(window.location.href);return null==e?null:e[1]||0},Vue.filter("firstCharacter",ContactRenderer.generateFirstCharacter);const Dialog=Vue.extend({template:"#modal-template"});Vue.directive("confirm",{bind(t,e,n){const s=e.value[1],o=e.value[0];t.handleClick=(t=>{const e={doYes:function(){s(),e.show=!1},show:!0,bodyMessage:o};let n=new Dialog({data:e}).$mount();document.getElementById("app").appendChild(n.$el)}),t.addEventListener("click",t.handleClick)},unbind(t){t.removeEventListener("click",t.handleClick)}}),jQuery,OC,window.onfocus=function(){Sms.unreadCountCurrentConv=0,document.title=Sms.originalTitle};var SmsSettings=new Vue({el:"#app-settings",data:{messageLimit:100,enableNotifications:!0,contactOrderBy:"lastmsg",reverseContactOrder:!0,country:""},created:function(){var t=this;$.getJSON(Sms.generateURL("/front-api/v1/settings"),function(e,n){!0===e.status&&(t.messageLimit=parseInt(e.message_limit),t.enableNotifications=0!==parseInt(e.notification_state)?1:0,t.contactOrderBy=e.contact_order,t.reverseContactOrder=toBool(e.contact_order_reverse),t.country=e.country)})},methods:{sendMessageLimit:function(){if(null!==this.messageLimit){$.post(Sms.generateURL("/set/msglimit"),{limit:this.messageLimit})}},sendNotificationFlag:function(){$.post(Sms.generateURL("/set/notification_state"),{notification:parseInt(this.enableNotifications)})},sendContactOrder:function(){$.post(Sms.generateURL("/set/contact_order"),{attribute:this.contactOrderBy,reverse:this.reverseContactOrder})},sendCountry:function(){$.post(Sms.generateURL("/set/country"),{country:this.country})},wipeAllMessages:function(){$.post(Sms.generateURL("/front-api/v1/delete/all"),{},function(){ContactList.reset(),Conversation.clear()})},isContactListEmpty:function(){return 0===ContactList.contacts.length}}}),ContactList=new Vue({el:"#app-mailbox-peers",data:{isContactsLoading:!0,contacts:[],lastRetrievedMessageDate:0,totalUnreadMessages:0,lastTotalUnreadCount:0},created:function(){this.reset(),this.fetch(),this.checkNewMessages(),setInterval(this.checkNewMessages,1e4)},methods:{reset:function(){this.contacts=[],this.lastRetrievedMessageDate=0,this.totalUnreadMessages=0,this.lastTotalUnreadCount=0},fetch:function(){let t=this;$.getJSON(Sms.generateURL("/front-api/v1/peerlist"),function(e,n){let s=[];Sms.photoVersion=e.photo_version,$.each(e.phonelist,function(n,o){var a;if(!inArray(a=void 0===e.contacts[n]?n:e.contacts[n],s)){var i={label:a,nav:n,unread:0,lastmsg:parseInt(o)};void 0!==e.photos[a]&&(i.avatar=e.photos[a]),void 0!==e.uids[a]?i.uid=e.uids[a]:i.uid=a,t.addContact(i),s.push(a)}}),t.isContactsLoading=!1,Sms.lastContactListMsgDate=e.lastRead,t.lastRetrievedMessageDate=e.lastMessage;var o=$.urlParam("phonenumber");if(null!=o){var a=decodeURIComponent(o);if(null!=a){if(void 0===Conversation.selectedContact.nav){Conversation.selectedContact.label=a,Conversation.selectedContact.nav=a,Conversation.selectedContact.avatar=void 0;for(var i=0;i0&&Sms.unreadCountNotifStep--,t.totalUnreadMessages>0&&(0!==Sms.unreadCountNotifStep&&t.lastTotalUnreadCount===t.totalUnreadMessages||(SmsNotifications.notify(t.totalUnreadMessages+" unread message(s) for all conversations"),Sms.unreadCountNotifStep=12,t.lastTotalUnreadCount=t.totalUnreadMessages))})}},computed:{orderedContacts:function(){return _.orderBy(this.contacts,[SmsSettings.contactOrderBy],[SmsSettings.reverseContactOrder?"desc":"asc"])}}}),Conversation=new Vue({el:"#app-content",data:{selectedContact:{},isConvLoading:!1,messages:[],lastConvMessageDate:0,totalMessageCount:0,refreshIntervalId:null},methods:{fetch:function(t){null!=t&&(this.selectedContact=t,this.isConvLoading=!0),this.messages=[],this.lastConvMessageDate=0;let e=this;$.getJSON(Sms.generateURL("/front-api/v1/conversation"),{phoneNumber:e.selectedContact.nav},function(t,n){let s=e.selectedContact.nav;if(void 0!==t.phoneNumbers){s=arrayUnique(t.phoneNumbers).toString()}e.formatConversation(t),void 0===t.contactName||""===t.contactName?(e.selectedContact.label=s,e.selectedContact.opt_numbers=""):(e.selectedContact.label=t.contactName,e.selectedContact.opt_numbers=s),e.totalMessageCount=void 0!==t.msgCount?t.msgCount:0,e.isConvLoading=!1,$("#app-content").scrollTop(1e10),null!==e.refreshIntervalId&&clearInterval(e.refreshIntervalId),e.refreshIntervalId=setInterval(e.refresh,1e4)})},refresh:function(){var t=this;$.getJSON(Sms.generateURL("/front-api/v1/conversation"),{phoneNumber:Conversation.selectedContact.nav,lastDate:Conversation.lastConvMessageDate},function(e,n){var s=t.formatConversation(e);!0===s[1]&&($("#app-content").scrollTop(1e10),!1===document.hasFocus()&&(Sms.unreadCountCurrentConv+=parseInt(s[0]),document.title=Sms.originalTitle+" ("+Sms.unreadCountCurrentConv+")",SmsNotifications.notify(Sms.unreadCountCurrentConv+" unread message(s) in conversation with "+Conversation.selectedContact.label))),t.totalMessageCount=void 0!==e.msgCount?parseInt(e.msgCount):0})},getContactColor:function(t){return ContactRenderer.generateColor(t)},formatConversation:function(t){let e=!1,n="",s=0,o=this;return $.each(t.conversation,function(t,a){n=1==a.type?"recv":2==a.type?"sent":"unknown",t/100>o.lastConvMessageDate/100&&(o.lastConvMessageDate=t,o.addConversationMessage({id:t,type:n,date:new Date(1*t),content:a.msg}),e=!0,s++)}),[s,e]},addConversationMessage:function(t){this.messages.push(t)},removeConversationMessage:function(t){const e=this.messages.length;let n=this;for(var s=0;s