示例#1
0
        public BirthdayEvent(Core core, User owner, User user, int year)
            : base(core)
        {
            this.owner = owner;
            this.user = user;

            if (!user.IsFriend(owner.ItemKey))
            {
                throw new InvalidEventException();
            }

            UnixTime tz = new UnixTime(core, user.UserInfo.TimeZoneCode);

            this.eventId = ~user.Id;
            this.subject = user.TitleNameOwnership + " birthday";
            this.description = string.Empty;
            this.views = 0;
            this.attendeeCount = 0;
            this.ownerKey = new ItemKey(owner.Id, owner.TypeId);
            this.userId = user.Id;
            this.startTimeRaw =  tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 0, 0, 0));
            this.endTimeRaw = tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 23, 59, 59));
            this.allDay = true;
            this.invitees = 0;
            this.category = 0;
            this.location = string.Empty;
        }
        void AccountFriendManage_Add(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            // all ok, add as a friend
            long friendId = 0;

            try
            {
                friendId = long.Parse(core.Http.Query["id"]);
            }
            catch
            {
                SetRedirectUri(BuildUri());
                core.Display.ShowMessage("Cannot add friend", "No friend specified to add. Please go back and try again.");
                return;
            }

            // cannot befriend yourself
            if (friendId == LoggedInMember.UserId)
            {
                SetRedirectUri(BuildUri());
                core.Display.ShowMessage("Cannot add friend", "You cannot add yourself as a friend.");
                return;
            }

            // check existing friend-foe status
            DataTable relationsTable = db.Query(string.Format("SELECT relation_type FROM user_relations WHERE relation_me = {0} AND relation_you = {1}",
                LoggedInMember.UserId, friendId));

            for (int i = 0; i < relationsTable.Rows.Count; i++)
            {
                if ((string)relationsTable.Rows[i]["relation_type"] == "FRIEND")
                {
                    core.Display.ShowMessage("Already friend", "You have already added this person as a friend.");
                    return;
                }
                if ((string)relationsTable.Rows[i]["relation_type"] == "BLOCKED")
                {
                    core.Display.ShowMessage("Person Blocked", "You have blocked this person, to add them as a friend you must first unblock them.");
                    return;
                }
            }

            User friendProfile = new User(core, friendId);

            bool isFriend = friendProfile.IsFriend(session.LoggedInMember.ItemKey);

            db.BeginTransaction();
            long relationId = db.UpdateQuery(string.Format("INSERT INTO user_relations (relation_me, relation_you, relation_time_ut, relation_type) VALUES ({0}, {1}, UNIX_TIMESTAMP(), 'FRIEND');",
                LoggedInMember.UserId, friendId));

            //
            // send notifications
            //

            ApplicationEntry ae = core.GetApplication("Profile");

            if (!isFriend)
            {
                ae.SendNotification(core, LoggedInMember, friendProfile, LoggedInMember.ItemKey, LoggedInMember.ItemKey, "_WANTS_FRIENDSHIP", LoggedInMember.Uri, "friend");
            }
            else
            {
                ae.SendNotification(core, LoggedInMember, friendProfile, LoggedInMember.ItemKey, LoggedInMember.ItemKey, "_ACCEPTED_FRIENDSHIP", LoggedInMember.Uri);
            }

            db.UpdateQuery(string.Format("UPDATE user_info ui SET ui.user_friends = ui.user_friends + 1 WHERE ui.user_id = {0};",
                LoggedInMember.UserId));

            SetRedirectUri(BuildUri());
            core.Display.ShowMessage("Added friend", "You have added a friend.");
        }
示例#3
0
        public void Invite(Core core, User invitee)
        {
            core.LoadUserProfile(userId);
            User user = core.PrimitiveCache[userId];
            // only the person who created the event can invite people to it
            if (core.LoggedInMemberId == userId)
            {
                // we can only invite people friends with us to an event
                if (invitee.IsFriend(user.ItemKey))
                {
                    InsertQuery iQuery = new InsertQuery("event_invites");
                    iQuery.AddField("event_id", EventId);
                    iQuery.AddField("item_id", invitee.Id);
                    iQuery.AddField("item_type_id", invitee.TypeId);
                    iQuery.AddField("inviter_id", userId);
                    iQuery.AddField("invite_date_ut", UnixTime.UnixTimeStamp());
                    iQuery.AddField("invite_accepted", false);
                    iQuery.AddField("invite_status", (byte)EventAttendance.Unknown);

                    long invitationId = db.Query(iQuery);

                    UpdateQuery uQuery = new UpdateQuery("events");
                    uQuery.AddField("event_invitees", new QueryOperation("event_invitees", QueryOperations.Addition, 1));
                    uQuery.AddCondition("event_id", EventId);

                    db.Query(uQuery);

                    core.CallingApplication.SendNotification(core, user, invitee, OwnerKey, ItemKey, "_INVITED_EVENT", Uri, "invite");

                }
                else
                {
                    throw new CouldNotInviteEventException();
                }
            }
            else
            {
                throw new CouldNotInviteEventException();
            }
        }