Example #1
0
		public void Test()
		{
			BuddyImporterService service = new BuddyImporterService();
			string email = "*****@*****.**";

			Usr u = new Usr();
			u.Update();

			Usr u2 = new Usr()
			{
				Email = email
			};
			u2.Update();

			Buddy b = new Buddy()
			{
				UsrK = u.K,
				BuddyUsrK = u2.K
			};
			b.Update();

			List<Contact> cList;
			List<Usr> uList;

			List<Contact> list = new List<Contact>()
			{
				new Contact("Bob", email)
			};

			int alreadyBuddies;
			service.SplitOutEmailContacts(list, u.K, out alreadyBuddies, out uList, out cList);

			Assert.AreEqual(1, uList.Count);
			Assert.IsTrue((bool)uList[0].ExtraSelectElements["BuddyRequested"]);
			Assert.AreEqual(0, cList.Count);
		}
Example #2
0
		public void SetBuddyInvite(Usr buddyUsr, bool allowBuddyInvite, AddBuddySource source, Buddy.BuddyFindingMethod? foundByMethod, string skeletonName)
		{
			if (allowBuddyInvite && !foundByMethod.HasValue)
			{
				throw new ArgumentNullException("foundByMethod", "Must have a method when allowBuddyInvite is true");
			}

			ValidateBuddyUsr(buddyUsr);

			if (this.HasBuddy(buddyUsr.K))
			{
				try
				{
					Buddy buddy = new Buddy(this.K, buddyUsr.K);
					buddy.CanBuddyInvite = allowBuddyInvite;
					buddy.Update();
					#region update reverse buddy
					try
					{
						Buddy reverseBuddy = new Buddy(buddyUsr.K, this.K);
						reverseBuddy.CanInvite = allowBuddyInvite;
						reverseBuddy.Update();
					}
					catch (BobNotFound) { }
					#endregion
				}
				catch (Exception ex)
				{
					throw ex;
				}
			}
			else if (allowBuddyInvite)
			{
				this.AddBuddy(buddyUsr, source, foundByMethod.Value, skeletonName );
			}
		}
Example #3
0
		public bool HasFullBuddy(int buddyUsrK)
		{
			try
			{
				Buddy b = new Buddy(this.K, buddyUsrK);
				return b.FullBuddy;
			}
			catch
			{
				return false;
			}
		}
Example #4
0
		public bool CanInvite(int buddyUsrK)
		{
			try
			{
				Buddy b = new Buddy(this.K, buddyUsrK);
				return b.CanInvite;
			}
			catch
			{
				return false;
			}
		}
Example #5
0
		public bool HasBuddy(int buddyUsrK)
		{
			try
			{
				Buddy b = new Buddy(this.K, buddyUsrK);
				return true;
			}
			catch
			{
				return false;
			}
		}
Example #6
0
		public void DenyBuddy(int buddyUsrK, bool deny)
		{
			if (deny == true)
			{
				try
				{
					Buddy b = new Buddy(buddyUsrK, this.K);
					b.Denied = true;
					b.FullBuddy = false;
					b.CanInvite = false;
					b.CanBuddyInvite = false;
					b.Update();
				}
				catch (BobNotFound)
				{
					Buddy b = new Buddy();
					b.UsrK = buddyUsrK;
					b.BuddyUsrK = this.K;
					b.Denied = true;
					b.Update();
				}
				try
				{
					Buddy b = new Buddy(this.K, buddyUsrK);
					b.Delete();
					b.Update();
				}
				catch (BobNotFound) { }
			}
			else
			{
				try
				{
					Buddy b = new Buddy(buddyUsrK, this.K);
					b.Denied = false;
					b.Update();
				}
				catch (BobNotFound) { }
			}
		}
Example #7
0
		public void RemoveBuddy(int BuddyUsrK)
		{
			try
			{
				Buddy b = new Buddy(this.K, BuddyUsrK);
				b.Delete();
				b.Update();
				b.Usr.UpdateBuddyCount(null);
				b.BuddyUsr.UpdateBuddyCount(null);
			}
			catch { }

			try
			{
				Buddy b = new Buddy(BuddyUsrK, this.K);
				b.FullBuddy = false;
				b.Update();
				b.Usr.UpdateBuddyCount(null);
				b.BuddyUsr.UpdateBuddyCount(null);
			}
			catch { }
		}
		private void BuddyInvite(bool state, int buddyK, Buddy.BuddyFindingMethod usrFoundByMethod)
		{
			Usr.Current.SetBuddyInvite(new Usr(buddyK), state, Usr.AddBuddySource.BuddyButtonClick, usrFoundByMethod, null);
		}
