예제 #1
0
        public bool SendEmail(MessageItem item, bool sendToSession)
        {
            //put it in the database first
            var dbitem = new DbInboxMsg()
            {
                sender_id   = item.SenderID,
                target_id   = item.TargetID,
                subject     = item.Subject,
                body        = item.Body,
                sender_name = item.SenderName,
                time        = DateTime.UtcNow,
                msg_type    = item.Type,
                msg_subtype = item.Subtype,
                read_state  = 0,
            };

            using (var da = DA.Get())
            {
                try
                {
                    var id = da.Inbox.CreateMessage(dbitem);

                    //try to tell the target they have recieved a message.
                    //if they haven't we can serve it to them next time they log in.
                    dbitem.message_id = id;
                    item.ID           = id;
                    item.Time         = dbitem.time.Ticks;

                    if (sendToSession)
                    {
                        var targetSession = Sessions.GetByAvatarId(dbitem.target_id);
                        if (targetSession != null)
                        {
                            //send them the mail directly
                            targetSession.Write(new MailResponse
                            {
                                Type     = MailResponseType.NEW_MAIL,
                                Messages = new MessageItem[] { item }
                            });
                        }
                    }

                    //it's in the database - next time the user logs in they will recieve the message if they dont have it

                    return(true);
                } catch
                {
                    return(false);
                }
            }
        }
예제 #2
0
        public MessageItem ToItem(DbInboxMsg msg)
        {
            var result = new MessageItem
            {
                ID         = msg.message_id,
                SenderID   = msg.sender_id,
                TargetID   = msg.target_id,
                Subject    = msg.subject,
                Body       = msg.body,
                SenderName = msg.sender_name,
                Time       = msg.time.Ticks,
                Type       = msg.msg_type,
                Subtype    = msg.msg_subtype,
                ReadState  = msg.read_state,
                ReplyID    = msg.reply_id
            };

            return(result);
        }