示例#1
0
        internal static void RenderMessage(Core core, Template template, Message message)
        {
            MessageRecipient recipient = new MessageRecipient(core, core.Session.LoggedInMember, message.Id);

            VariableCollection messageVariableCollection = template.CreateChild("post_list");

            messageVariableCollection.Parse("SUBJECT", message.Subject);
            messageVariableCollection.Parse("POST_TIME", core.Tz.DateTimeToString(message.GetSentDate(core.Tz)));
            messageVariableCollection.Parse("URI", message.Uri);
            messageVariableCollection.Parse("ID", message.Id.ToString());
            core.Display.ParseBbcode(messageVariableCollection, "MESSAGE", message.Text);
            if (message.Sender != null)
            {
                messageVariableCollection.Parse("U_USER", message.Sender.Uri);
                messageVariableCollection.Parse("USER_DISPLAY_NAME", message.Sender.UserInfo.DisplayName);
                messageVariableCollection.Parse("USER_TILE", message.Sender.Tile);
                messageVariableCollection.Parse("USER_ICON", message.Sender.Icon);
                messageVariableCollection.Parse("USER_JOINED", core.Tz.DateTimeToString(message.Sender.UserInfo.GetRegistrationDate(core.Tz)));
                messageVariableCollection.Parse("USER_COUNTRY", message.Sender.Profile.Country);
                //core.Display.ParseBbcode(messageVariableCollection, "SIGNATURE", postersList[post.UserId].ForumSignature);

                if (message.Sender.Id == core.LoggedInMemberId)
                {
                    messageVariableCollection.Parse("OWNER", "TRUE");
                }
            }
            else
            {
                messageVariableCollection.Parse("USER_DISPLAY_NAME", "Anonymous");
            }

            if (recipient.IsRead)
            {
                messageVariableCollection.Parse("IS_READ", "TRUE");
            }
            else
            {
                messageVariableCollection.Parse("IS_READ", "FALSE");
            }

            recipient.MarkRead();
        }
示例#2
0
        public static void Create(Core core, Message message, MessageRecipient recipient, RecipientType type, MailFolder folder)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Item.Create(core, typeof(MessageRecipient), true,
                new FieldValuePair("message_id", message.Id),
                new FieldValuePair("sender_id", message.SenderId),
                new FieldValuePair("user_id", recipient.UserId),
                new FieldValuePair("message_folder_id", folder.Id),
                new FieldValuePair("recipient_type", (byte)type),
                new FieldValuePair("is_read", type == RecipientType.Sender));
        }
示例#3
0
        void AccountCompose_ReplySave(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            bool ajax = false;

            try
            {
                ajax = bool.Parse(core.Http["ajax"]);
            }
            catch { }

            long messageId = core.Functions.FormLong("id", 0);
            long newestId = core.Functions.FormLong("newest-id", 0);
            string text = core.Http.Form["message"];

            Message threadStart = new Message(core, messageId);

            Message newMessage = Message.Reply(core, LoggedInMember, threadStart, text);

            if (ajax)
            {
                Template template = new Template(core.CallingApplication.Assembly, "pane_message");

                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                MessageRecipient recipient = new MessageRecipient(core, core.Session.LoggedInMember, messageId);

                template.Parse("S_ID", threadStart.Id.ToString());

                List<Message> messages = threadStart.GetMessages(newestId, true);

                // IF NOT DELETED THEN
                foreach (Message message in messages)
                {
                    AccountMessage.RenderMessage(core, template, message);
                    newestId = message.Id;
                }

                threadStart.MarkRead();

                Dictionary<string, string> returnValues = new Dictionary<string, string>();

                returnValues.Add("update", "true");
                returnValues.Add("message", newMessage.Text);
                returnValues.Add("template", template.ToString());
                returnValues.Add("newest-id", newestId.ToString());

                core.Response.SendDictionary("replySent", returnValues);
            }
            else
            {
                SetRedirectUri(BuildUri("inbox"));
                core.Display.ShowMessage("Message sent", "Your mail message has been sent.");
            }
        }