Example #9
0
		public void AddBuddy(Usr buddyUsr, bool canBuddyInvite, AddBuddySource source, Buddy.BuddyFindingMethod foundByMethod, string skeletonName)
		{
			AddBuddy(buddyUsr, canBuddyInvite, true, source, foundByMethod, skeletonName);
		}
Example #10
0
		private string getSpottedDisplayHtml(Usr usr)
		{
			if (usr.NickName != "")
			{
				return usr.Link();
			}
			if (Usr.Current != null)
			{
				try
				{
					Buddy b = new Buddy(Usr.Current.K, usr.K);
					return "<span onmouseover=\"stt('" + usr.Email + "');\" onmouseout=\"htm();\">" + (b.SkeletonName != "" ? b.SkeletonName : usr.Email.TruncateWithDots(10) )+ "</span>";
					
				}
				catch (BobNotFound) { }
			}

			return null;
		}
Example #11
0
		private int CreateUsrFromEmail(string text, bool addAsBuddy)
		{
			string email = text;
			string name = name = email.TruncateWithDots(10);
			int indexOfFirstSpace = text.IndexOf(' ');
			if (indexOfFirstSpace >= 0)
			{
				email = text.Substring(0, indexOfFirstSpace);
				name = text.Substring(indexOfFirstSpace + 1);
			}
			Regex emailRegex = new Regex(Cambro.Misc.RegEx.Email);
			if (!emailRegex.IsMatch(email))
			{
				throw new Exception(email + "is not a valid email address. ALERT");
			}
			else
			{
				var usrSet = new UsrSet(new Query(new Q(Bobs.Usr.Columns.Email, email)));
				if (usrSet.Count == 0)
				{
					var service = new BuddyImporterService();
					service.InviteContacts(Usr.Current, new List<Contact>() { new Contact(name, email) });
					usrSet = new UsrSet(new Query(new Q(Bobs.Usr.Columns.Email, email)));
				}
				Usr newUsr = usrSet[0];
				if (addAsBuddy)
				{
					try
					{
						Buddy buddy = new Buddy(Usr.Current.K, newUsr.K);
					}
					catch (BobNotFound)
					{
						Usr.Current.AddBuddy(newUsr, true, true, Usr.AddBuddySource.BuddyAutoComplete, Buddy.BuddyFindingMethod.EmailAddress, name);
					}
				}
				return usrSet[0].K;
			}
		}
Example #12
0
		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;
		}
Example #13
0
		protected void InviteGridView_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				DropDownList OptionsDropDownList = (DropDownList)e.Row.FindControl("OptionsDropDownList");
				DropDownList TopicOptionsDropDownList = (DropDownList)e.Row.FindControl("TopicOptionsDropDownList");
				Label InviteNotBuddyLabel = (Label)e.Row.FindControl("InviteNotBuddyLabel");
				ThreadUsr threadUsr = (Bobs.ThreadUsr)e.Row.DataItem;

				if (OptionsDropDownList != null)
				{
					OptionsDropDownList.Items.Clear();
					OptionsDropDownList.Items.Add(new ListItem("Leave as buddy", ""));
					if (threadUsr.InvitingUsr.CanInvite(Usr.Current.K))
						OptionsDropDownList.Items.Add(new ListItem("Stop bulk invite", "Stop bulk invite"));
					try
					{
						Buddy buddy = new Buddy(Usr.Current.K, threadUsr.InvitingUsrK);
						OptionsDropDownList.Items.Add(new ListItem("Un-buddy", "Un-buddy"));
					}
					catch
					{
						InviteNotBuddyLabel.Visible = true;
						OptionsDropDownList.Visible = false;
					}
				}

				SetupTopicOptionsDropDownList(TopicOptionsDropDownList);
			}

			GridViewRowDataBound(sender, e);
		}
Example #14
0
		public bool AllowLinkToProfile(Buddy.BuddyFindingMethod? buddyFindingMethod)
		{
			return (buddyFindingMethod.HasValue && buddyFindingMethod.Value == Buddy.BuddyFindingMethod.SpotterCode) ||
				this.ExDirectory == false ||
				(BuddyRelationshipWithCurrentLoggedInUsr != null &&
					(BuddyRelationshipWithCurrentLoggedInUsr.FullBuddy == true ||
					BuddyRelationshipWithCurrentLoggedInUsr.BuddyFoundByMethod == Buddy.BuddyFindingMethod.Nickname ||
					BuddyRelationshipWithCurrentLoggedInUsr.BuddyFoundByMethod == Buddy.BuddyFindingMethod.SpotterCode));
		}
