コード例 #1
0
ファイル: Message.cs プロジェクト: davelondon/dontstayin
		public Message(MessageStub messageStub, Controller parent, int serverRequestIndex)
			: base(messageStub, parent, serverRequestIndex)
		{
			NickName = messageStub.nickName;
			StmuParams = messageStub.stmuParams;
			UsrK = messageStub.usrK;
			Pic = messageStub.pic;
			ChatPic = messageStub.chatPic;
			Text = messageStub.text;
			PinRoomGuid = messageStub.pinRoomGuid;
			RoomGuid = messageStub.roomGuid;
			AnyPic = Pic == "0" ? "00000000-0000-0000-b916-000000000001" : Pic;
			AnyChatPic = ChatPic == "0" ? "00000000-0000-0000-b916-000000000005" : ChatPic;
			
			IsInNewSection = false;
			IsTopOfSection = false;
			IsBottomOfSection = false;

			PicID = ClientID + "_Pic";
			PinID = ClientID + "_RoomPin";
			MessageBodyID = ClientID + "_MessageBody";
		}
コード例 #2
0
ファイル: Program.cs プロジェクト: davelondon/dontstayin
		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;
			}
		}
コード例 #3
0
ファイル: Chat.cs プロジェクト: davelondon/dontstayin
			public string GetArchiveItems(int numberOfItems)
			{
				//Get from cache...
				string s = (string)Caching.Instances.Main.Get(GetArchiveCacheKey(this.Guid));
				if (s != null && !Vars.DevEnv)
					return s;

				string roomGuidPacked = this.Guid.Pack();
				System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

				List<ItemStub> items = new List<ItemStub>();
				//Generate...
				if (IsThreadRoom || IsHasPrimaryThreadObject)
				{
					if (ThreadK > 0)
					{
						Query q = new Query();
						q.QueryCondition = new Q(Comment.Columns.ThreadK, ThreadK);
						q.OrderBy = new OrderBy(Comment.Columns.K, OrderBy.OrderDirection.Descending);
						q.TopRecords = numberOfItems;

						CommentSet cs = new CommentSet(q);

						for (int i = 0; i < cs.Count; i++)
						{
							Comment c = cs[i];

							if (!c.ChatItemGuid.HasValue)
							{
								c.ChatItemGuid = Guid.NewGuid();
								c.Update();
							}

							CommentMessageStub cms = c.GetCommentMessageStub();
							items.Add(cms);
						}
					}
				}
				else
				{
					//get from ChatMessage

					bool isBuddyIfRoomIsPrivate = IsPrivateChatRoom && ((Usr)ObjectBob).HasFullBuddy(SecondObjectK);

					Query q = new Query();
					q.QueryCondition = new Q(ChatMessage.Columns.RoomGuid, this.Guid);
					q.OrderBy = new OrderBy(ChatMessage.Columns.K, OrderBy.OrderDirection.Descending);
					q.TopRecords = numberOfItems;

					ChatMessageSet cs = new ChatMessageSet(q);

					for (int i = 0; i < cs.Count; i++)
					{
						ChatMessage cm = cs[i];

						if (cm.Deleted.HasValue && cm.Deleted.Value)
							break;

						if (!cm.ChatItemGuid.HasValue)
						{
							cm.ChatItemGuid = Guid.NewGuid();
							cm.Update();
						}

						if (IsPrivateChatRoom)
						{
							PrivateStub p = new PrivateStub(
								cm.ChatItemGuid.Value.Pack(),
								ItemType.PrivateChatMessage,
								cm.DateTime.Ticks.ToString(),
								roomGuidPacked,
								cm.FromUsr.NickName,
								cm.FromUsr.StmuParams,
								cm.FromUsr.K,
								cm.FromUsr.HasPicNotFacebook ? cm.FromUsr.Pic.ToString() : "0",
								cm.FromUsr.HasChatPic ? cm.FromUsr.ChatPic.Value.ToString() : "0",
								cm.Text,
								"",
								isBuddyIfRoomIsPrivate);
							items.Add(p);
						}
						else
						{
							MessageStub m = new MessageStub(
								cm.ChatItemGuid.Value.Pack(),
								ItemType.PrivateChatMessage,
								cm.DateTime.Ticks.ToString(),
								roomGuidPacked,
								cm.FromUsr.NickName,
								cm.FromUsr.StmuParams,
								cm.FromUsr.K,
								cm.FromUsr.HasPicNotFacebook ? cm.FromUsr.Pic.ToString() : "0",
								cm.FromUsr.HasChatPic ? cm.FromUsr.ChatPic.Value.ToString() : "0",
								cm.Text,
								"");
							items.Add(m);
						}
					}
				}

				string itemsString = "";

				if (items.Count > 0)
				{
					StringBuilder sb = new StringBuilder();
					foreach (ItemStub item in items)
					{
						if (sb.Length > 0)
							sb.Append(",");

						sb.Append(serializer.Serialize(item));
					}
					itemsString = sb.ToString();
				}

				Caching.Instances.Main.Set(GetArchiveCacheKey(this.Guid), itemsString);

				return itemsString;

			}
