Ejemplo n.º 1
0
		public RefreshStub StoreUpdatedRoomListOrder(string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState)
		{
			WaitIfDevEnv();

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

			storeRoomState(roomState, Usr.Current.K);

			foreach (StateStub ss in roomState)
			{
				try
				{
					RoomPin rp = new RoomPin(Usr.Current.K, ss.guid.UnPackGuid());
					if (rp.ListOrder != ss.listOrder)
					{
						rp.ListOrder = ss.listOrder;
						rp.Update();
					}
				}
				catch(BobNotFound)
				{
					Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(ss.guid.UnPackGuid());
					RoomPin rp = new RoomPin();
					rp.DateTime = DateTime.Now;
					rp.ListOrder = ss.listOrder;
					rp.Pinned = true;
					rp.RoomGuid = spec.Guid;
					rp.Starred = spec.IsStarredByDefault;
					rp.UsrK = Usr.Current.K;
					rp.Update();
				}
			}

			return refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, Usr.Current.K, roomState);
		}
Ejemplo n.º 2
0
		RoomPin getOrCreateRoomPin(Guid guid, int? listOrder, int usrK)
		{
			Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid);
			RoomPin p;
			try
			{
				p = new RoomPin(usrK, guid);
			}
			catch
			{
				p = new RoomPin();
				p.UsrK = usrK;
				p.RoomGuid = guid;
				if (listOrder.HasValue)
					p.ListOrder = listOrder.Value;
				else
					p.ListOrder = GetMaximumRoomPinListOrder(Usr.Current) + 1;
			}
			p.DateTime = DateTime.Now;
			p.Pinned = true;
			p.Starred = spec.IsStarredByDefault;
			p.Expires = false;
			p.Update();
			return p;
		}
Ejemplo n.º 3
0
		public UnPinStub UnPin(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();

			StateStub state = null;
			foreach (StateStub ss in roomState)
			{
				if (ss.guid == roomGuid)
				{
					state = ss;
					break;
				}
			}

			#region Exit room on chat server only if we need to
			//For thread chat and PersistantAlertsRooms, we don't want to exit the room on the chat server.
			if (spec.RoomType == RoomType.Normal && (spec.ObjectType == Model.Entities.ObjectType.Thread || (spec.ObjectBob != null && spec.ObjectBob is IHasPrimaryThread && ((IHasPrimaryThread)spec.ObjectBob).ThreadK.IsNotNullOrZero())))
			{
				//don't exit the room if we're watching the topic
				bool exitRoom = true;
				int threadK = spec.ObjectType == Model.Entities.ObjectType.Thread ? spec.ObjectK : ((IHasPrimaryThread)spec.ObjectBob).ThreadK.Value;

				try
				{
					Thread t = new Thread(threadK);
					ThreadUsr tu = t.GetThreadUsr(Usr.Current);
					if (tu != null && tu.IsWatching)
						exitRoom = false;
				}
				catch { }
				if (exitRoom)
					Chat.ExitRoom(guid, Usr.Current.K);
			}
			else if (!spec.IsPersistantAlertsRoom)
			{
				Chat.ExitRoom(guid, Usr.Current.K);
			}
			#endregion

			#region Store the un-pinned room in the database, or delete the pin record.
			try
			{
				RoomPin rp = new RoomPin(Usr.Current.K, guid);
				if (spec.IsDefaultRoom)
				{
					rp.Pinned = false;
					rp.Update();
				}
				else
				{
					rp.Delete();
				}
			}
			catch (BobNotFound)
			{
				if (spec.IsDefaultRoom)
				{
					RoomPin rp = new RoomPin();
					rp.UsrK = Usr.Current.K;
					rp.RoomGuid = guid;
					rp.ListOrder = state != null ? state.listOrder : 0;
					rp.Pinned = false;
					rp.Starred = spec.IsStarredByDefault;
					rp.DateTime = DateTime.Now;
					rp.Update();
				}
			}
			#endregion

			storeRoomState(roomState, Usr.Current.K);

			lastActionTicks = resetLastActionAndSessionID(sessionID);

			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.GetLatest(Usr.Current.K, sessionID, false, lastItemGuid, ref lastItemGuidReturned);

			UnPinStub ups = new UnPinStub();
			ups.roomGuid = roomGuid;
			ups.itemsJson = chatItems;
			ups.lastActionTicks = lastActionTicks;
			ups.lastItemGuidReturned = lastItemGuidReturned.Pack();
			return ups;
		}
Ejemplo n.º 4
0
		public RefreshStub Star(string clientID, string roomGuid, bool starred, 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.IsStarrable)
				throw new Exception("This room is not starrable");

			StateStub state = null;
			foreach (StateStub ss in roomState)
			{
				if (ss.guid == roomGuid)
				{
					state = ss;
					break;
				}
			}

			#region Store the star room in the database, or delete the pin record.
			try
			{
				RoomPin rp = new RoomPin(Usr.Current.K, guid);
				rp.Starred = starred;
				rp.Update();
			}
			catch (BobNotFound)
			{
				if (!spec.IsDefaultRoom || spec.IsStarredByDefault != starred)
				{
					RoomPin rp = new RoomPin();
					rp.UsrK = Usr.Current.K;
					rp.RoomGuid = guid;
					rp.ListOrder = state != null ? state.listOrder : 0;
					rp.Pinned = true;
					rp.Starred = starred;
					rp.DateTime = DateTime.Now;
					rp.Update();
				}
			}
			#endregion

			storeRoomState(roomState, Usr.Current.K);

			lastActionTicks = resetLastActionAndSessionID(sessionID);

			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.GetLatest(Usr.Current.K, sessionID, false, lastItemGuid, ref lastItemGuidReturned);

			RefreshStub rs = new RefreshStub();
			rs.itemsJson = chatItems;
			rs.lastActionTicks = lastActionTicks;
			rs.lastItemGuidReturned = lastItemGuidReturned.Pack();
			return rs;
		}
Ejemplo n.º 5
0
		void ensureAllRoomsAreInDatabase(Dictionary<Guid, RoomStub> rooms, List<Guid> roomsOrder, RoomPinSet roomPinSet)
		{
			if (Usr.Current != null)
			{
				Dictionary<Guid, RoomPin> roomPins = new Dictionary<Guid, RoomPin>();
				if (roomPinSet != null) roomPinSet.ToList().ForEach((rp) => { if (!roomPins.ContainsKey(rp.RoomGuid)) roomPins.Add(rp.RoomGuid, rp); });

				foreach (Guid g in roomsOrder)
				{
					if (!roomPins.ContainsKey(g))
					{
						try
						{
							Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(g);
							RoomPin rp = new RoomPin();
							rp.DateTime = DateTime.Now;
							rp.ListOrder = rooms[g].listOrder;
							rp.Pinned = rooms[g].pinned;
							rp.RoomGuid = g;
							rp.Starred = rooms[g].starred;
							rp.UsrK = Usr.Current.K;
							rp.Update();
						}
						catch { }
					}
				}
			}
		}