/// <summary>
        /// This method gets called when a message is received by the listener
        /// </summary>
        /// <param name="from">The user who send the message</param>
        /// <param name="data">The data of the message, includes the message text and message code</param>
        public override void OnMessageReceived(string from, Bundle data)
        {
            var message = data.GetString("message");

            int ms_code = 0;

            int.TryParse((data.GetString("message_code")), out ms_code);

            string username = data.GetString("username_from");

            //Create a new message object to be stored
            MeetMeet_Native_Portable.Droid.Message m = new MeetMeet_Native_Portable.Droid.Message();
            m.MsgText  = message;
            m.Date     = System.DateTime.Now.ToString();
            m.incoming = true;

            //Check the message code to decide what to do with the message
            if (ms_code == 1)
            {
                //This is for single messages, simply save the message and display a notification
                m.UserName = username;
                MessageRepository.SaveMessage(m);
                SendNotification(message, username);
            }
            else if (ms_code == 2)
            {
                //This is for group invites, bring up the invite screen
                Intent intent = new Intent(this, typeof(InviteRequestActivity));
                intent.PutExtra("username_from", username);
                intent.SetFlags(ActivityFlags.NewTask);
                StartActivity(intent);
            }
            else if (ms_code == 3)
            {
                //This is for group messages, save the message to the group conversation and add the sending user's name
                //to the message text. Then display a notification
                m.UserName = "******";
                m.MsgText  = username + ": " + m.MsgText;
                MessageRepository.SaveMessage(m);
                SendNotification(message, m.UserName);
            }

            //Try to add it to the inbox, if the inbox has been created.
            //Otherwise, it will get added automatically when the user opens the inbox
            ViewInbox inbox = (ViewInbox)MainActivity.references.Get("Inbox");

            if (inbox != null)
            {
                inbox.newMessage(m);
            }
        }
        /// <summary>
        /// This method gets called when a message is received by the listener
        /// </summary>
        /// <param name="from">The user who send the message</param>
        /// <param name="data">The data of the message, includes the message text and message code</param>
        public override void OnMessageReceived(string from, Bundle data)
        {
            var message = data.GetString("message");
            
			int ms_code = 0;
			int.TryParse((data.GetString ("message_code")), out ms_code);

			string username = data.GetString ("username_from");

            //Create a new message object to be stored
			MeetMeet_Native_Portable.Droid.Message m = new MeetMeet_Native_Portable.Droid.Message ();
			m.MsgText = message;
			m.Date = System.DateTime.Now.ToString();
			m.incoming = true;
			
            //Check the message code to decide what to do with the message
            if(ms_code == 1)
            {
                //This is for single messages, simply save the message and display a notification
				m.UserName = username;
				MessageRepository.SaveMessage (m);
                SendNotification(message, username);
            }
            else if(ms_code == 2)
            {
                //This is for group invites, bring up the invite screen
				Intent intent = new Intent(this, typeof(InviteRequestActivity));
				intent.PutExtra ("username_from", username);
				intent.SetFlags (ActivityFlags.NewTask);
				StartActivity(intent);
			}
            else if(ms_code == 3){
				//This is for group messages, save the message to the group conversation and add the sending user's name 
                //to the message text. Then display a notification
				m.UserName = "******";
                m.MsgText = username + ": " + m.MsgText;
				MessageRepository.SaveMessage (m);
                SendNotification(message, m.UserName);
            }

            //Try to add it to the inbox, if the inbox has been created.
            //Otherwise, it will get added automatically when the user opens the inbox
			ViewInbox inbox = (ViewInbox)MainActivity.references.Get ("Inbox");
            if(inbox != null)
            {
                inbox.newMessage (m);
            }
        }
 /// <summary>
 /// Delete the given message from the database
 /// </summary>
 /// <param name="msg">The message to delete</param>
 /// <returns></returns>
 public static int DeleteMessage(Message msg)
 {
     return me.db.DeleteMessage(msg);
 }
 /// <summary>
 /// Save the given message to the database. First check to see if the generated ID is already in the DB, 
 /// if it is, call the update method and then adds the msg.
 /// </summary>
 /// <param name="msg">The message to add</param>
 /// <returns>The id of the message</returns>
 public static int SaveMessage(Message msg)
 {
     return me.db.SaveMessage(msg);
 }
Example #5
0
        /// <summary>
        /// Delete the given message from the database
        /// </summary>
        /// <param name="msg">The message to delete</param>
        /// <returns></returns>
		public int DeleteMessage(Message msg) 
		{
			lock (locker) {
				return Delete<Message> (msg.Id);
			}
		}
Example #6
0
        /// <summary>
        /// Save the given message to the database. First check to see if the generated ID is already in the DB, 
        /// if it is, call the update method and then adds the msg.
        /// </summary>
        /// <param name="msg">The message to add</param>
        /// <returns>The id of the message</returns>
        public int SaveMessage (Message msg) 
		{
			lock (locker) {
				if (msg.Id != 0) {
					Update (msg);
					return msg.Id;
				} else {
					return Insert (msg);
				}
			}
		}