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); }
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."); }
bool gotRoom(object o, EventArgs e) { GotRoomEventArgs a = (GotRoomEventArgs)e; object ob = Rooms[a.RoomStub.guid]; if (ob == null) { Room r = new Room(this, View); r.InitialiseFromStub(a.RoomStub, a.RoomStub.guest ? View.RoomGuestList : a.RoomStub.isPrivateChatRoom ? View.RoomPrivateList : View.RoomList, State); initialiseRoomEvents(r); Rooms[r.Guid] = r; RoomsListOrder[RoomsListOrder.Length] = r.Guid; r.SetListOrder(RoomsListOrder.Length - 1); SelectedRoom = r; updateDraggable(); if (a.RoomStub.guest) updateRoomGuestListVisibility(true); else if (a.RoomStub.isPrivateChatRoom) updateRoomPrivateListVisibility(true); return false; } else { Room r = (Room)ob; if (!r.Pinned) r.Pinned = true; SelectedRoom = r; return true; } }
bool gotNewPhotoRoom(object o, EventArgs e) { GotRoomEventArgs a = (GotRoomEventArgs)e; bool newRoomShouldBeSelected = removeAllUnPinnedGuestPhotoRoomsExceptSpecified(a.RoomStub.guid); object ob = Rooms[a.RoomStub.guid]; if (ob == null) { Room r = new Room(this, View); r.InitialiseFromStub(a.RoomStub, a.RoomStub.isPrivateChatRoom ? View.RoomPrivateList : a.RoomStub.guest ? View.RoomGuestList : View.RoomList, State); initialiseRoomEvents(r); Rooms[r.Guid] = r; RoomsListOrder[RoomsListOrder.Length] = r.Guid; r.SetListOrder(RoomsListOrder.Length - 1); if (newRoomShouldBeSelected) setSelectedRoom(r, false); updateDraggable(); updateRoomUI(); return false; } else { Room r = (Room)ob; if (newRoomShouldBeSelected) setSelectedRoom(r, false); return true; } }
public void PinNewRoom(string newRoomGuid) { unPauseChatClient(false); View.TabsChatLink.Focus(); object ob = Rooms[newRoomGuid]; if (ob == null) { Server.PinRoom(newRoomGuid); } else { Room r = (Room)ob; if (!r.Pinned) r.Pinned = true; SelectedRoom = r; } }
void roomListClick(DomEvent e) { if (e.Target.ID.EndsWith("PrivateChatDrop")) return; if (e.Target.ID.EndsWith("_Link") || e.Target.ID.EndsWith("_Icon")) { Room r = getRoomFromChildID(e.Target.ID); SelectedRoom = r; unPauseChatClient(true); } else if (e.Target.ID.EndsWith("_Cross")) { Room r = getRoomFromChildID(e.Target.ID); if (r.Pinned) { unPauseChatClient(false); SelectedRoom = null; r.Pinned = false; //r.RemoveFromRoomsList(); } else unPauseChatClient(true); } else if (e.Target.ID.EndsWith("_Star")) { Room r = getRoomFromChildID(e.Target.ID); if (r.Starrable) r.Starred = !r.Starred; else if (r.Starred) Script.Alert("This room can't be un-starred"); else Script.Alert("This room can't be starred"); unPauseChatClient(true); } if (SelectedRoom != null) { focusNow(SelectedRoom); } e.PreventDefault(); }
void unPauseChatClient(bool selectPreviousRoom) { if (chatClientIsPaused) { chatClientIsPaused = false; View.WrongSessionHolder.Style.Display = "none"; View.TimeoutHolder.Style.Display = "none"; if (selectPreviousRoom && previouslySelectedRoomGuid.Length > 0) SelectedRoom = (Room)Rooms[previouslySelectedRoomGuid]; Server.ResumeAfterPause(); } }
void gotTimeoutException(object o, EventArgs e) { GotExceptionEventArgs a = (GotExceptionEventArgs)e; previouslySelectedRoomGuid = SelectedRoom == null ? "" : SelectedRoom.Guid; SelectedRoom = null; chatClientIsPaused = true; View.WrongSessionHolder.Style.Display = "none"; View.TimeoutHolder.Style.Display = ""; }
void focusNow(Room r) { if (!r.ReadOnly && UsrK > 0) View.TextBox.Focus(); else View.TabsChatLink.Focus(); }
void setSelectedRoom(Room room, bool focus) { if (chatClientIsPaused) { previouslySelectedRoomGuid = room == null ? "" : room.Guid; return; } selectedRoomGuid = room == null ? "" : room.Guid; foreach (DictionaryEntry entry in Rooms) { Room r = (Room)entry.Value; if (room != null && r.Guid == room.Guid) { if (!r.Selected) { r.Selected = true; selectedRoomGuid = r.Guid; } } else if (r.Selected) { r.Selected = false; } } View.TextBox.Style.Display = (room == null || room.ReadOnly) ? "none" : ""; View.DeleteArchiveHolder.Style.Display = (room == null || !room.IsPrivateChatRoom) ? "none" : ""; View.DeleteArchiveDoneLabel.Style.Display = "none"; //Script.Literal("RepositionChatBox()"); if (room != null && focus) { focusNow(room); } }
void initialiseRoomEvents(Room r) { r.RoomPinAction = new EventHandler(roomPinAction); r.RoomStarAction = new EventHandler(roomStarAction); r.GetMoreInfoHtml = new EventHandler(getRoomMoreInfoHtml); r.GetArchiveItems = new EventHandler(getRoomArchiveItems); if (r.Guest) r.GuestRoomPinAction = new EventHandler(guestRoomPinAction); }
void outerKeyDown(DomEvent e) { if (e.KeyCode == (int)Key.Up || e.KeyCode == (int)Key.Down) { int selectedRoomIndex = getSelectedRoomListIndex(); Room newRoom = null; int count = 0; while ((count <= RoomsListOrder.Length + 1) && (newRoom == null || !newRoom.Pinned || newRoom.Guid == PublicStreamRoomGuid)) { if (e.KeyCode == (int)Key.Up) { if (selectedRoomIndex == 0) selectedRoomIndex = RoomsListOrder.Length; selectedRoomIndex--; } else if (e.KeyCode == (int)Key.Down) { if (selectedRoomIndex == RoomsListOrder.Length - 1) selectedRoomIndex = -1; selectedRoomIndex++; } newRoom = (Room)Rooms[RoomsListOrder[selectedRoomIndex].ToString()]; count++; } SelectedRoom = newRoom; unPauseChatClient(true); e.PreventDefault(); } }