protected override void Execute() { Usr myUsr = new Usr(UsrK); //get logged on buddies... Query q = new Query(); q.TableElement = Usr.BuddyJoin; q.QueryCondition = new And(myUsr.BuddiesFullQ, Usr.LoggedInChatQ); q.Columns = new ColumnSet(Usr.Columns.K); UsrSet loggedOnBuddies = new UsrSet(q); Guid myRoom = new Chat.RoomSpec(SpottedScript.Controls.ChatClient.Shared.RoomType.BuddyAlerts, Model.Entities.ObjectType.Usr, myUsr.K).Guid; if (loggedOnBuddies.Count > 0) { int[] loggedOnBuddyKs = loggedOnBuddies.ToList().ConvertAll(u1 => u1.K).ToArray(); List<Guid> buddyRooms = new List<Guid>(); foreach (int buddyK in loggedOnBuddyKs) { buddyRooms.Add(new Chat.RoomSpec(SpottedScript.Controls.ChatClient.Shared.RoomType.BuddyAlerts, Model.Entities.ObjectType.Usr, buddyK).Guid); } ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); cs.JoinRoom(buddyRooms.ToArray(), myUsr.K); cs.JoinRoom(myRoom, loggedOnBuddyKs); } if (SendLoginChatItem) { SpottedScript.Controls.ChatClient.Shared.AlertStub alertStub = new SpottedScript.Controls.ChatClient.Shared.AlertStub( Guid.NewGuid().Pack(), SpottedScript.Controls.ChatClient.Shared.ItemType.LoginAlert, DateTime.Now.Ticks.ToString(), myRoom.Pack(), myUsr.NickName, myUsr.StmuParams, myUsr.K, myUsr.HasPic ? myUsr.Pic.ToString() : "0"); Chat.SendJsonChatItem(alertStub); } }
public static void SendNow(ChatMessage c, Random r) { try { Query q = new Query(); q.QueryCondition = new Q(RoomPin.Columns.Pinned, true); RoomPinSet rps = new RoomPinSet(q); Guid roomGuid; int rand = r.Next(10); if (rand == 1) roomGuid = new Chat.RoomSpec(RoomType.RandomChat, Model.Entities.ObjectType.None, 0, Model.Entities.ObjectType.None, 0).Guid; else if (rand == 2) roomGuid = new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.None, 0, Model.Entities.ObjectType.None, 0).Guid; else roomGuid = rps[r.Next(rps.Count)].RoomGuid; string chatRoomName = roomGuid.ToString(); try { Chat.RoomSpec c1 = Chat.RoomSpec.FromGuid(roomGuid); if (c1.GetName().Length > 0) chatRoomName = c1.GetName(); else chatRoomName = c1.RoomType.ToString(); if (c1.RoomType != RoomType.Normal && c1.RoomType != RoomType.PrivateChat) return; } catch { } MessageStub m = new MessageStub( Guid.NewGuid().Pack(), ItemType.PublicChatMessage, DateTime.Now.Ticks.ToString(), roomGuid.Pack(), c.FromUsr.NickName, c.FromUsr.StmuParams, c.FromUsr.K, c.FromUsr.HasPic ? c.FromUsr.Pic.ToString() : "0", c.FromUsr.HasChatPic ? c.FromUsr.ChatPic.Value.ToString() : "0", c.Text + " (" + chatRoomName + ")", ""); Chat.SendJsonChatItem(m, c.FromUsr.K); } catch(Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public PinStub Pin(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); storeRoomState(roomState, Usr.Current.K); RoomStub r; if (spec.RoomType == RoomType.BuddyAlerts && spec.ObjectK > 0) { if (spec.ObjectK == Usr.Current.K) throw new SelfPrivateChatRoomException(); spec = new Chat.RoomSpec(spec.ObjectK, Usr.Current.K); guid = spec.Guid; } if (spec.RoomType == RoomType.PrivateChat && spec.ObjectK > 0 && spec.SecondObjectK == 0) { if (spec.ObjectK == Usr.Current.K) throw new SelfPrivateChatRoomException(); spec = new Chat.RoomSpec(spec.ObjectK, Usr.Current.K); guid = spec.Guid; } if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); lastActionTicks = resetLastActionAndSessionID(sessionID); RoomPin p = getOrCreateRoomPin(guid, null, Usr.Current.K); r = new RoomStub( clientID, guid.Pack(), spec.GetName(Usr.Current), spec.GetUrl(Usr.Current), true, spec.IsStarredByDefault, spec.IsStarredByDefault, true, spec.IsStarrable, false, false, 0, 0, "", "", "", spec.IsReadOnly, p.ListOrder, spec.IsPhotoChatRoom, spec.IsPrivateChatRoom, spec.IsNewPhotoAlertsRoom, spec.GetPrivateChatRoomPresence(Usr.Current), spec.Icon, "", "", spec.HasArchive, spec.HiddenFromRoomList, spec.IsStreamRoom); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.PinRoom(Usr.Current.K, sessionID, lastItemGuid, ref lastItemGuidReturned, guid); PinStub ps = new PinStub(); ps.roomStub = r; ps.itemsJson = chatItems; ps.lastActionTicks = lastActionTicks; ps.lastItemGuidReturned = lastItemGuidReturned.Pack(); return ps; }
public Chat.RoomSpec GetRoomSpec() { Chat.RoomSpec roomSpec = new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.Thread, this.K); try { //Lets work out the room... remember for photo / article primary threads, we post to the parent room, not the thread room. if (this.PhotoK > 0 && this.Photo != null && this.Photo.ThreadK == this.K) { roomSpec = new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.Photo, this.PhotoK); } else if (this.ArticleK > 0 && this.Article != null && this.Article.ThreadK == this.K) { roomSpec = new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.Article, this.ArticleK); } } catch { } return roomSpec; }
List<Guid> getGuestRooms(Dictionary<Guid, RoomStub> rooms) { List<Guid> guestRooms = new List<Guid>(); Thread t = null; if (ContainerPage.Url.HasObjectFilter || (ContainerPage.Url.CurrentApplication == "chat" && ContainerPage.Url["k"].IsInt)) { IBob guestChatObject = null; #region Get from page if (ContainerPage.Url.CurrentApplication == "chat" && ContainerPage.Url["k"].IsInt) { try { t = new Thread(ContainerPage.Url["k"]); IBob b = t.ParentObject; while (b != null && b is Photo && b is IHasParent) b = ((IHasParent)b).ParentObject; guestChatObject = (IBob)b; } catch { } } else if (ContainerPage.Url.HasArticleObjectFilter) guestChatObject = ContainerPage.Url.ObjectFilterArticle; else if (ContainerPage.Url.HasGroupLogicalFilter) guestChatObject = ContainerPage.Url.LogicalFilterGroup; else if (ContainerPage.Url.HasEventObjectFilter) guestChatObject = ContainerPage.Url.ObjectFilterEvent; else if (ContainerPage.Url.HasVenueObjectFilter) guestChatObject = ContainerPage.Url.ObjectFilterVenue; else if (ContainerPage.Url.HasPlaceObjectFilter) guestChatObject = ContainerPage.Url.ObjectFilterPlace; else if (ContainerPage.Url.HasCountryObjectFilter) guestChatObject = ContainerPage.Url.ObjectFilterCountry; else if (ContainerPage.Url.HasUsrObjectFilter && Usr.Current != null && ContainerPage.Url.ObjectFilterUsr.K != Usr.Current.K) guestChatObject = ContainerPage.Url.ObjectFilterUsr; #endregion if (guestChatObject != null) { #region Create spec Chat.RoomSpec s = null; if (guestChatObject is Usr) { if (Usr.Current != null) { Usr usrWeAreVisiting = (Usr)guestChatObject; if (usrWeAreVisiting.K != Usr.Current.K) { s = new Chat.RoomSpec(Usr.Current.K, usrWeAreVisiting.K); } } } else { s = new Chat.RoomSpec(RoomType.Normal, ((IBobType)guestChatObject).ObjectType, ((IHasSinglePrimaryKey)guestChatObject).K); } #endregion if (s != null && !s.Disabled && s.CheckPermission(Usr.Current, false)) { Guid g = s.Guid; guestRooms.Add(g); } } } #region Did we find a thread? if (t != null) { try { Chat.RoomSpec s = t.GetRoomSpec(); if (s != null && !s.Disabled && s.CheckPermission(Usr.Current, false)) guestRooms.Add(s.Guid); } catch { } } #endregion #region Photo guest Photo p = null; if ((ContainerPage.Url.CurrentApplication.StartsWith("tags/") || ContainerPage.Url.CurrentApplication == "photos") && ContainerPage.Url["photo"].IsInt) { //photo room... try { p = new Photo(ContainerPage.Url["photo"]); } catch { } } else if (ContainerPage.Url.HasPhotoObjectFilter) { try { p = ContainerPage.Url.ObjectFilterPhoto; } catch { } } else if (ContainerPage.Url.HasGalleryObjectFilter && ContainerPage.Url.ObjectFilterGallery.LivePhotos > 0) { try { p = ContainerPage.Url.ObjectFilterGallery.ChildPhotos(Photo.EnabledQueryCondition, Photo.DefaultOrder)[0]; } catch { } } if (p != null) { try { Chat.RoomSpec s = new Chat.RoomSpec(RoomType.Normal, Model.Entities.ObjectType.Photo, p.K); if (s != null && !s.Disabled && s.CheckPermission(Usr.Current, false)) guestRooms.Add(s.Guid); } catch { } } #endregion return guestRooms; }