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();
        }
Exemple #2
0
        public static MailFolder GetFolder(Core core, FolderTypes folder, MessageRecipient user)
        {
            SelectQuery query = MailFolder.GetSelectQueryStub(core, typeof(MailFolder));
            query.AddCondition("folder_type", (byte)folder);
            query.AddCondition("owner_id", user.UserId);

            System.Data.Common.DbDataReader inboxReader = core.Db.ReaderQuery(query);

            if (inboxReader.HasRows)
            {
                inboxReader.Read();

                MailFolder newFolder = new MailFolder(core, inboxReader);

                inboxReader.Close();
                inboxReader.Dispose();

                return newFolder;
            }
            else
            {
                inboxReader.Close();
                inboxReader.Dispose();

                throw new InvalidMailFolderException();
            }
        }
        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));
        }
        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.");
            }
        }
        void AccountMailInbox_Show(object sender, EventArgs e)
        {
            SetTemplate("account_mailbox");

            if (LoggedInMember.UserInfo.UnseenMail > 0)
            {
                UpdateQuery query = new UpdateQuery(typeof(UserInfo));
                query.AddField("user_unseen_mail", new QueryOperation("user_unseen_mail", QueryOperations.Subtraction, LoggedInMember.UserInfo.UnseenMail));
                query.AddCondition("user_id", LoggedInMember.Id);

                db.Query(query);

                core.Template.Parse("UNSEEN_MAIL", "FALSE");
            }

            /*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));
            }*/

            string folder = "Inbox";
            if (!string.IsNullOrEmpty(core.Http.Query["folder"]))
            {
                folder = core.Http.Query["folder"];
            }

            MailFolder mailFolder = null;
            try
            {
                mailFolder = new MailFolder(core, core.Session.LoggedInMember, folder);
            }
            catch (InvalidMailFolderException)
            {
                if (folder == "Inbox")
                {
                    mailFolder = MailFolder.Create(core, FolderTypes.Inbox, folder);
                    MailFolder.Create(core, FolderTypes.Draft, core.Prose.GetString("DRAFTS"));
                    MailFolder.Create(core, FolderTypes.Outbox, core.Prose.GetString("OUTBOX"));
                    MailFolder.Create(core, FolderTypes.SentItems, core.Prose.GetString("SENT_ITEMS"));
                }
                else
                {
                    core.Functions.Generate404();
                    return;
                }
            }

            List<Message> messages = mailFolder.GetThreads(core.TopLevelPageNumber, 20);

            List<long> messageIds = new List<long>();
            List<long> lastMessageIds = new List<long>();
            Dictionary<long, MessageRecipient> readStatus = new Dictionary<long, MessageRecipient>();

            if (messages.Count > 0)
            {
                foreach (Message message in messages)
                {
                    messageIds.Add(message.Id);
                    if (message.LastId > 0)
                    {
                        lastMessageIds.Add(message.LastId);
                    }
                    else
                    {
                        lastMessageIds.Add(message.Id);
                    }
                }

                SelectQuery query = MessageRecipient.GetSelectQueryStub(core, typeof(MessageRecipient));
                query.AddCondition("user_id", core.Session.LoggedInMember.Id);
                query.AddCondition("message_id", ConditionEquality.In, lastMessageIds);

                System.Data.Common.DbDataReader recipientReader = db.ReaderQuery(query);

                while(recipientReader.Read())
                {
                    MessageRecipient recipient = new MessageRecipient(core, recipientReader);
                    readStatus.Add(recipient.MessageId, recipient);
                }

                recipientReader.Close();
                recipientReader.Dispose();
            }

            foreach (Message message in messages)
            {
                VariableCollection messageVariableCollection = template.CreateChild("mail_item");

                bool isRead = false;

                long lastId = message.LastId;
                if (lastId == 0)
                {
                    lastId = message.Id;
                }

                if (readStatus.ContainsKey(lastId))
                {
                    if (readStatus[lastId].IsRead)
                    {
                        isRead = true;
                    }
                }

                if (isRead)
                {
                    messageVariableCollection.Parse("IS_NORMAL_READ", "TRUE");
                }
                else
                {
                    messageVariableCollection.Parse("IS_NORMAL_UNREAD", "TRUE");
                }

                messageVariableCollection.Parse("SUBJECT", message.Subject);
                messageVariableCollection.Parse("URI", message.Uri);
                messageVariableCollection.Parse("U_DELETE", BuildUri("message", "delete", message.Id));

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

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

                switch (mailFolder.FolderType)
                {
                    case FolderTypes.Inbox:
                    case FolderTypes.Custom:
                        // INBOX show sender
                        if (message.SenderId > 0)
                        {
                            messageVariableCollection.Parse("SENDER", message.Sender.DisplayName);
                            messageVariableCollection.Parse("U_SENDER", message.Sender.Uri);
                        }
                        for (int i = 0; i < recipients.Count; i++)
                        {
                            if (recipients[i].UserId != LoggedInMember.Id)
                            {
                                VariableCollection recipientVariableCollection = messageVariableCollection.CreateChild("recipients");

                                recipientVariableCollection.Parse("DISPLAY_NAME", core.PrimitiveCache[recipients[i].UserId].DisplayName);
                            }
                        }

                        template.Parse("INBOX", "TRUE");
                        break;
                    case FolderTypes.Draft:
                    case FolderTypes.Outbox:
                    case FolderTypes.SentItems:
                        {
                            int i = 0;
                            while (recipients.Count > i)
                            {
                                if (recipients[i].RecipientType == RecipientType.To)
                                {
                                    messageVariableCollection.Parse("SENDER", core.PrimitiveCache[recipients[i].UserId].DisplayName);
                                    messageVariableCollection.Parse("U_SENDER", core.PrimitiveCache[recipients[i].UserId].Uri);
                                    break;
                                }
                                i++;
                            }
                        }
                        break;
                }
                messageVariableCollection.Parse("DATE", core.Tz.DateTimeToString(message.GetSentDate(core.Tz)));
                messageVariableCollection.Parse("LAST_DATE", core.Tz.DateTimeToString(message.GetLastMessageDate(core.Tz)));
            }

            Dictionary<string, string> a = new Dictionary<string,string>();
            a.Add("folder", mailFolder.FolderName);

            core.Display.ParsePagination(template, BuildUri(a), 20, mailFolder.MessageCount);
        }
        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();
            }
        }
        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();
            }
        }