示例#4
0
        private void SaveOrSend(bool draft)
        {
            long messageId = core.Functions.FormLong("id", 0);
            string subject = core.Http.Form["subject"];
            string text = core.Http.Form["message"];
            Dictionary<User, RecipientType> recipients = new Dictionary<User, RecipientType>();

            recipients.Add(core.Session.LoggedInMember, RecipientType.Sender);

            List<long> toRecipients = UserSelectBox.FormUsers(core, "to");
            List<long> ccRecipients = UserSelectBox.FormUsers(core, "cc");

            foreach (long id in toRecipients)
            {
                core.PrimitiveCache.LoadUserProfile(id);
            }

            foreach (long id in ccRecipients)
            {
                core.PrimitiveCache.LoadUserProfile(id);
            }

            foreach (long id in toRecipients)
            {
                if (core.PrimitiveCache[id] != null)
                {
                    recipients.Add(core.PrimitiveCache[id], RecipientType.To);
                }
            }

            foreach (long id in ccRecipients)
            {
                if (core.PrimitiveCache[id] != null)
                {
                    recipients.Add(core.PrimitiveCache[id], RecipientType.Cc);
                }
            }

            if (recipients.Count > 1)
            {
                if (messageId > 0)
                {
                    bool send = false;
                    Message message = new Message(core, messageId);
                    if (message.Draft && (!draft))
                    {
                        send = true;
                        message.Draft = draft;
                    }
                    message.Subject = subject;
                    message.Text = text;

                    /* Check recipient list */
                    List<MessageRecipient> savedRecipients = message.GetRecipients();

                    foreach (MessageRecipient r in savedRecipients)
                    {
                        bool flag = false;
                        foreach (User user in recipients.Keys)
                        {
                            if (r.UserId == user.Id && r.RecipientType == recipients[user])
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            r.Delete();
                        }
                    }

                    foreach (User user in recipients.Keys)
                    {
                        bool flag = false;
                        foreach (MessageRecipient r in savedRecipients)
                        {
                            if (r.UserId == user.Id && r.RecipientType == recipients[user])
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            message.AddRecipient(user, recipients[user]);
                        }
                    }

                    if (send)
                    {

                    }

                    message.Update();

                    SetRedirectUri(BuildUri("inbox"));
                    core.Display.ShowMessage("Message Updated", "Your mail message has been saved.");
                }
                else
                {
                    Message message = Message.Create(core, draft, subject, text, recipients);
                    if (draft)
                    {
                        SetRedirectUri(BuildUri("inbox"));
                        core.Display.ShowMessage("Message saved", "Your mail message has been saved.");
                    }
                    else
                    {
                        SetRedirectUri(BuildUri("inbox"));
                        core.Display.ShowMessage("Message sent", "Your mail message has been sent.");
                    }
                }
            }
        }