Example #15
0
		public void AddBuddy(Usr buddyUsr, bool canBuddyInvite, bool sendNotificationEmailIfNewBuddyRequest, AddBuddySource source, Buddy.BuddyFindingMethod foundByMethod, string skeletonName)
		{
			ValidateBuddyUsr(buddyUsr, true);

			Buddy b;
			try
			{
				b = new Buddy(this.K, buddyUsr.K);
			}
			catch (BobNotFound)
			{
				b = new Buddy();
				b.UsrK = this.K;
				b.BuddyUsrK = buddyUsr.K;
				b.CanBuddyInvite = canBuddyInvite;
				b.BuddyFoundByMethod = foundByMethod;
				b.SkeletonName = skeletonName;
				try
				{
					Buddy reverseBuddy = new Buddy(buddyUsr.K, this.K);
					reverseBuddy.FullBuddy = true;
					reverseBuddy.Denied = false;
					reverseBuddy.CanInvite = canBuddyInvite;
					b.CanInvite = reverseBuddy.CanBuddyInvite;
					b.FullBuddy = true;
					b.Denied = false;
					reverseBuddy.Update();

					if (this.FacebookConnected && this.FacebookStoryNewBuddy)
					{
						try
						{
							FacebookPost.CreateNewBuddy(this, buddyUsr, true);
						}
						catch { }
					}

					if (buddyUsr.FacebookConnected && buddyUsr.FacebookStoryNewBuddy)
					{
						try
						{
							FacebookPost.CreateNewBuddy(buddyUsr, this, false);
						}
						catch { }
					}
				}
				catch (BobNotFound)
				{
					if (source == AddBuddySource.BuddyButtonClick ||
						source == AddBuddySource.UsrPageSendPrivateMessage)
					{
						Usr.IncrementSpamBotDefeaterCounter(SpamBotDefeaterCounter.BuddyRequests, this.K);
					}

					b.CanInvite = false;
					b.FullBuddy = false;

					if (sendNotificationEmailIfNewBuddyRequest)
					{
						Mailer m = new Mailer();
						m.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
						m.Subject = this.NickName + " has invited you to " + this.HisString(false) + " buddy list";
						
						if (this.HasPic)
						{
							m.Body += "<a href=\"[LOGIN(" + this.Url() + ")]\"><img src=\"" + this.PicPath + "\" style=\"margin-left:5px;\" class=\"BorderBlack All\" width=\"100\" height=\"100\" align=\"right\" vspace=\"6\" border=\"0\"></a>";
						}
						m.Body += "<h1>" + HttpUtility.HtmlEncode(this.NickName) + " has invited you to " + this.HisString(false) + " buddy list</h1>";
						m.Body += "<p>Name: <a href=\"[LOGIN(" + this.Url() + ")]\">" + HttpUtility.HtmlEncode(this.FirstName) + " " + HttpUtility.HtmlEncode(this.LastName) + "</a>.</p>";
						m.Body += "<p>To add " + HttpUtility.HtmlEncode(this.NickName) + " to your buddy list, view " + this.HisString(false) + " <a href=\"[LOGIN(" + this.Url() + ")]\">profile</a> and click the \"Add " + HttpUtility.HtmlEncode(this.NickName) + " to my buddy list\" button.</p>";
						m.OverrideLoginLink = buddyUsr.LoginAndTransfer(this.Url());
						m.UsrRecipient = buddyUsr;
						m.To = buddyUsr.Email;
						m.Send();
					}
				}
				b.Update();
				b.Usr.UpdateBuddyCount(null);
				b.BuddyUsr.UpdateBuddyCount(null);
			}
		}
Example #16
0
		public string DisplayName(Buddy.BuddyFindingMethod? foundByMethod)
		{
			if (!this.ExDirectory)
			{
				return this.NickNameSafe;
			}
			if (!foundByMethod.HasValue)
			{
				if (BuddyRelationshipWithCurrentLoggedInUsr == null)
				{
					throw new ArgumentNullException("foundByMethod", "must have a value if current Buddy relationship is null");
				}
				else
				{
					foundByMethod = BuddyRelationshipWithCurrentLoggedInUsr.BuddyFoundByMethod;
				}
			}

			switch (foundByMethod.Value)
			{
				case Bobs.Buddy.BuddyFindingMethod.Nickname: return this.NickNameSafe;
				case Bobs.Buddy.BuddyFindingMethod.EmailAddress: return this.Email;
				case Bobs.Buddy.BuddyFindingMethod.RealName: return this.FullName;
				case Bobs.Buddy.BuddyFindingMethod.SpotterCode: return this.NickNameSafe; // this is fine, spotter numbers are public anyway
				default: throw new NotImplementedException();
			}
		}
		private static void Buddy(bool state, int buddyK, Buddy.BuddyFindingMethod foundByMethod)
		{
			Usr u = new Usr(buddyK);

			if (state)
				Usr.Current.AddBuddy(u, Usr.AddBuddySource.BuddyButtonClick, foundByMethod, null);
			else
				Usr.Current.RemoveBuddy(u.K);
		}