﻿
Type.registerNamespace("PlainJoeStudios.MediaSocial.WebServer.Controls");PlainJoeStudios.MediaSocial.WebServer.Controls.FacebookFriendsList=function(vars)
{this.Initialize(vars);};PlainJoeStudios.MediaSocial.WebServer.Controls.FacebookFriendsList.prototype={UserStatusExcerptLengthMax:100,UserListMaxResults:80,_ClientID:null,_ConnectedToFacebook:false,_Mode:null,_TemplateUserPlacard:null,_TemplateUserPlacardNoChatLink:null,_EnablePersonalMessageCheck:null,_EventId:null,_FacebookUserId:null,_JqUserListPanel:null,_tUserPlacard:null,_tiPopupCurrentlyOpen:null,_iPopupHoverDelayTimeoutId:null,_iPopupHoverDelayForFbUserId:null,_jqPopupContainer:null,Initialize:function(vars){var This=this;this._ConnectedToFacebook=vars["ConnectedToFacebook"];this._TemplateUserPlacard=vars["TemplateUserPlacard"];this._TemplateUserPlacardNoChatLink=vars["TemplateUserPlacardNoChatLink"];this._Mode=vars["Mode"];this._EnablePersonalMessageCheck=vars["EnablePersonalMessageCheck"];this._EventId=vars["EventId"];this._ClientID=vars["ClientID"];if(typeof(vars["UserListPanelId"])==="string"){this._JqUserListPanel=$("#"+vars["UserListPanelId"]);}
if(this._JqUserListPanel==null||this._JqUserListPanel.length==0){throw new Error("Cannot find user list panel.");}
this._tUserPlacard=$tau("ms","FacebookFriendsList_UserPlacard");var oBus=$PJP.GetControl("ChannelBus");oBus.attachListener(oBus.LISTENER_TYPE_WHOS_ONLINE,function(oData){This._processUserListPacket(oData);});if(this._Mode==="FriendsOnly"){oBus.attachListener(oBus.LISTENER_TYPE_CHAT_PRIVATE,function(oData){This._processPrivateChatAlerts(oData);});}
this._jqPopupContainer=$("#socialtop");},_processUserListPacket:function(oPacket){var This=this;var arr_oUsersOnline;if(oPacket!=null&&oPacket.FacebookUsers!=null){arr_oUsersOnline=oPacket.FacebookUsers||null;}
else{arr_oUsersOnline=null;}
var oFbUser=g_Facebook.GetUser();var strCurrentFbUserId=g_Facebook.GetUserId();var arr_iFbUserFriends=g_Facebook.GetUserFriends();if(!(arr_oUsersOnline!=null&&(this._Mode!=="FriendsOnly"||(this._Mode=="FriendsOnly"&&arr_iFbUserFriends!=null)))){return;}
var iUsersShownInList=0;var hash_oUsersOnline={};for(var i=arr_oUsersOnline.length-1;i>=0;--i){var oTmp=arr_oUsersOnline[i];hash_oUsersOnline[oTmp.UserId.toString()]=oTmp;}
if(arr_oUsersOnline!==null){var jqExistingUsers=this._JqUserListPanel.find(".tUserPlacard");var iNumExistingUsers=jqExistingUsers.length;for(var i=0;i<iNumExistingUsers;++i){var tiExistingUser=jqExistingUsers.eq(i).data("tau");var strExistingFbUserId=tiExistingUser.data("FbUserId").toString();var oUserFromPacket=hash_oUsersOnline[strExistingFbUserId]||null;if(oUserFromPacket===null){tiExistingUser.root.remove();continue;}
else{tiExistingUser.namedElements.TxtStatus.text(oUserFromPacket.UserStatus||"");tiExistingUser.namedElements.TxtLocation.text(oUserFromPacket.GeographicalLocation||"");++iUsersShownInList;hash_oUsersOnline[strExistingFbUserId]={__type:"msffltmp",updated:true,tau:tiExistingUser};var oDataSource={UserId:oUserFromPacket["UserId"],UserName:oUserFromPacket["Name"]||"Facebook User",UserLocation:oUserFromPacket["GeographicalLocation"]||"",UserStatus:oUserFromPacket["UserStatus"]||"",UserPicUrl:oUserFromPacket["UserPictureUrl"]||"null.null",NumViewingsAtChannel:oUserFromPacket["NumViewingsAtChannel"]||0,IsModeratorAtChannel:oUserFromPacket["IsModeratorAtChannel"]};tiExistingUser.dataSource(oDataSource);var bShowChatLink=false;if(oFbUser!==null&&oDataSource.UserId!=strCurrentFbUserId){bShowChatLink=true;}
if(!bShowChatLink){tiExistingUser.namedElements.btnOpenChat.hide();}
else{tiExistingUser.namedElements.btnOpenChat.show();}}}}
var jqPreviousRow=null;for(var i=0;i<arr_oUsersOnline.length;++i){var tmpResult=arr_oUsersOnline[i];var strFbUserId=tmpResult["UserId"].toString();if(hash_oUsersOnline[strFbUserId].__type==="msffltmp"){jqPreviousRow=hash_oUsersOnline[strFbUserId].tau.root;continue;}
if(this._Mode==="FriendsOnly"){var bFound=false;for(var j=0;j<arr_iFbUserFriends.length;++j){if(arr_iFbUserFriends[j]==strFbUserId){bFound=true;break;}}
if(!bFound){continue;}}
if(tmpResult["Name"]==null||tmpResult["Name"]==="Facebook User"||tmpResult["UserPictureUrl"]==null){continue;}
var oDataSource={UserId:tmpResult["UserId"],UserName:tmpResult["Name"]||"Facebook User",UserLocation:tmpResult["GeographicalLocation"]||"",UserStatus:tmpResult["UserStatus"]||"",UserPicUrl:tmpResult["UserPictureUrl"]||"null.null",NumViewingsAtChannel:tmpResult["NumViewingsAtChannel"]||0,IsModeratorAtChannel:tmpResult["IsModeratorAtChannel"]};var tiUserPlacard=this._tUserPlacard.Generate("FbUser_"+this._Mode+"_"+oDataSource.UserId,oDataSource,this);if(jqPreviousRow===null){this._JqUserListPanel.prepend(tiUserPlacard.root);}
else{tiUserPlacard.root.insertAfter(jqPreviousRow);}
jqPreviousRow=tiUserPlacard.root;tiUserPlacard.data("FbUserId",strFbUserId);tiUserPlacard.root.data("tau",tiUserPlacard);var bShowChatLink=false;if(oFbUser!=null&&strCurrentFbUserId!=strFbUserId){bShowChatLink=true;}
if(!bShowChatLink){tiUserPlacard.namedElements.btnOpenChat.hide();}
else{tiUserPlacard.namedElements.btnOpenChat.show();}
tiUserPlacard.namedElements.divAdminOptions.remove();++iUsersShownInList;}
if(this._Mode!=="FriendsOnly"){$PJP.GetControl("FacebookOverview").NotifyNumFbUsersOnline(iUsersShownInList,oPacket.NumTotalViewers);}
else{$PJP.GetControl("FacebookOverview").NotifyNumFriendsOnline(iUsersShownInList);}},onPlacardClick:function(tiUserPlacard,oEvent){var bIsExpanded=tiUserPlacard.data("IsExpanded")||false;if(!bIsExpanded&&tiUserPlacard.namedElements.btnOpenChat.css("display")=="none"){return;}
if(!bIsExpanded){tiUserPlacard.namedElements.DivExpanded.slideDown();tiUserPlacard.root.addClass("user_expanded");tiUserPlacard.data("IsExpanded",true);}
else{tiUserPlacard.namedElements.DivExpanded.slideUp();tiUserPlacard.root.removeClass("user_expanded");tiUserPlacard.data("IsExpanded",false);}},onModeratorCheckClicked:function(ti,oEvent){},onModeratorCheckChanged:function(ti,oEvent){var strFacebookUserId=ti.dataSource()["UserId"];var bSetAsModerator=ti.namedElements.chkModerator.attr("checked");PlainJoeStudios.MediaSocial.WebServer.Services.Channel.SetFacebookUserIsModerator(this._EventId,strFacebookUserId,bSetAsModerator,function(){},function(){});oEvent.stopPropagation();},onChatClick:function(ti){var strFbUserId=ti.dataSource()["UserId"];var windowName="MediaSocialChat"+strFbUserId;if(WindowManager.GetWindow(windowName)==null){var openedWindow=window.open("/MediaSocial/Chat.aspx/PrivateMessage/"+strFbUserId,windowName,"width=644,height=447,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0",false);if(WindowManager.CheckForPopupBlock(openedWindow)){return;}
WindowManager.RegisterWindow(windowName,openedWindow);}},_processPrivateChatAlerts:function(result){var This=this;if(result!=null){for(var i=0;i<result.length;++i){var windowName="MediaSocialChat"+result[i].UserId;var windowTimestamp=WindowManager.GetWindowTimestamp(windowName);if(windowTimestamp==null||windowTimestamp<result[i]["Timestamp"]){if(WindowManager.GetWindow(windowName)==null){var openedWindow=window.open("/MediaSocial/Chat.aspx/PrivateMessage/"+result[i].UserId,windowName,"width=644,height=447,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0",false);if(WindowManager.CheckForPopupBlock(openedWindow)){return;}
WindowManager.RegisterWindow(windowName,openedWindow,result[i]["Timestamp"]);}
else{WindowManager.SetWindowTimestamp(windowName,result[i]["Timestamp"]);}}}}}};