示例#5
0
        void AccountCompose_Show(object sender, EventArgs e)
        {
            SetTemplate("account_compose");

            /*List<MailFolder> folders = MailFolder.GetFolders(core, core.Session.LoggedInMember);

            foreach (MailFolder f in folders)
            {
                if (f.FolderType == FolderTypes.Inbox) continue;

                VariableCollection modulesVariableCollection = core.Template.CreateChild("account_links");
                ParentModulesVariableCollection.CreateChild("account_links", modulesVariableCollection);

                Dictionary<string, string> args = new Dictionary<string, string>();
                args.Add("folder", f.FolderName);

                switch (f.FolderType)
                {
                    case FolderTypes.Draft:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("DRAFTS"));
                        break;
                    case FolderTypes.Outbox:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("OUTBOX"));
                        break;
                    case FolderTypes.SentItems:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("SENT_ITEMS"));
                        break;
                    default:
                        modulesVariableCollection.Parse("TITLE", f.FolderName);
                        break;
                }
                modulesVariableCollection.Parse("SUB", Key);
                modulesVariableCollection.Parse("MODULE", ModuleKey);
                modulesVariableCollection.Parse("URI", BuildUri(args));
            }*/

            long messageId = core.Functions.FormLong("id", 0);
            bool edit = false;

            UserSelectBox toUserSelectBox = new UserSelectBox(core, "to");
            UserSelectBox ccUserSelectBox = new UserSelectBox(core, "cc");
            TextBox subjectTextBox = new TextBox("subject");
            TextBox messageTextBox = new TextBox("message");
            messageTextBox.IsFormatted = true;

            Message message = null;
            try
            {
                message = new Message(core, messageId);
                if (message.SenderId == core.Session.LoggedInMember.Id)
                {
                    edit = true;
                }
                else
                {
                    core.Functions.Generate403();
                }
            }
            catch (InvalidMessageException)
            {
            }

            if (edit)
            {
                subjectTextBox.Value = message.Subject;
                messageTextBox.Value = message.Text;

                List<MessageRecipient> recipients = message.GetRecipients();

                foreach (MessageRecipient recipient in recipients)
                {
                    switch (recipient.RecipientType)
                    {
                        case RecipientType.To:
                            toUserSelectBox.AddUserId(recipient.UserId);
                            break;
                        case RecipientType.Cc:
                            ccUserSelectBox.AddUserId(recipient.UserId);
                            break;
                    }
                }

                if (message.Draft)
                {
                    template.Parse("SAVE_DRAFT", "TRUE");
                }
                else
                {
                    template.Parse("SAVE_DRAFT", "FALSE");
                }
            }
            else
            {
                template.Parse("SAVE_DRAFT", "TRUE");
            }

            template.Parse("S_TO", toUserSelectBox);
            template.Parse("S_CC", ccUserSelectBox);

            template.Parse("S_SUBJECT", subjectTextBox);
            template.Parse("S_MESSAGE", messageTextBox);

            if (core.Http.Form["save"] != null)
            {
                AccountCompose_Save(this, new EventArgs());
            }

            if (core.Http.Form["send"] != null)
            {
                AccountCompose_Send(this, new EventArgs());
            }
        }
示例#6
0
        public static Message Reply(Core core, User sender, Message threadStart, string text)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            long now = UnixTime.UnixTimeStamp();

            core.Db.BeginTransaction();

            Message newItem = (Message)Item.Create(core, typeof(Message),
                   new FieldValuePair("sender_id", sender.Id),
                   new FieldValuePair("message_subject", "RE: " + threadStart.Subject),
                   new FieldValuePair("message_text", text),
                   new FieldValuePair("message_time_ut", now),
                   new FieldValuePair("message_ip", core.Session.IPAddress.ToString()),
                   new FieldValuePair("message_draft", false),
                   new FieldValuePair("message_read", false),
                   new FieldValuePair("message_thread_start_id", threadStart.Id));

            {
                UpdateQuery uQuery = new UpdateQuery(typeof(Message));
                uQuery.AddField("message_time_last_ut", now);
                uQuery.AddField("message_replies", new QueryOperation("message_replies", QueryOperations.Addition, 1));
                uQuery.AddField("message_last_id", newItem.Id);
                uQuery.AddCondition("message_id", threadStart.Id);

                core.Db.Query(uQuery);
            }

            MailFolder folder = null;
            UpdateQuery uquery = null;

            List<MessageRecipient> recipients  = threadStart.GetRecipients();

            List<long> recipientIds = new List<long>();
            foreach (MessageRecipient user in recipients)
            {
                if (user.UserId == sender.Id)
                {
                    folder = MailFolder.GetFolder(core, FolderTypes.Outbox, user);
                    MessageRecipient.Create(core, newItem, user, RecipientType.Sender, folder);
                }
                else
                {
                    folder = MailFolder.GetFolder(core, FolderTypes.Inbox, user);
                    MessageRecipient.Create(core, newItem, user, RecipientType.To, folder);
                    recipientIds.Add(user.UserId);
                }

                uquery = new UpdateQuery(typeof(MailFolder));
                uquery.AddCondition("folder_id", folder.Id);
                uquery.AddField("folder_messages", new QueryOperation("folder_messages", QueryOperations.Addition, 1));

                core.Db.Query(uquery);

            }

            if (recipientIds.Count > 0)
            {
                uquery = new UpdateQuery(typeof(UserInfo));
                uquery.AddField("user_unseen_mail", new QueryOperation("user_unseen_mail", QueryOperations.Addition, 1));
                uquery.AddCondition("user_id", ConditionEquality.In, recipientIds);

                core.Db.Query(uquery);

                // Send notifications
            }

            core.CallingApplication.QueueNotifications(core, newItem.ItemKey, "notifyMessage", Functions.TrimStringWithExtension(core.Bbcode.Flatten(text), 160));

            return newItem;
        }
