From 4f16ae603e2cd8838d8d592bcc5ca9bab657b1d8 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sun, 11 Nov 2018 14:21:48 +0100 Subject: [PATCH] Release 2.0 --- appinfo/info.xml | 2 +- js/app.min.js | 2 +- templates/main.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index c118417..0f5167f 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,7 @@ An app to sync SMS with your cloud agpl Loic Blot - 1.99.1 + 2.0 multimedia tools diff --git a/js/app.min.js b/js/app.min.js index 727d839..4adaf96 100644 --- a/js/app.min.js +++ b/js/app.min.js @@ -1 +1 @@ -var Sms={selectedConversation:null,unreadCountCurrentConv:0,unreadCountAllConv:0,unreadCountNotifStep:12,lastUnreadCountAllConv:0,lastContactListMsgDate:0,originalTitle:document.title,photoVersion:1,_winRegexp:/(.*)\/ocsms.*/,generateURL:function(endpoint){var match=this._winRegexp.exec(window.location.href);if(match.length!==2){console.log("A very bad error happened when parsing window location")}return match[1]+"/ocsms"+endpoint},selectConversation:function(item){if(item==="undefined"||item==null){return}if(this.selectedConversation!=null){this.selectedConversation.parent().removeClass("selected")}this.selectedConversation=item;this.selectedConversation.parent().addClass("selected");this.selectedConversation.css("font-weight","normal");this.selectedConversation.html(this.selectedConversation.attr("mailbox-label"))}};var ContactRenderer={generateColor:function(input){if(typeof input==="undefined"){return""}if(typeof input.toHsl==="function"){var hsl=input.toHsl();return"hsl("+hsl[0]+", "+hsl[1]+"%, "+hsl[2]+"%)"}else{var hash=md5(input).substring(0,4),maxRange=parseInt("ffff",16),hue=parseInt(hash,16)/maxRange*256;return"hsl("+hue+", 90%, 65%)"}},generateFirstCharacter:function(input){if(input.charAt(0)==="+"){return"#"}return input.charAt(0)}};function inArray(val,arr){return $.inArray(val,arr)!==-1}function arrayUnique(arr){return arr.filter(function(item,i,arr){return i===arr.indexOf(item)})}function toBool(str){if(str==="true"){return true}else if(str==="false"){return false}return null}var app=angular.module("OcSms",[]);app.directive("toInt",function(){return{require:"ngModel",link:function(scope,element,attrs,modelCtrl){modelCtrl.$parsers.push(function(inputValue){return parseInt(inputValue,10)})}}});app.filter("peerColor",function(){return ContactRenderer.generateColor});app.filter("firstCharacter",function(){return ContactRenderer.generateFirstCharacter});app.controller("OcSmsController",["$scope","$interval","$timeout","$compile",function($scope,$interval,$timeout,$compile){$scope.lastConvMessageDate=0;$scope.isConvLoading=false;$scope.isContactsLoading=true;$scope.buttons=[{text:"Send"}];$scope.vsettings=SmsSettings;$scope.contacts=[];$scope.messages=[];$scope.totalMessageCount=0;$scope.selectedContact={};$scope.lastSearch="";$scope.loadConversation=function(contact){OC.Util.History.pushState("phonenumber="+contact.nav);if(contact.nav!==null){$scope.fetchConversation(contact);Sms.selectConversation($("a[mailbox-navigation='"+contact.nav+"']"))}};$scope.fetchConversation=function(contact){if(contact!=null){$scope.selectedContact=contact;$scope.isConvLoading=true}$scope.messages=[];$scope.lastConvMessageDate=0;$.getJSON(Sms.generateURL("/front-api/v1/conversation"),{phoneNumber:$scope.selectedContact.nav},function(jsondata,status){var phoneNumberLabel=$scope.selectedContact.nav;if(typeof jsondata["phoneNumbers"]!=="undefined"){var phoneNumberList=arrayUnique(jsondata["phoneNumbers"]);phoneNumberLabel=phoneNumberList.toString()}$scope.formatConversation(jsondata);$scope.$apply(function(){if(typeof jsondata["contactName"]==="undefined"||jsondata["contactName"]===""){$scope.selectedContact.label=phoneNumberLabel;$scope.selectedContact.opt_numbers=""}else{$scope.selectedContact.label=jsondata["contactName"];$scope.selectedContact.opt_numbers=phoneNumberLabel}$scope.totalMessageCount=jsondata["msgCount"]!==undefined?jsondata["msgCount"]:0;$scope.isConvLoading=false});$("#app-content").scrollTop(1e10)})};$scope.refreshConversation=function(){$.getJSON(Sms.generateURL("/ocsms/front-api/v1/conversation"),{phoneNumber:$scope.selectedContact.nav,lastDate:$scope.lastConvMessageDate},function(jsondata,status){var fmt=$scope.formatConversation(jsondata);var conversationBuf=fmt[1];if(conversationBuf===true){$("#app-content").scrollTop(1e10);if(document.hasFocus()===false){Sms.unreadCountCurrentConv+=parseInt(fmt[0]);document.title=Sms.originalTitle+" ("+Sms.unreadCountCurrentConv+")";SmsNotifications.notify(Sms.unreadCountCurrentConv+" unread message(s) in conversation with "+$scope.selectedContact.label)}}$scope.totalMessageCount=jsondata["msgCount"]!==undefined?parseInt(jsondata["msgCount"]):0})};$scope.checkNewMessages=function(){Sms.unreadCountAllConv=0;$.getJSON(Sms.generateURL("/front-api/v1/new_messages"),{lastDate:Sms.lastContactListMsgDate},function(jsondata,status){var bufferedContacts=[];$.each(jsondata["phonelist"],function(id,val){var fn,peerLabel;if(typeof jsondata["contacts"][id]==="undefined"){peerLabel=id}else{fn=jsondata["contacts"][id];peerLabel=fn}if(!inArray(peerLabel,bufferedContacts)){var contactObj={label:peerLabel,nav:id,unread:parseInt(val)};if(typeof jsondata["photos"][peerLabel]!=="undefined"){contactObj.avatar=jsondata["photos"][peerLabel]}if(typeof jsondata["uids"][peerLabel]!=="undefined"){contactObj.uid=jsondata["uids"][peerLabel]}else{contactObj.uid=peerLabel}$scope.modifyContact(contactObj);bufferedContacts.push(peerLabel);if(id===$scope.selectedContact.nav){Sms.selectConversation($("a[mailbox-navigation='"+id+"']"))}Sms.unreadCountAllConv+=parseInt(val)}});if(Sms.unreadCountNotifStep>0){Sms.unreadCountNotifStep--}if(Sms.unreadCountAllConv>0){if(Sms.unreadCountNotifStep===0||Sms.lastUnreadCountAllConv!==Sms.unreadCountAllConv){SmsNotifications.notify(Sms.unreadCountAllConv+" unread message(s) for all conversations");Sms.unreadCountNotifStep=12;Sms.lastUnreadCountAllConv=Sms.unreadCountAllConv}}})};$scope.removeConversation=function(){$.post(Sms.generateURL("/delete/conversation"),{contact:$scope.selectedContact.label},function(data){$scope.selectedContact.label="";$scope.selectedContact.opt_numbers="";$scope.selectedContact.avatar=undefined;$scope.removeContact($scope.selectedContact);$scope.$apply(function(){$scope.messages=[]});$scope.selectedContact.nav="";OC.Util.History.pushState("")})};$scope.filterSms=function(query){if(query!==$scope.lastSearch){}};OC.Plugins.register("OCA.Search",{attach:function(search){search.setFilter("sms",$scope.filterSms)}});$scope.addContact=function(ct){$scope.$apply(function(){$scope.contacts.push(ct)})};$scope.removeContact=function(ct){var len=$scope.contacts.length;for(var i=0;i$scope.lastConvMessageDate/100){$scope.lastConvMessageDate=id;$scope.addConversationMessage({id:id,type:msgClass,date:new Date(id*1),content:vals["msg"]});buf=true;msgCount++}});return[msgCount,buf]};$interval($scope.refreshConversation,1e4);$interval($scope.checkNewMessages,1e4);$timeout(function(){Sms.originalTitle=document.title;$.getJSON(Sms.generateURL("/front-api/v1/peerlist"),function(jsondata,status){$scope.fetchInitialPeerList(jsondata);var pnParam=$.urlParam("phonenumber");if(pnParam!=null){var urlPhoneNumber=decodeURIComponent(pnParam);if(urlPhoneNumber!=null){if($scope.selectedContact.nav===undefined){$scope.selectedContact.label=urlPhoneNumber;$scope.selectedContact.nav=urlPhoneNumber;$scope.selectedContact.avatar=undefined}$scope.fetchConversation(null);Sms.selectConversation($("a[mailbox-navigation='"+urlPhoneNumber+"']"))}}});SmsSettings.init();SmsNotifications.init();$scope.checkNewMessages()})}]);$.urlParam=function(name){var results=new RegExp("[?&]"+name+"=([^&#]*)").exec(window.location.href);if(results==null){return null}else{return results[1]||0}};(function($,OC){window.onfocus=function(){Sms.unreadCountCurrentConv=0;document.title=Sms.originalTitle}})(jQuery,OC);var SmsNotifications={init:function(){if(!("Notification"in window)){return}Notification.requestPermission(function(permission){if(!("permission"in Notification)){Notification.permission=permission}})},notify:function(message){if(!SmsSettings.enableNotifications){return}if(!("Notification"in window)){return}if(Notification.permission==="granted"){new Notification("Phone Sync - "+message)}else if(Notification.permission!=="denied"){Notification.requestPermission(function(permission){if(!("permission"in Notification)){Notification.permission=permission}if(permission==="granted"){new Notification("Phone Sync - "+message)}})}}};var SmsSettings={messageLimit:100,enableNotifications:true,contactOrderBy:"lastmsg",reverseContactOrder:true,country:"",init:function(){var self=this;$.getJSON(Sms.generateURL("/front-api/v1/settings"),function(jsondata,status){if(jsondata["status"]===true){self.messageLimit=parseInt(jsondata["message_limit"]);self.enableNotifications=parseInt(jsondata["notification_state"])!==0;self.contactOrderBy=jsondata["contact_order"];self.reverseContactOrder=toBool(jsondata["contact_order_reverse"]);self.country=jsondata["country"];self.updateView()}})},sendMessageLimit:function(){if(this.messageLimit===null){return}var self=this;$.post(Sms.generateURL("/set/msglimit"),{limit:self.messageLimit})},sendNotificationFlag:function(){var self=this;$.post(Sms.generateURL("/set/notification_state"),{notification:self.enableNotifications?1:0})},sendContactOrder:function(){var self=this;$.post(Sms.generateURL("/set/contact_order"),{attribute:self.contactOrderBy,reverse:self.reverseContactOrder})},sendCountry:function(){$.post(Sms.generateURL("/set/country"),{country:$("select[name=intl_phone]").val()})},updateView:function(){$("#sel_intl_phone").val(this.country);$("input[name=setting_msg_per_page]").val(this.messageLimit);$("select[name=setting_notif]").val(this.enableNotifications?1:0);$("select[name=setting_contact_order]").val(this.contactOrderBy);$("input[name=setting_contact_order_reverse]").val(this.reverseContactOrder)}}; +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}}}); \ No newline at end of file diff --git a/templates/main.php b/templates/main.php index 9c2efb8..17b8042 100644 --- a/templates/main.php +++ b/templates/main.php @@ -4,15 +4,15 @@ use \OCA\OcSms\Lib\CountryCodes; \OCP\Util::addScript('ocsms', 'lodash.min'); \OCP\Util::addScript('ocsms', 'vue.min'); // Production -//\OCP\Util::addScript('ocsms', 'app.min'); +\OCP\Util::addScript('ocsms', 'app.min'); // Develop -\OCP\Util::addScript('ocsms', 'devel/app'); -\OCP\Util::addScript('ocsms', 'devel/settings'); -\OCP\Util::addScript('ocsms', 'devel/contactlist'); -\OCP\Util::addScript('ocsms', 'devel/conversation'); -\OCP\Util::addScript('ocsms', 'devel/helpers'); -\OCP\Util::addScript('ocsms', 'devel/notifications'); -\OCP\Util::addStyle('ocsms', 'style'); +//\OCP\Util::addScript('ocsms', 'devel/app'); +//\OCP\Util::addScript('ocsms', 'devel/settings'); +//\OCP\Util::addScript('ocsms', 'devel/contactlist'); +//\OCP\Util::addScript('ocsms', 'devel/conversation'); +//\OCP\Util::addScript('ocsms', 'devel/helpers'); +//\OCP\Util::addScript('ocsms', 'devel/notifications'); +//\OCP\Util::addStyle('ocsms', 'style'); ?>