// Home page controller - includes content messages, share a thought, question and answer angular.module('kalgudiApp').controller('newsFeedController', ['$scope','$rootScope','$state','$stateParams','kalgudiLiterals','$injector','$http','$timeout',"$compile","$sce", 'loadingS3UrlFactory','$filter','$timeout','$interval','profileService','commonServices','dashboardFactory','webNotificationFactory',"myconnectsRequestService", function($scope,$rootScope,$state,$stateParams,kalgudiLiterals,$injector,$http,$timeout,$compile,$sce, loadingS3UrlFactory,$filter,$timeout,$interval,profileService,commonServices,dashboardFactory,webNotificationFactory,myconnectsRequestService){ $scope.isSurvey = true; //$rootScope.shareThought = {}; if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $uibModal = $injector.get("$uibModal"); myconnectsRequestActionsFactory=$injector.get("myconnectsRequestActionsFactory"); setTimeout(function() { $scope.recommendationsInFeedStream(); }, 10); } if((window.location.pathname.indexOf('mobile_index')>-1)){ $ionicScrollDelegate = $injector.get("$ionicScrollDelegate"); profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey); } $scope.contentLiterals = kalgudiLiterals; $scope.connectsLiterals=kalgudiLiterals; $scope.disable_flag = false; $scope.loadMore={ text:$scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_LOADING'), limit:20, flag:true, newItemsInFeed:0, newItemsInFeedCount:0, newItemsInFeedFlag:false } $scope.contentNewfeed = true; $scope.messageRequest = { limit : $scope.loadMore.limit, offset : 0, labelId : 0 }; $scope.share={ comment:'' }; if(window.location.href.includes('devkalgudi')){ $scope.isDevkalgudi = true; } else { $scope.isDevkalgudi = false; } $scope.contentShare={ "recepient":"", "to":[] }; $scope.FeedRequest={ limit : 40, offset : 0, }; $scope.csmRequest={ "offset":0, limit:10 }; $scope.messages={feed:[]}; $scope.selectedMessages = { selectedMsg : [], messagesLoadedFlags : [], deleteFlag : false, totalSelectdCount : 0, selected_index_count : '' }; $scope.tempPeopleViewYourProfile = []; $scope.tempPeopleRequestAccepted = []; $scope.tempPeopleConnected = []; $scope.tempPeopleSentConnectRequest = []; $scope.nonContentMessages=['Share a Thought','question','answer','ConnectsRecommendation','Latest Connect','Connect request', 'CONNECT_REQUEST_RECEIVED', 'PROFILE_VISITED', 'CONNECT_REQUEST_ACCEPTED', 'Survey']; $scope.tabs_click = function(tab){ $scope.isTabOpened=true; if(tab === 'first_tab'){ $scope.first_tab = !$scope.first_tab; $scope.second_tab = false; $scope.third_tab = false; } else if(tab === 'second_tab'){ $scope.first_tab = false; $scope.second_tab = !$scope.second_tab; $scope.third_tab = false; } else{ $scope.first_tab = false; $scope.second_tab = false; $scope.third_tab = !$scope.third_tab; } } function resetTabs(){ $scope.first_tab = false; $scope.second_tab = false; $scope.third_tab = false; } $scope.sendMessage = function(user){ if(user.senderProfileKey == $rootScope.loggedInUserBusinessProfile.profileKey){ var userObj = { 'receiverId':user.receiverProfileKey, 'receiverName':user.receiverFirstName, 'receiverbizId':user.receiverBusinessId } } else { var userObj = { 'receiverId':user.senderProfileKey, 'receiverName':user.senderFirstName, 'receiverbizId':user.senderBusinessId } } if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $state.go('chatMessage',userObj); } if((window.location.pathname.indexOf('mobile_index')>-1)){ $state.go('mychat.chatbox',userObj); } } $scope.acceptConnect = function(connect){ var request = { "receiverBusinessId":connect.senderBusinessId, "receiverId":connect.senderProfileKey, "firstName":connect.senderFirstName, "businessName":connect.senderBusinessName, "eventType":"CONNECT_REQUEST_ACCEPTED", "message": "I would like to add you to my business network in kalgudi." } connect.spinner=true; if(!(window.location.pathname.indexOf('mobile_index')>-1)){ myconnectsRequestActionsFactory.acceptConnectRequest(request).then(function(result) { connect.spinner=false; if(result.code == 201) { connect.latestActivity.latestActivity.type = "CONNECTED"; } else { $rootScope.showErrorMessage('Something\'s gone wrong', 'Please try again after some time', 4000); } }); } if((window.location.pathname.indexOf('mobile_index')>-1)){ myconnectsRequestService.acceptConnectRequest(request).then(function(result){ if(result.code == 201) { connect.spinner=false; connect.latestActivity.latestActivity.type = "CONNECTED"; var data = JSON.parse(result.data); var latestActivityTimestamp = data.lastUpdatedTimeStamp; // Update connect accept notification view with latest timestamp loadingS3UrlFactory.makeNOtificationRead("homepage", latestActivityTimestamp) .then( function (notificationsResult) { if (window.location.pathname.indexOf('mobile_index') > -1) { $rootScope.notificationCounts.count = 0; } } ); } }); } } $rootScope.$on('submittedSucessfully', function (event, data) { resetTabs(); }); // This will be triggered if any Update or question will be deleted $rootScope.$on("updateDeleted", function(event, data){ $scope.removeItemFromUi(data); }); angular.element(document).on("click", function(e) { //e.stopPropagation(); $scope.$apply(function() { if(e.toElement.name ==='threeDot' ){ // do nothing } else if(e.toElement.name ==='textarea'){ $scope.heightFlag= true; } else if(e.toElement.name ==='tabOpened' || e.toElement.name ==='tabOpenedBlock'){ $scope.isTabOpened=true; } else{ $scope.heightFlag= false; $scope.dropdown_enable_question = false; $scope.disable_flag = false; $scope.isTabOpened=false; } }); }); $scope.resetHomeFeedNotification=function(){ loadingS3UrlFactory.resetHomeFeedNotificationData(); } $scope.resetHomeFeedNotification(); $scope.contentTemplateLoaded = function(keypattern_id) { $scope.selectedMessages.messagesLoadedFlags[keypattern_id] = true; }; $scope.show_more_data = false; $scope.show_less_data = true; $scope.show_toggle = function(message,index){ if($scope.messages.feed[index].showFlag){ $scope.messages.feed[index].text = "Show more"; $scope.messages.feed[index].showFlag = false; }else{ $scope.messages.feed[index].text = "Show less"; $scope.messages.feed[index].showFlag = true; } } $scope.goToPageFullView = function(entityId,where){ if(where == 'program'){ $state.go('mypages.pages.programfullView',{entityId:entityId}); } else { $state.go('mypages.pages.fullView',{entityId:entityId}); } } $scope.openPost=function(type){ var streamInbox = ""; switch($rootScope.loggedInUserBusinessProfile.additionalBizDetails.businessTypeId){ case 'BT000000': streamInbox = "mybusiness.streamInbox"; break; case 'BT000001': streamInbox = "CA.streamInbox"; break; case 'BT000002': streamInbox = "farmer.streamInbox"; break; case 'BT000003': streamInbox = "mytransporter.streamInbox"; break; case 'BT000006': streamInbox = "mywarehouse.streamInbox"; break; case 'BT000008': streamInbox = "agriInput.streamInbox"; break; case 'BT000010': streamInbox = "coApp.streamInbox"; break; case 'BT000013': streamInbox = "intermediaryApp.streamInbox"; break; case 'BT000014': streamInbox = "agencyApp.streamInbox"; break; case 'BT000012': case 'BT000015': case 'BT000016': case 'BT000017': case 'BT000018': case 'BT000019': streamInbox = "basicApp.streamInbox"; break; } $state.go(streamInbox); var request = { tabType : type, } $timeout(function() { $rootScope.$broadcast("openPostInStream",request); },500); } $scope.getCsmInboxMesages =function(csmRequest){ /*opportunityInboxFactory.getCsmInboxMesages(csmRequest).then(function(result){ var tempresult=result; var removedRecommendations= _.remove(result, function(n) { return n._messageTemplateId== "RecommendConnects" || n._messageTemplateId=="RecommendedPost";}); $scope.peopleConnected = _.filter(tempresult ,function(n) { return n.button_event=='POST'}); $scope.peopleviewYourProfile = _.filter(tempresult ,function(n) { return n.lastConnectUpdate=='PROFILE_VISITED'}); $scope.peopleRequestAccepted = _.filter(tempresult ,function(n) { return n.lastConnectUpdate=='CONNECT_REQUEST_ACCEPTED'}); $scope.peopleSentConnectRequest = _.filter(tempresult ,function(n) { return n.lastConnectUpdate=='CONNECT_REQUESTED' ||n.lastConnectUpdate=="SENT_REQUEST"}); if($scope.peopleConnected.length!=0){ $scope.peopleConnected[0].type="peopleConnected"; $scope.messages.feed.push($scope.peopleConnected[0]); } if($scope.peopleviewYourProfile.length!=0){ //$scope.peopleviewYourProfile[0].type="peopleviewYourProfile"; var myDest= angular.copy($scope.peopleviewYourProfile[0]); myDest.type="peopleviewYourProfile"; $scope.messages.feed.push(myDest); } if($scope.peopleSentConnectRequest.length!=0){ $scope.peopleSentConnectRequest[0].type="peopleSentConnectRequest"; $scope.messages.feed.push($scope.peopleSentConnectRequest[0]); } });*/ var networkNotifications = _.filter(csmRequest,function(o){ return o.eventCategory == "Network"}); var tempresult=networkNotifications; $scope.peopleConnected = _.filter(tempresult ,function(n) { return n.latestActivity.type=='POST'}); $scope.peopleviewYourProfile = _.filter(tempresult ,function(n) { return n.latestActivity.type=='PROFILE_VISITED'}); $scope.peopleRequestAccepted = _.filter(tempresult ,function(n) { return n.latestActivity.type=='CONNECT_REQUEST_ACCEPTED'}); $scope.peopleSentConnectRequest = _.filter(tempresult ,function(n) { return n.latestActivity.type=='CONNECT_REQUESTED' ||n.latestActivity.type=="SENT_REQUEST"}); if($scope.peopleConnected.length!=0 && $scope.peopleConnected.length != $scope.tempPeopleConnected.length){ $scope.tempPeopleConnected = $scope.peopleConnected; loadingS3UrlFactory.getNetworkNotificationFromUrls($scope.peopleConnected[0].url).then(function(data){ var myDest= angular.copy(data); myDest.type="peopleConnected"; myDest.connectFeedMessage=true; $scope.messages.feed.push(myDest); }); } if($scope.peopleRequestAccepted.length!=0 && $scope.peopleRequestAccepted.length!=$scope.tempPeopleRequestAccepted.length){ $scope.tempPeopleRequestAccepted = $scope.peopleRequestAccepted; loadingS3UrlFactory.getNetworkNotificationFromUrls($scope.peopleRequestAccepted[0].url).then(function(data){ var myDest= angular.copy(data); myDest.type="peopleConnected"; myDest.connectFeedMessage=true; $scope.messages.feed.push(myDest); }); } if($scope.peopleviewYourProfile.length!=0 && $scope.peopleviewYourProfile.length != $scope.tempPeopleViewYourProfile.length){ $scope.tempPeopleViewYourProfile = $scope.peopleviewYourProfile ; loadingS3UrlFactory.getNetworkNotificationFromUrls($scope.peopleviewYourProfile[0].url).then(function(data){ var myDest= angular.copy(data); myDest.type="peopleviewYourProfile"; myDest.connectFeedMessage=true; $scope.messages.feed.push(myDest); }); } if($scope.peopleSentConnectRequest.length!=0 && $scope.tempPeopleSentConnectRequest.length != $scope.peopleSentConnectRequest.length){ $scope.tempPeopleSentConnectRequest = $scope.peopleSentConnectRequest; loadingS3UrlFactory.getNetworkNotificationFromUrls($scope.peopleSentConnectRequest[0].url).then(function(data){ var myDest= angular.copy(data); myDest.type="peopleSentConnectRequest"; myDest.connectFeedMessage=true; $scope.messages.feed.push(myDest); }); } }; $scope.socialBarContent =function(index){ if(!($scope.nonContentMessages.indexOf($scope.messages.feed[index].type)>-1)){ if($scope.messages.feed[index].hasOwnProperty('crawledMessage')){ if($scope.messages.feed[index].crawledMessage.template.templateId=="content_genericnews_00" || $scope.messages.feed[index].crawledMessage.template.templateId=="content_news_00"){ mycontentService.getSocialFullMessage($scope.messages.feed[index].crawledMessage.riakKey,index).then(function(data){ if(data!=undefined){ var socialMessage=data.socialMessage; if(socialMessage.commentedByList){ socialMessage.commentedByList.reverse(); } $scope.messages.feed[data.index].socialMessage= socialMessage; } }); } } } }; $rootScope.$on('RequestAccepted', function(event, args) { args.object.feed = args.object ; $scope.loadingAllFeedDashboard(args.object); }); $scope.removeItemFromUi = function(newItem){ var uiItemINdex= _.findIndex($scope.messages.feed , function(o) { return (( o.hasOwnProperty('shareId')&&o.shareId==newItem.shareId) ||( o.hasOwnProperty('questionId')&&(o.questionId==newItem.questionId)) || ( o.hasOwnProperty('activityId') && o.activityId == newItem.activityId)); }); if(uiItemINdex>-1){ $scope.messages.feed.splice( uiItemINdex, 1 ); } }; //Css collapsible $scope.inittap = function() { $('.collapsible').collapsible(); $('.collapsible').collapsible('open', 1); }; $scope.loadingAllFeedDashboard =function(feed){ if(feed.data.additionalBizDetails && feed.data.additionalBizDetails.businessTypeId && feed.data.additionalBizDetails.businessTypeId == 'BT000012'){ feed.data.additionalBizDetails.businessTypeName = 'A kalgudi user'; } if(feed.activityId){ feed.data.activityId = feed.activityId; } if(feed.event == "recommendedQ&A"){ feed.event = 'question'; feed.type="question"; for(var index in feed.data.qna_recommendation){ feed.data.qna_recommendation[index].isRecommended = true; feed.data.qna_recommendation[index].latestActivity = { type: 'question', id: feed.data.qna_recommendation[index].authorId, name: feed.data.qna_recommendation[index].authorName, notifyTime: feed.data.qna_recommendation[index].LUT, latestActivity:"" } feed.data.qna_recommendation[index].latestActivity.latestActivity= { type: 'recommendedQ&A', id: feed.data.qna_recommendation[index].authorId, name: feed.data.qna_recommendation[index].authorName } $scope.messages.feed.push(feed.data.qna_recommendation[index]); $scope.messages.feed=$filter('orderBy')($scope.messages.feed, 'LUT',true); } } else { if(feed.event=="ConnectsRecommendation"){ $rootScope.$broadcast("ConnectsRecommendationBroadCast", feed.data); } if(!($scope.nonContentMessages.indexOf(feed.event)>-1)){ if(feed.data.hasOwnProperty("modifiedDate")){ feed.data.latestActivity = { notifyTime : feed.data.modifiedDate } feed.data.LUT=feed.data.modifiedDate; } if(feed.data.hasOwnProperty("crawledMessage")){ if(feed.data.keypattern_id == 'DAILY_WEATHER_FORECAST'){ $scope.dailyWeatherInfo = feed.data; }else{ if(feed.data.keypattern_id == 'FOREX_RATES') $scope.forexInfo = feed.data; } feed.data.showFlag = false; feed.data.text = "Show more"; feed.data.latestActivity = { notifyTime : feed.data.crawledMessage.messageDate } feed.data.LUT=feed.data.crawledMessage.messageDate; } $scope.selectedMessages.messagesLoadedFlags[feed.data.keypattern_id] = false; } if(feed.event=='Share a Thought' || feed.event=="RecommendedShare a Thought"){ feed.data.comment=''; if(feed.data.hasOwnProperty('recentComments') && feed.data.recentComments.length != 0){ feed.data.recentComments = feed.data.recentComments; feed.data.count=2 } } if(feed.event=='question'|| feed.event=='answer' || feed.event=="recommendedQ&A"){ if(feed.data.hasOwnProperty("googleVisionResponse") && typeof(feed.data.googleVisionResponse)=='string'){ feed.data.googleVisionResponse = JSON.parse(feed.data.googleVisionResponse); } // feed.data.CT = $filter('timeagodatefilter')(feed.data.CT); } if(feed.eventCategory=='CONNECT'){ feed.data.LUT=feed.notifyTime; } if(feed.event == "Survey") { feed.data.LUT = feed.data.notification.notifyTime; } // Append price updates if(feed.eventCategory === 'PRICE_UPDATES') { feed.data.LUT = feed.data.modifiedDate; } feed.data.type=feed.event; if(feed.hasOwnProperty('whereToAppend')){ $scope.removeItemFromUi(feed.data); $scope.messages.feed.unshift(feed.data); $scope.messages.feed=$filter('orderBy')($scope.messages.feed, 'LUT',true); if((window.location.pathname.indexOf('mobile_index')>-1)){ $ionicScrollDelegate.scrollTop(); } }else{ $timeout(function(){ $scope.messages.feed.push(feed.data); $scope.messages.feed=$filter('orderBy')($scope.messages.feed, 'LUT',true); },0); } } $scope.seperateMultimediaAttachments(feed.data); // Issue: After load more feed tile header is not showing // Fix: Adding this to make sure latest activity always contains a latest activity field // with following other details. Since we have inject this everywhere in the feed items. if (feed.data.latestActivity && !feed.data.latestActivity.hasOwnProperty('latestActivity') && !feed.recommendationsFeed) { feed.data.latestActivity = { activityId: feed.data.id, isRecommended: false, // Condition already verified above isViewed: true, event: feed.data.latestActivity.event, eventCategory: "Social", latestActivity: new Object(feed.data.latestActivity), url: feed.data.s3URI, notifyTime: feed.data.LUT, moduleKey: "Content" }; } }; /** * Seperates other media attachments other than image from * list of attachments. This function will rmeove all media * attachments from lstOfAttachments field and put them to a * separate field lstOfMediaAttachments. * * @feed Feed object containing lstOfAttachments. */ $scope.seperateMultimediaAttachments = function (feed) { // Return if there is no attachments if (!feed.lstOfAttachments || !feed.lstOfAttachments.length) return; var mime = []; // Push all media attachments to separate array. for (var i = 0; i < feed.lstOfAttachments.length; i++) { if (feed.lstOfAttachments[i].msgType != 'IMAGE') { mime.push(feed.lstOfAttachments[i]); } } // Remove all media attachments from lstOfAttachments feed.lstOfAttachments = feed.lstOfAttachments.filter( function (attachment) { return (attachment.msgType === 'IMAGE'); } ); feed.lstOfMediaAttachments = mime; // Raise a flag for audio and doc attachments used by view mime.forEach(function (item) { if (item.msgType === 'DOCUMENT') feed.hasDocumentAttachment = true; if (item.msgType === 'AUDIO') feed.hasAudioAttachment = true; }); } $scope.homestreamBroadcast_webworker =function(oEvent){ switch (oEvent.data.type) { case "broadCastEachUrl" : { $scope.loadingAllFeedDashboard(oEvent.data.response); } break; case "broadCastAllmessagesloaded":{ if(loadingS3UrlFactory.storeNext20Urls.length!=0){ $scope.loadMore.text = $scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_MORE_MSG'); $scope.loadMore.flag = true; }else{ $scope.loadMore.text = $scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_NO_MORE_MSG'); $scope.loadMore.flag = false; } /*if($scope.messageRequest.offset==0 || feed.hasOwnProperty('whereToAppend') ){ var localStoragestreamFeed =$scope.messages.feed.concat(); localStoragestreamFeed.splice($scope.loadMore.limit); window.localStorage['homestream']=JSON.stringify(localStoragestreamFeed); }*/ if((window.location.pathname.indexOf('mobile_index')>-1)){ $scope.$broadcast('scroll.refreshComplete'); } // $rootScope.$broadcast('broadCastAllmessagesloaded',oEvent.data.response); } break; }; }; function registerEvents () { if((window.location.pathname.indexOf('mobile_index')>-1)){ feedworker.onmessage = function(oEvent) { $scope.homestreamBroadcast_webworker(oEvent); } }else{ $rootScope.$on('newFeedS3Stream', function (event, oEvent) { $scope.homestreamBroadcast_webworker(oEvent); }); } } registerEvents(); /*if(!networkAvaliable() && detectmob()){ $scope.messages.feed=JSON.parse(window.localStorage['homestream']); window.plugins.toast.show(' No network ', 'long', 'bottom'); if(loadingS3UrlFactory.storeNext20Urls.length!=0){ $scope.loadMore.text = "View more"; $scope.loadMore.flag = true; }else{ $scope.loadMore.text = "No more messages"; $scope.loadMore.flag = false; } }*/ $scope.recommendationsInFeedStream = function(){ loadingS3UrlFactory.S3FeedRecommendationStream($scope.FeedRequest).then(function(result){ }); }; $scope.LoadmorecallForS3FeedStream =function(){ loadingS3UrlFactory.fetchDataFromUrls(loadingS3UrlFactory.storeNext20Urls)/*.then(function(fetchedData){ });*/ loadingS3UrlFactory.LoadmorecallForLodingS3Urls($scope.FeedRequest).then(function(result){ if(loadingS3UrlFactory.storeNext20Urls.length!=0){ $scope.loadMore.text = $scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_MORE_MSG'); $scope.loadMore.flag = true; }else{ $scope.loadMore.text = $scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_NO_MORE_MSG'); $scope.loadMore.flag = false; } }); }; $scope.webNotificationForFirstTime=function(notificationsResult){ if(notificationsResult.hasOwnProperty('notifications')){ /*var socialNotifications = _.filter(notificationsResult.notifications,function(o){ return o.eventCategory != "CONNECT"});*/ loadingS3UrlFactory.callForLodingS3Urls(notificationsResult.notifications,$scope.FeedRequest,$scope.loadMore)/*.then(function(result){ if(loadingS3UrlFactory.storeNext20Urls.length!=0){ $scope.loadMore.text = "View more"; $scope.loadMore.flag = true; }else{ $scope.loadMore.text = "No more messages"; $scope.loadMore.flag = false; } });*/ } else{ $scope.loadMore.text = $scope.contentLiterals.searchByKey('COMMON_LOAD_MORE_NO_MORE_MSG'); $scope.loadMore.flag = false; } if(notificationsResult.hasOwnProperty('contentNotifications')){ loadingS3UrlFactory.contentNotifications(notificationsResult.contentNotifications).then(function(feedcontent){ for(var index in feedcontent){ var ConetentDummy={ data:feedcontent[index], event:'contnet' } $scope.loadingAllFeedDashboard(ConetentDummy); } }); } } $scope.viewNewFeedStreams =function(){ $rootScope.notifications.webMouseOverFlag = true; window.localStorage['webMouseOverFlag'] = true; $scope.loadMore.newItemsInFeedFlag =false; loadingS3UrlFactory.feedNotification($scope.FeedRequest); $scope.loadMore.newItemsInFeed=0; $rootScope.$broadcast("headerWebnotificationRead", $scope.loadMore.newItemsInFeed); $rootScope.$broadcast("headerWebnotificationReadService"); }; $scope.checkPendingActivity = function(){ if(commonServices.hasOwnProperty("getPendingActivity")){ commonServices.getPendingActivity().then(function(data){ if(data && data.data) { $rootScope.pendingActivityData = JSON.parse(data.data); } //console.log("response.data from service call:: ", $rootScope.pendingActivityData); }); } }; //It should get called only once /* if(!$rootScope.isPendingActivityChecked){ $scope.checkPendingActivity(); }*/ if(!$rootScope.isPendingActivityChecked){ profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function(){ $scope.checkPendingActivity(); }); } $scope.webNotification = function(interval){ commonServices.webNotifications().then(function(notificationsResult){ $rootScope.$broadcast("BroadCastNotifications", notificationsResult); var socialNotifications = _.filter(notificationsResult.notifications,function(o){ return o.eventCategory != "CONNECT"}); loadingS3UrlFactory.storeNewNotificationResult(notificationsResult.notifications); if(notificationsResult.hasOwnProperty('businessNotifications')){ var businessNotification = _.filter(notificationsResult.businessNotifications,function(o){ return o.eventCategory != "CONNECT"}); loadingS3UrlFactory.storeNewNotificationResult(businessNotification,'business'); } //loadingS3UrlFactory.storeNewNotificationResult(socialNotifications); //$scope.getCsmInboxMesages(notificationsResult.notifications); if(interval!='interval'){ /*var social=_.groupBy(notificationsResult.notifications,'eventCategory'); */ var social=_.groupBy(socialNotifications,'eventCategory'); $scope.webNotificationForFirstTime(notificationsResult); if( social['Social']!=undefined && social['Social'].length!=0){ loadingS3UrlFactory.makeNOtificationRead("homepage",social['Social'][0].notifyTime); } }else{ if($state.current.name=="home"){ /*$scope.loadMore.newItemsInFeed = dashboardFactory.webNotificationCount(notificationsResult.notifications,loadingS3UrlFactory.storeNotificationResult,0,'feedinbox');*/ $scope.loadMore.newItemsInFeed = dashboardFactory.webNotificationCount(socialNotifications,loadingS3UrlFactory.storeNotificationResult,0,'feedinbox'); if($scope.loadMore.newItemsInFeed>0){ var countOfnewitemsINUI=loadingS3UrlFactory.newFeedNotificationCount($scope.messages.feed,notificationsResult.notifications); var recommendedNotificationCount = loadingS3UrlFactory.recommendationsNotifications(); $scope.loadMore.newItemsInFeed=$scope.loadMore.newItemsInFeed-countOfnewitemsINUI.length; if($scope.loadMore.newItemsInFeed>0){ $scope.loadMore.newItemsInFeedFlag = true; }else{ $scope.loadMore.newItemsInFeedFlag = false; } $scope.loadMore.newItemsInFeedCount= $scope.loadMore.newItemsInFeed; }else{ $scope.loadMore.newItemsInFeedFlag = false; } } else{ //$scope.loadMore.newItemsInFeed=loadingS3UrlFactory.webNotificationCountIfINOtherPage(); /*$scope.loadMore.newItemsInFeed = dashboardFactory.webNotificationCount(notificationsResult.notifications);*/ $scope.loadMore.newItemsInFeed = dashboardFactory.webNotificationCount(socialNotifications); loadingS3UrlFactory.replaceStoredNotificationWithNew(); } } /*$rootScope.$broadcast("groupsCount");*/ $rootScope.$broadcast("headerWebnotificationRead", $scope.loadMore.newItemsInFeed); }); }; $rootScope.$on('homePageWebnotification', function(event, notificationsResult) { var socialNotifications = _.filter(notificationsResult.notifications,function(o){ return o.eventCategory != "CONNECT"}); $scope.loadMore.newItemsInFeed = loadingS3UrlFactory.webNotificationCount(socialNotifications); $scope.selfActivityList = loadingS3UrlFactory.selfActivityList(socialNotifications); if($scope.selfActivityList.length){ loadingS3UrlFactory.fetchDataFromUrls($scope.selfActivityList,'top'); $rootScope.$broadcast("headerWebnotificationReadService"); } if($scope.loadMore.newItemsInFeed>0){ var countOfnewitemsINUI=loadingS3UrlFactory.newFeedNotificationCount($scope.messages.feed,notificationsResult.notifications); var recommendedNotificationCount = loadingS3UrlFactory.recommendationsNotifications(); $scope.loadMore.newItemsInFeed=$scope.loadMore.newItemsInFeed-countOfnewitemsINUI.length; if($scope.loadMore.newItemsInFeed>0){ $scope.loadMore.newItemsInFeedFlag = true; }else{ $scope.loadMore.newItemsInFeedFlag = false; } $scope.loadMore.newItemsInFeedCount= $scope.loadMore.newItemsInFeed; }else{ $scope.loadMore.newItemsInFeedFlag = false; } $rootScope.$broadcast("headerWebnotificationRead", $scope.loadMore.newItemsInFeed); }); $rootScope.$on('homeNotificationONRefresh', function(event, notificationsResult) { var socialNotifications = _.filter(notificationsResult.notifications,function(o){ return o.eventCategory != "CONNECT"}); $scope.loadMore.newItemsInFeed = loadingS3UrlFactory.webNotificationCount(socialNotifications); $scope.selfActivityList = loadingS3UrlFactory.selfActivityList(socialNotifications); if($scope.selfActivityList.length){ loadingS3UrlFactory.fetchDataFromUrls($scope.selfActivityList,'top'); $rootScope.$broadcast("headerWebnotificationReadService"); } if($scope.loadMore.newItemsInFeed>0){ var countOfnewitemsINUI=loadingS3UrlFactory.newFeedNotificationCount($scope.messages.feed,notificationsResult.notifications); var recommendedNotificationCount = loadingS3UrlFactory.recommendationsNotifications(); $scope.loadMore.newItemsInFeed=$scope.loadMore.newItemsInFeed-countOfnewitemsINUI.length; } $scope.viewNewFeedStreams(); }); //if($rootScope.fromState || $state.current.name=="" || window.location.pathname.indexOf('mobile_index')>-1){ /*if(! $rootScope.isWebNotificationCalled){ webNotificationFactory.callWebNotifications(); } $rootScope.isWebNotificationCalled = false;*/ //} //$timeout(function(){ /*$rootScope.isWebNotificationCalled = false; $scope.isWebNotificationCallRequired = function (){ if((($state.current.data.action == "streamInbox" || $state.current.data.action == "inbox_temp") && !$rootScope.isWebNotificationCalled)){ $rootScope.isWebNotificationCalled = true; return true; } else { return false; } } */ /*if(window.location.pathname.indexOf('mobile_index')>-1){ webNotificationFactory.callWebNotifications(); } $scope.recommendationsInFeedStream();*/ $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { var fromStateList = ['programs.list']; if(fromStateList.includes(fromState.name)){ $scope.messages.feed = []; registerEvents(); } if(window.location.pathname.indexOf('mobile_index')>-1 && !$scope.messages.feed.length) { webNotificationFactory.callWebNotifications(); $scope.recommendationsInFeedStream(); } } ); /*$scope.getCsmInboxMesages($scope.csmRequest);*/ //},2000); /* $interval(function(){ $scope.webNotification("interval"); },120000);*/ $rootScope.$on('shareUpdatesInHome',function (event, feed) { var latestActivity={ "event" : "Share a Thought", "type" : "Share a Thought", "activityId" : feed.shareId, "TS" : feed.LUT, 'id' : $rootScope.loggedInUserBusinessProfile.profileKey }; feed.latestActivity=latestActivity; feed.latestActivity.latestActivity=latestActivity; var dummyFeedShare= {"data":feed,"whereToAppend":"top"}; dummyFeedShare.event="Share a Thought"; $scope.loadingAllFeedDashboard(dummyFeedShare); }); $rootScope.$on('questionInHome',function (event, feed) { var latestActivity={ "event":"question", "type":"question", "activityId":feed.questionId, "TS":feed.LUT, 'id':$rootScope.loggedInUserBusinessProfile.profileKey }; feed.latestActivity=latestActivity; feed.latestActivity.latestActivity=latestActivity; var dummyFeedQue= {"data":feed,"whereToAppend":"top"}; dummyFeedQue.event="question"; $scope.loadingAllFeedDashboard(dummyFeedQue); }); $scope.doHomeRefresh = function(){ webNotificationFactory.callWebNotifications('refresh'); } /** * Returns business state name based on the business of current logged in user. */ $scope.getBusinessInboxStateName = function() { // State name to return based on the business type var stateName = ""; if( $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000012"|| $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000015"|| $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000016"|| $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000017"|| $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000018"|| $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000019") { stateName = "basicApp.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000000") { stateName = "mybusiness.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000001") { stateName = "CA.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000010") { stateName = "coApp.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000002") { stateName = "farmer.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000003") { stateName = "mytransporter.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000006") { stateName = "mywarehouse.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000013") { stateName = "intermediaryApp.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000008") { stateName = "agriInput.streamInbox"; } else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000014") { stateName = "agencyApp.home"; } return stateName; } /** * Navigates to the business state based on the current logged in user business type. */ $scope.goToBusiness = function() { var businessStateName = $scope.getBusinessInboxStateName(); if(businessStateName != "") $rootScope.goToStateTransition(businessStateName); } /** * Function to add price updates to homestream. * * @priceUpdatesList List of price updates. */ onPriceUpdate = function(event, priceUpdatesList) { /* Inject price update list to homestream newsfeed */ for(i in priceUpdatesList) { // Add eventCategory to priceUpdates field priceUpdatesList[i].eventCategory = 'PRICE_UPDATES'; var feed = { data : priceUpdatesList[i] }; $scope.loadingAllFeedDashboard(feed); } } /* Subscribe price updates event */ $rootScope.$on('priceUpdates', onPriceUpdate); //Surveys functionality $scope.getSurveyStats = function(surveyId, flag){ $scope.statsFlag=flag; $scope.surveyIndex=surveyId; surveyServices.getStats(surveyId).then(function(response){ $scope.stats=JSON.parse(response.data); }); } //full view surveys //Full views $scope.openSurveyFullview = function(surveyObj){ var isAdmin = false; for(var i in surveyObj.admins){ if(surveyObj.admins[i].id == $rootScope.loggedInUserBusinessProfile.profileKey){ $state.go('surveys.adminFullview',{'id':surveyObj.id}); isAdmin =true; break; } } if(!isAdmin){ $state.go('surveys.response',{'surveyId':surveyObj.id, 'profileId' : $rootScope.loggedInUserBusinessProfile.profileKey}); } } $scope.trustAsHtml = function(title){ if (title) { return $sce.trustAsHtml(title.split("|")[0]); } else { return ''; } } } ]); angular.module('kalgudiApp').controller('reportAbouseController',['$uibModalInstance','$scope','dataItems','$rootScope','helpandlegalservice','$state', function ($uibModalInstance,$scope,dataItems,$rootScope,helpandlegalservice,$state) { $scope.ok = function () { $uibModalInstance.close(); }; $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; $scope.info = dataItems; $scope.personalDetails= $rootScope.loggedInUserBusinessProfile $scope.reportabusedir = function() { var request = { "userName":$scope.personalDetails.firstName, "profileKey": $scope.personalDetails.profileKey, "moduleId": $state.current.data.module, "fullViewMessageId":$state.params.threadId, "message":$scope.abusetextmodal.textdata, "mobileNumber":$scope.personalDetails.mobileNo, "businessName" : $scope.personalDetails.lstOfUserBusinessDetailsInfo[0].businessName, "location": $scope.personalDetails.lstOfUserBusinessDetailsInfo[0].locationTo.placeName }; if(request.message == ''){ $scope.reportmodalFlag = true; //$rootScope.validationTopErrorAlertFlagfun(); } else { helpandlegalservice.reportAbuseService(request).then(function(data){ if(data[0] == 200){ $scope.abusetextmodal.textdata ="" //$scope.reportmodalFlag = false; //$scope.reportabuseText.Flag=false; $scope.cancel(); } }); } } }]);