示例#7
0
        public static void NotifyMessage(Core core, Job job)
        {
            Message ev = new Message(core, job.ItemId);

            List<MessageRecipient> recipients = ev.GetRecipients();

            foreach (MessageRecipient recipient in recipients)
            {
                core.LoadUserProfile(recipient.UserId);
            }

            foreach (MessageRecipient recipient in recipients)
            {
                // TODO: notify everyone via push notifications

                if (ev.SenderId == recipient.UserId)
                {
                    // don't need to notify ourselves via e-mail
                    continue;
                }

                User receiver = core.PrimitiveCache[recipient.UserId];

                if (receiver.UserInfo.EmailNotifications)
                {
                    string notificationString = string.Format("[user]{0}[/user] [iurl=\"{1}\"]" + core.Prose.GetString("_SENT_YOU_A_MESSAGE") + "[/iurl]",
                        ev.SenderId, ev.Uri);

                    Template emailTemplate = new Template(core.TemplateEmailPath, "notification.html");

                    emailTemplate.Parse("SITE_TITLE", core.Settings.SiteTitle);
                    emailTemplate.Parse("U_SITE", core.Hyperlink.StripSid(core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.BuildHomeUri())));
                    emailTemplate.Parse("TO_NAME", receiver.DisplayName);
                    core.Display.ParseBbcode(emailTemplate, "NOTIFICATION_MESSAGE", notificationString, receiver, false, string.Empty, string.Empty, true);
                    emailTemplate.Parse("NOTIFICATION_BODY", job.Body);

                    core.Email.SendEmail(receiver.UserInfo.PrimaryEmail, HttpUtility.HtmlDecode(core.Bbcode.Flatten(HttpUtility.HtmlEncode(notificationString))), emailTemplate);
                }
            }
        }
