Пример #1
0
		public ServerClass(Controller controller, int sessionID, string lastActionTicks, StateStub[] controllerRoomState)
		{
			SessionID = sessionID;
			LastActionTicks = lastActionTicks;
			LastItemGuid = "";
			RequestIndex = 0;
			Controller = controller;
			criticalRequestQueue = new Queue();
			criticalRequestInProgress = false;
			periodicBackgroundRefreshInProgress = false;
			cancelCurrentPeriodicBackgroundRefresh = false;
			periodicBackgroundRefreshIsPaused = false;
			roomState = controllerRoomState;
		}
Пример #2
0
		public Popup(Controller controller, string title, Room room, HtmlItem[] items)
		{
			Title = title;
			RoomGuid = room.Guid;
			Removed = false;
			RoomGuidForClickAction = room.Guid;
			//RoomGuidForClickAction = item.GetRoomGuidForChatClickAction();


			#region //Holder
			Holder = (DivElement)Document.CreateElement("div");
			Holder.ClassName = "ChatClientPopup";
			Holder.Style.Width = PopupArea.PopupWidth.ToString() + "px";
			Holder.Style.Height = PopupArea.PopupHeight.ToString() + "px";
			
			#region //HeaderDiv
			DOMElement header = (DOMElement)Document.CreateElement("div");
			header.ClassName = "ChatClientPopupHeader";
			header.Style.Overflow = "hidden";

			{
				#region //Close button
				DivElement div = (DivElement)Document.CreateElement("div");
				div.ClassName = "ChatClientPopupCloseLinkHolder";

				{
					AnchorElement link = (AnchorElement)Document.CreateElement("a");
					link.InnerHTML = "Close";
					link.Href = "";
					DomEvent.AddHandler(link, "click", new DomEventHandler(closeButtonClick));
					div.AppendChild(link);
				}
				header.AppendChild(div);
				#endregion
			}

			{
				#region //TitleDiv
				DivElement div = (DivElement)Document.CreateElement("div");
				div.ClassName = "ChatClientPopupTitle";
				div.InnerHTML = Title;
				header.AppendChild(div);
				#endregion
			}

			Holder.AppendChild(header);
			
			#endregion

			#region //ItemsDiv
			{
				if (items != null)
				{
					ItemsList = (DivElement)Document.CreateElement("div");
					ItemsList.ClassName = "ChatClientPopupItemsList";

					DomEvent.AddHandler(ItemsList, "click", new DomEventHandler(holderClick));
					DomEvent.AddHandler(ItemsList, "mouseover", new DomEventHandler(holderMouseOver));
					DomEvent.AddHandler(ItemsList, "mouseout", new DomEventHandler(holderMouseOut));

					bool hasMultipleRelevantItems = false;
					for (int i = 0; i < items.Length; i++)
					{
						HtmlItem item = (HtmlItem)items[i];

						#region // if the item is posted by the current user, we never want to show a popup
						if (item is IHasPostingUsr)
						{
							if (((IHasPostingUsr)item).PostingUsrK == controller.UsrK)
								continue;
						}
						#endregion

						if (HasRelevantItems)
						{
							hasMultipleRelevantItems = true;
							break;
						}

						HasRelevantItems = true;
					}
					if (HasRelevantItems)
					{
						for (int i = 0; i < items.Length; i++)
						{
							HtmlItem item = (HtmlItem)items[i];

							#region // if the item is posted by the current user, we never want to show a popup
							if (item is IHasPostingUsr)
							{
								if (((IHasPostingUsr)item).PostingUsrK == controller.UsrK)
									continue;
							}
							#endregion

							if (!hasMultipleRelevantItems)
								RoomGuidForClickAction = item.GetRoomGuidForChatClickAction();

							#region //bodge it so it displays correctly - remember to save all things we change
							int previousInstance = item.Instance;
							bool previousNewStatus = false;
							if (item is Newable)
							{
								previousNewStatus = ((Newable)item).IsInNewSection;
								((Newable)item).IsInNewSection = false;
							}
							item.Instance = 2;

							bool previousShowChatButton = false;
							if (!hasMultipleRelevantItems && item is Message) // we only hide the chat button if there's only one item shown. for multi-item popups we want to leave the chat buttons as they were.
							{
								previousShowChatButton = ((Message)item).ShowChatButton;
								((Message)item).ShowChatButton = false;
							}
							#endregion

							DOMElement itemNode = Document.CreateElement("span");
							itemNode.InnerHTML = item.ToHtml();

							if (ItemsList.HasChildNodes())
								ItemsList.InsertBefore(itemNode, ItemsList.ChildNodes[0]);
							else
								ItemsList.AppendChild(itemNode);

							#region //restore all the things we bodged

							item.Instance = previousInstance;

							if (item is Newable)
								((Newable)item).IsInNewSection = previousNewStatus;
							
							if (!hasMultipleRelevantItems && item is Message) // we only hide the chat button if there's only one item shown. for multi-item popups we want to leave the chat buttons as they were.
								((Message)item).ShowChatButton = previousShowChatButton;

							#endregion

						}
						Holder.AppendChild(ItemsList);
					}
				}
			}
			#endregion

			#endregion

			Id = Math.Random().ToString();
			jHolder = JQueryAPI.JQuery(Holder);
		}
