Exemple #1
0
        public List<Message> RecentMessages(int roomId, int sinceMessageId, Message.MType messageTypes)
        {
            // GET /room/#{id}/recent.xml
            string cmd = string.Format("/room/{0}/recent.xml", roomId);
            if (sinceMessageId > 0)
            {
                cmd = string.Format("{0}?since_message_id={1}", cmd, sinceMessageId);
            }

            XDocument xdoc = requestor.Doit(cmd);

            // get all the messages
            var messages = from elem in xdoc.Descendants() where elem.Name == "message" select new Message(elem);

            // now filter out ones NOT matching 'messageTypes'
            messages = from msg in messages where ((msg.Type & messageTypes) != 0) select msg;

            List<Message> msgs = messages.ToList();

            return msgs;
        }
Exemple #2
0
 public static void TraceErrorMessage(Message msg, string extraText)
 {
     TraceMessage(TraceLevel.Error, msg, extraText);
 }
Exemple #3
0
 public static void TraceWarningMessage(Message msg, string extraText)
 {
     TraceMessage(TraceLevel.Warning, msg, extraText);
 }
Exemple #4
0
 public static void TraceInfoMessage(Message msg, string extraText)
 {
     TraceMessage(TraceLevel.Info, msg, extraText);
 }
Exemple #5
0
 public static void TraceVerboseMessage(Message msg, string extraText)
 {
     TraceMessage(TraceLevel.Verbose, msg, extraText);
 }
Exemple #6
0
        public static void TraceMessage(TraceLevel level, Message msg, string extraText)
        {
            CampfireState campState = CampfireState.Instance;
            IList<CampfireState.UserInfo> allUsers = campState.Users;

            CampfireState.UserInfo user = allUsers.FirstOrDefault(u => u.Id == msg.UserId);
            string userName = (user != null) ? user.NickName : msg.UserId.ToString();

            CampfireState.RoomInfo room = campState.Rooms.FirstOrDefault(r => r.Id == msg.RoomId);
            string roomName = (room != null) ? room.Name : msg.RoomId.ToString();

            TraceMessage(level, string.Format("At: {0}, User: {1}, Room: {2}, {3}{4}{5}",
                msg.PostedAt.ToString(), userName, roomName,
                (extraText ?? ""), (!string.IsNullOrEmpty(extraText)) ? ": " : "", msg.TrimmedBody));
        }
 /// <summary>
 /// (Thread safe) add a new Text/Paste/Enter message into a queue, the queue of waiting to be processed messages
 /// </summary>
 /// <param name="msg"></param>
 public void QueueMessage(Message msg)
 {
     lock (this.MessageQueue)
     {
         this.MessageQueue.Enqueue(msg);
     }
 }
 private static void ProcessEnterMessage(CampfireState campfireInfo, Message msg, ICampfireAPI api)
 {
     // remove any pending notifications for this user in the room in which this Enter message appeared
     campfireInfo.RemovePendingNotification(msg.UserId, msg.RoomId, msg.PostedAt, true);
 }
        private static void ProcessTextMessage(CampfireState campfireInfo, Message msg, ICampfireAPI api)
        {
            // The person that posted this message... If they have a pending notification in the room... then cancel it... they've spoken
            campfireInfo.RemovePendingNotification(msg.UserId, msg.RoomId, msg.PostedAt, true);

            IList<CampfireState.UserInfo> allUsers = campfireInfo.Users;

            IList<CampfireState.UserReference> lazyNotificationUsers;
            IList<CampfireState.UserReference> immediateNotificationUsers;
            IList<CampfireState.UserReference> smokeSignalReferences;
            Utils.FindUserReferences(msg.Body, allUsers, out lazyNotificationUsers, out immediateNotificationUsers, out smokeSignalReferences);

            CampfireState.UserInfo source = allUsers.FirstOrDefault(u => u.Id == msg.UserId);
            CampfireState.RoomInfo room = CampfireState.Instance.Rooms.FirstOrDefault(r => r.Id == msg.RoomId);

            // special smoke signal commands only make sense if a legitimate user issued them
            if (source != null)
            {
                foreach (CampfireState.UserReference ri in smokeSignalReferences)
                {
                    ri.SourceUser = source;
                    ri.Room = room;
                    ProcessSmokeSignalCommands(source.Id, ri);
                }
            }

            foreach (CampfireState.UserReference ri in immediateNotificationUsers)
            {
                ri.SourceUser = source;
                ri.Room = room;
                campfireInfo.AddPendingNotification(ri, msg.PostedAt.AddSeconds(0));
            }
            foreach (CampfireState.UserReference ri in lazyNotificationUsers)
            {
                ri.SourceUser = source;
                ri.Room = room;

                int delay = ri.TargetUser.DelayInMinutes > 0 ? ri.TargetUser.DelayInMinutes : SmokeSignalConfig.Instance.DelayBeforeSmokeSignalInMinutes;
                campfireInfo.AddPendingNotification(ri, msg.PostedAt.AddSeconds(delay * 60));
            }
        }
        private static void CheckForUnknownUserOrRoom(CampfireState campfireInfo, Message msg, ICampfireAPI api)
        {
            // If this userId isn't already known...
            if (!campfireInfo.IsUserKnown(msg.UserId))
            {
                // fetch all the user Info and then add
                User newUser = api.GetUser(msg.UserId);
                if ((newUser != null) && (newUser.Type == User.UserType.Member) && !string.IsNullOrEmpty(newUser.Name) && !string.IsNullOrEmpty(newUser.Email))
                {
                    Utils.TraceVerboseMessage(string.Format("Found a new User: {0}, Id: {1}", newUser.Name, newUser.Id));
                    campfireInfo.AddUser(newUser.Id, newUser.Name, newUser.Email, string.Empty);
                }
            }

            // If this roomId isn't already known...
            if (!campfireInfo.IsRoomKnown(msg.RoomId))
            {
                // fetch all the user Info and then add
                Room newRoom = api.GetRoom(msg.RoomId);
                if (newRoom != null)
                {
                    Utils.TraceVerboseMessage(string.Format("Found a new Room: {0}, Id: {1}", newRoom.Name, newRoom.Id));
                    campfireInfo.AddRoom(newRoom.Id, newRoom.Name, 0);
                }
            }
        }
 private static void QueueMessage(CampfireState campfireInfo, Message msg)
 {
     if (msg.Type == Message.MType.TextMessage)
     {
         // only process messages posted within the last 1 hour
         if (msg.PostedAt >= DateTime.Now.AddHours(-1))
         {
             // put msg into the Text Queue
             Utils.TraceVerboseMessage(msg, "Msg");
             campfireInfo.QueueMessage(msg);
         }
     }
     else if (msg.Type == Message.MType.EnterMessage)
     {
         // put msg into the Enter Queue
         Utils.TraceVerboseMessage(msg, "Enter");
         campfireInfo.QueueMessage(msg);
     }
 }
Exemple #12
0
 public List<Message> RecentMessages(int roomId, Message.MType messageTypes)
 {
     return RecentMessages(roomId, 0, messageTypes);
 }