示例#8
0
        void AccountMessage_Show(object sender, EventArgs e)
        {
            SetTemplate("account_view_message");

            List<MailFolder> folders = MailFolder.GetFolders(core, core.Session.LoggedInMember);

            /*foreach (MailFolder f in folders)
            {
                if (f.FolderType == FolderTypes.Inbox) continue;

                VariableCollection modulesVariableCollection = core.Template.CreateChild("account_links");
                ParentModulesVariableCollection.CreateChild("account_links", modulesVariableCollection);

                Dictionary<string, string> args = new Dictionary<string, string>();
                args.Add("folder", f.FolderName);

                switch (f.FolderType)
                {
                    case FolderTypes.Draft:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("DRAFTS"));
                        break;
                    case FolderTypes.Outbox:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("OUTBOX"));
                        break;
                    case FolderTypes.SentItems:
                        modulesVariableCollection.Parse("TITLE", core.Prose.GetString("SENT_ITEMS"));
                        break;
                    default:
                        modulesVariableCollection.Parse("TITLE", f.FolderName);
                        break;
                }
                modulesVariableCollection.Parse("SUB", Key);
                modulesVariableCollection.Parse("MODULE", ModuleKey);
                modulesVariableCollection.Parse("URI", BuildUri("inbox", args));
            }*/

            long messageId = core.Functions.RequestLong("id", 0);

            long newestId = 0;
            try
            {
                MessageRecipient recipient = new MessageRecipient(core, core.Session.LoggedInMember, messageId);

                Message threadStart = new Message(core, messageId);

                template.Parse("S_ID", threadStart.Id.ToString());

                List<Message> messages = threadStart.GetMessages();

                if (messages.Count < 3)
                {
                    RenderMessage(core, template, threadStart);
                }

                // IF NOT DELETED THEN
                foreach (Message message in messages)
                {
                    RenderMessage(core, template, message);
                    newestId = message.Id;
                }

                threadStart.MarkRead();

                List<MessageRecipient> recipients = threadStart.GetRecipients();

                for (int i = 0; i < recipients.Count; i++)
                {
                    core.PrimitiveCache.LoadUserProfile(recipients[i].UserId);
                }

                for (int i = 0; i < recipients.Count; i++)
                {
                    VariableCollection recipientVariableCollection = template.CreateChild("recipients");

                    recipientVariableCollection.Parse("DISPLAY_NAME", core.PrimitiveCache[recipients[i].UserId].DisplayName);
                    if (core.PrimitiveCache[recipients[i].UserId].IsOnline)
                    {
                        recipientVariableCollection.Parse("IS_ONLINE", "TRUE");
                    }
                    else
                    {
                        recipientVariableCollection.Parse("IS_ONLINE", "FALSE");
                    }
                }

                template.Parse("NEWEST_ID", newestId);

            }
            catch (InvalidMessageRecipientException)
            {
                // Security, if not a recipeint, cannot see the message.
                core.Functions.Generate404();
            }
        }
示例#9
0
        void AccountMessage_Poll(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long messageId = core.Functions.RequestLong("id", 0);

            long newestId = core.Functions.RequestLong("newest-id", 0);
            try
            {
                Template template = new Template(core.CallingApplication.Assembly, "pane_message");

                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                MessageRecipient recipient = new MessageRecipient(core, core.Session.LoggedInMember, messageId);

                Message threadStart = new Message(core, messageId);

                template.Parse("S_ID", threadStart.Id.ToString());

                List<Message> messages = threadStart.GetMessages(newestId, true);

                // IF NOT DELETED THEN
                foreach (Message message in messages)
                {
                    RenderMessage(core, template, message);
                    newestId = message.Id;
                }

                threadStart.MarkRead();

                Dictionary<string, string> returnValues = new Dictionary<string, string>();

                returnValues.Add("update", "true");
                returnValues.Add("template", template.ToString());
                returnValues.Add("newest-id", newestId.ToString());

                core.Response.SendDictionary("newMessages", returnValues);

            }
            catch (InvalidMessageRecipientException)
            {
                // Security, if not a recipeint, cannot see the message.
                core.Functions.Generate404();
            }
        }
示例#10
0
        void AccountMessage_Delete(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long messageId = core.Functions.RequestLong("id", 0);

            if (messageId == 0)
            {
                core.Display.ShowMessage("Cannot Delete Message", "No message specified to delete. Please go back and try again.");
                return;
            }

            try
            {
                Message message = new Message(core, messageId);
                if (message.SenderId == core.Session.LoggedInMember.Id)
                {
                    message.Delete();
                }
                else
                {
                    message.RemoveRecipient(core.Session.LoggedInMember, RecipientType.Any);
                }

                SetRedirectUri(BuildUri("galleries", "galleries"));
                core.Display.ShowMessage("Message Deleted", "You have successfully deleted the message.");
            }
            catch
            {
                core.Display.ShowMessage("Cannot Delete Message", "An Error occured while trying to delete the message.");
                return;
            }
        }