Пример #3
0
		public Room(Controller parent, View view)
		{
			Parent = parent;
			Items = (Item[])new Array();

			LoggedIn = parent.LoggedIn;

			elementsInitialised = false;
			needsNewStatusUpdate = false;
			doneFullUpdateOfNewStatus = false;
			
			MesssagesElementHolder = Document.CreateElement("div");
			MesssagesElementHolder.Style.Display = "none";
			view.MessageList.AppendChild(MesssagesElementHolder);

		//	if (this.Guid == parent.PublicStreamRoomGuid)
		//	{
		//		Script.Alert("foo");
		//		MesssagesElement = view.StreamList;
		//	}
		//	else
		//	{
				MesssagesElement = Document.CreateElement("div");
				MesssagesElementHolder.AppendChild(MesssagesElement);
		//	}

			MoreInfoElement = Document.CreateElement("div");
			MoreInfoElement.ClassName = "ChatClientMessageListHiddenHolder";
			view.MessageList.AppendChild(MoreInfoElement);

			RequestIndex = 0;

		}
Пример #4
0
		void initialise()
		{
			if (View.InitGo.Value == "0")
				return;

			serverTicksAtPageLoad = getRelevantDigits(View.InitLastActionTicks.Value);
			clientTicksAtPageLoad = getRelevantDigits(new DateTime().GetTime().ToString());

			StreamList = View.StreamList;
			Instance = this;
			UsrK = int.ParseInvariant(View.InitUsrK.Value);
			LoggedIn = UsrK > 0;
			ClientID = View.InitClientID.Value;
			LastActionTicks = View.InitLastActionTicks.Value;
			SessionID = Math.Round(Math.Random() * 10000);
			SystemMessagesRoomGuid = View.InitSystemMessagesRoomGuid.Value;
			InboxUpdatesRoomGuid = View.InitInboxUpdatesRoomGuid.Value;
			BuddyStreamRoomGuid = View.InitBuddyStreamRoomGuid.Value;
			PublicStreamRoomGuid = "ARAFAAAAAAUAAAAANdfH9w";
			PrivateChatRequestsRoomGuid = "ARIFAAAAAAUAAAAAO3ZY0A";
			lastKeyDown = -1;
			chatClientIsPaused = false;
			State = new StateStub[0];
			RoomsListOrder = new Array();
			Popups = new PopupArea(View);

			#region Add dom events
			DomEvent.AddHandler(View.TextBox, "focus", new DomEventHandler(textBoxFocus));
			DomEvent.AddHandler(View.TextBox, "blur", new DomEventHandler(textBoxBlur));
			DomEvent.AddHandler(View.TextBox, "keypress", new DomEventHandler(textBoxKeyPress));
			DomEvent.AddHandler(View.TextBox, "keydown", new DomEventHandler(textBoxKeyDown));
			DomEvent.AddHandler(View.OuterMain, "keydown", new DomEventHandler(outerKeyDown));
			DomEvent.AddHandler(View.RoomsMain, "click", new DomEventHandler(roomListClick));
			DomEvent.AddHandler(View.RoomsMain, "mousedown", new DomEventHandler(roomListMouseDown));
			if (LoggedIn)
			{
				DomEvent.AddHandler(View.PrivateChatDrop, "change", new DomEventHandler(privateChatDropChange));
			}
			DomEvent.AddHandler(View.WrongSessionResumeLink, "click", new DomEventHandler(resumeLinkClick));
			DomEvent.AddHandler(View.TimeoutResumeLink, "click", new DomEventHandler(resumeLinkClick));
			DomEvent.AddHandler(View.DeleteArchiveAnchor, "click", new DomEventHandler(deleteArchive));
			#endregion

			#region Create rooms
			Rooms = new Dictionary();
			selectedRoomGuid = "";
			for (int i = 0; i < View.RoomList.ChildNodes.Length + View.RoomPrivateList.ChildNodes.Length + View.RoomGuestList.ChildNodes.Length; i++)
			{
				DOMElement child = null;
				if (i < View.RoomList.ChildNodes.Length)
					child = View.RoomList.ChildNodes[i];
				else if (i < View.RoomList.ChildNodes.Length + View.RoomPrivateList.ChildNodes.Length)
					child = View.RoomPrivateList.ChildNodes[i - View.RoomList.ChildNodes.Length];
				else
					child = View.RoomGuestList.ChildNodes[i - View.RoomList.ChildNodes.Length - View.RoomPrivateList.ChildNodes.Length];

				if (child.NodeType == DOMElementType.Element && child.ClassName.StartsWith("ChatClientRoomHolder"))
				{
					Room r = new Room(this, View);
					r.InitialiseFromElement(child, State);
					initialiseRoomEvents(r);

					if (r.Selected)
					{
						if (selectedRoomGuid.Length > 0)
							r.Selected = false;
						else
							selectedRoomGuid = r.Guid;
					}

					Rooms[r.Guid] = r;
					RoomsListOrder[RoomsListOrder.Length] = r.Guid;
					r.SetListOrder(RoomsListOrder.Length - 1);
				}
			}
			#endregion

			#region LatestTopPhoto
			if (View.InitTopPhoto.Value.Length > 0 && Rooms["AQEFAAAAAAUAAAAAvVaVmQ"] != null)
			{
				string[] topPhotoParts = View.InitTopPhoto.Value.Split(',');
				TopPhoto p = new TopPhoto(
					new TopPhotoStub(
						"", 
						ItemType.TopPhoto, 
						"", 
						"AQEFAAAAAAUAAAAAvVaVmQ",
						int.ParseInvariant(topPhotoParts[0]),
						topPhotoParts[1],
						topPhotoParts[2],
						topPhotoParts[3],
						int.ParseInvariant(topPhotoParts[4]),
						int.ParseInvariant(topPhotoParts[5]),
						topPhotoParts[6],
						int.ParseInvariant(topPhotoParts[7]),
						int.ParseInvariant(topPhotoParts[8])),
					this);
				((Room)Rooms["AQEFAAAAAAUAAAAAvVaVmQ"]).AddItem(p, null);
			}
			#endregion

			updateDraggable();

			#region Initialise server
			Server = new ServerClass(this, SessionID, LastActionTicks, State);
			Server.GotItems = new EventHandler(gotItems);
			Server.GotNoItems = new EventHandler(gotNoItems);
			Server.GotWrongSessionException = new EventHandler(gotWrongSessionException);
			Server.GotTimeoutException = new EventHandler(gotTimeoutException);
			Server.GotGenericException = new EventHandler(gotGenericException);
			Server.GotRoom = new GotRoomHandler(gotRoom);
			Server.GotNewPhotoRoom = new GotRoomHandler(gotNewPhotoRoom);
			Server.GotRoomState = new EventHandler(gotRoomState);
			Server.ShowLoadingIcon = new EventHandler(showLoadingIcon);
			Server.HideLoadingIcon = new EventHandler(hideLoadingIcon);
			Server.GotMoreInfo = new EventHandler(gotRoomMoreInfoHtml);
			Server.GotArchiveItems = new EventHandler(gotRoomArchiveItems);
			Server.DebugPrint = new EventHandler(debugEventHandler);
			Server.DoneDeleteArchive = new EventHandler(doneDeleteArchive);
			Server.Start();
			#endregion

			if (selectedRoomGuid.Length == 0 && RoomsListOrder.Length > 0)
				SelectedRoom = (Room)Rooms[(string)RoomsListOrder[0]];

			debug("Controller started successfully.");

			
		}