コード例 #4
0
ファイル: Service.asmx.cs プロジェクト: davelondon/dontstayin
		public RefreshStub Send(string message, string roomGuidString, string lastItemGuidString, int sessionID, string pageUrl, StateStub[] roomState)
		{
			WaitIfDevEnv();

			if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned)
				throw new LoginPermissionException();

			Guid guid = roomGuidString.UnPackGuid();
			Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid);
			Guid chatItemGuid = Guid.NewGuid();

			if (spec == null)
				throw new InvalidRoomException();

			if (!spec.CheckPermission(Usr.Current, true))
				throw new WritePermissionException();

			storeRoomState(roomState, Usr.Current.K);

			string txt = Chat.GetMessageFromChatBox(message);

			#region Create a ChatMessage database entry
			if (!spec.IsThreadRoom)
			{
				ChatMessage c = new ChatMessage();
				c.ChatItemGuid = chatItemGuid;
				c.DateTime = DateTime.Now;
				c.UsrK = Usr.Current.K;
				c.Text = txt;
				c.RoomGuid = spec.Guid;
				c.Update();
			}
			#endregion

			Usr.Current.ChatMessageCount++;
			Usr.Current.DateTimeLastChatMessage = DateTime.Now;
			string lastActionTicks = resetLastActionAndSessionID(sessionID); //will also fire Usr.Current.Update()

			MessageStub m;
			if (spec.IsPrivateChatRoom)
			{
				#region Private chat message
				int recipientUsrK = Usr.Current.K == spec.ObjectK ? spec.SecondObjectK : spec.ObjectK;
				bool isBuddy;
				try
				{
					Buddy b = new Buddy(recipientUsrK, Usr.Current.K);
					isBuddy = true;
				}
				catch
				{
					isBuddy = false;
				}
				
				m = new PrivateStub(
					chatItemGuid.Pack(),
					ItemType.PrivateChatMessage,
					lastActionTicks,
					roomGuidString.UnPackGuid().Pack(),
					Usr.Current.NickName,
					Usr.Current.StmuParams,
					Usr.Current.K,
					Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0",
					Usr.Current.HasChatPic ? Usr.Current.ChatPic.Value.ToString() : "0",
					txt,
					"",
					isBuddy);

				Chat.SendJsonChatItem(m, new int[]{Usr.Current.K, recipientUsrK});
				#endregion
			}
			else if (spec.IsThreadRoom || spec.IsHasPrimaryThreadObject)
			{
				#region Thread rooms
				Thread t = null;
				bool alreadyCreatedComment = false;
				bool createNewThread = false;


				if (spec.IsHasPrimaryThreadObject)
				{
					//if the object doesn't have a primary thread...
					IHasPrimaryThread primaryThreadObject = (IHasPrimaryThread)spec.ObjectBob;

					if (primaryThreadObject.ThreadK.IsNullOrZero())
					{
						createNewThread = true;
					}
					else
					{
						try
						{
							t = new Thread(primaryThreadObject.ThreadK.Value);
						}
						catch (BobNotFound)
						{
							createNewThread = true;
						}
					}

					if (createNewThread)
					{
						Thread.MakerReturn threadMakerReturn = Thread.CreatePublicThread((IDiscussable)spec.ObjectBob, Guid.NewGuid(), txt, false, null, true);

						alreadyCreatedComment = true;

						if (threadMakerReturn.Success || threadMakerReturn.Duplicate)
							t = threadMakerReturn.Thread;
						else
							throw new Exception("Couldn't create new thread!");
					}
				}
				else
				{
					t = new Thread(spec.ObjectK);
				}

				string subject = t.Subject.TruncateWithDots(30);
				int threadK = t.K;
				bool isPublic = !t.Private && !t.PrivateGroup && !t.GroupPrivate;
				string url = "";
				if (createNewThread)
				{
					url = t.UrlRefresher() + "#Comments";
				}
				else
				{
					if (t.LastPage == 1)
						url = t.UrlRefresher() + "#Comments";
					else
						url = t.UrlRefresher("c", t.LastPage.ToString()) + "#Comments";

					try
					{
						if (t.TotalComments % 20 == 0)
							url = t.UrlRefresher("c", (t.LastPage + 1).ToString()) + "#Comments";
						else if (t.LastComment != null)
							url = t.LastComment.UrlRefresherAnchorAfter();
					}
					catch { }
				}

				m = new CommentMessageStub(
					chatItemGuid.Pack(),
					ItemType.CommentChatMessage,
					lastActionTicks,
					roomGuidString.UnPackGuid().Pack(),
					Usr.Current.NickName,
					Usr.Current.StmuParams,
					Usr.Current.K,
					Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0",
					Usr.Current.HasChatPic ? Usr.Current.ChatPic.Value.ToString() : "0",
					txt,
					"",
					url,
					subject);

				List<int> usrKs = Thread.GetAllLoggedInParticipants(t).ToList().ConvertAll(u => u.K);
				try
				{
					usrKs.Add(Usr.Current.K);
				}
				catch { }
				
				Chat.SendJsonChatItem(m, usrKs.ToArray());

				if (isPublic && threadK > 0)
				{
					m.guid = Guid.NewGuid().Pack();
					m.roomGuid = new Chat.RoomSpec(RoomType.RandomChat).Guid.Pack();
					m.pinRoomGuid = t.GetRoomSpec().Guid.Pack();
					Chat.SendJsonChatItem(m);
				}

				if (!alreadyCreatedComment)
				{
					AddCommentJob job = new AddCommentJob(t.K, txt, Usr.Current.K, chatItemGuid);
					job.ExecuteAsynchronously();
				}
				#endregion
			}
			else
			{
				#region Public chat rooms
				m = new MessageStub(
					chatItemGuid.Pack(),
					ItemType.PublicChatMessage,
					lastActionTicks,
					roomGuidString.UnPackGuid().Pack(),
					Usr.Current.NickName,
					Usr.Current.StmuParams,
					Usr.Current.K,
					Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0",
					Usr.Current.HasChatPic ? Usr.Current.ChatPic.ToString() : "0",
					txt,
					"");

				Chat.SendJsonChatItem(m, Usr.Current.K);
				#endregion
			}

			SendStub s = new SendStub();
			s.itemGuid = chatItemGuid.Pack();

			RefreshStub r = refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, Usr.Current.K, roomState);
			s.guestRefreshStubs = r.guestRefreshStubs;
			s.itemsJson = r.itemsJson;
			s.lastActionTicks = r.lastActionTicks;
			s.lastItemGuidReturned = r.lastItemGuidReturned;
			return s;
		}