public VerseMessageParticipant addParticipantToThread(VerseMessageThread vmt, long participant_id, DateTime datetime_joined, DateTime datetime_last_read)
 {
     VerseMessageParticipant vmp = new VerseMessageParticipant(-1, vmt.thread_id, participant_id, datetime_joined, datetime_last_read);
     ParticipantTask pt = new ParticipantTask(us, vmp);
     //TODO change this not to be done in thread.
     pt.AddParticipantToThread();
     VerseThreadManager.getInstance().addParticipant(vmt, vmp);
     return vmp;
 }
 public VerseMessageParticipant addNewParticipantToThread(VerseMessageThread vmt, long participant_id)
 {
     DateTime datetime = DateTime.Now;
     VerseMessageParticipant vmp = new VerseMessageParticipant(-1,vmt.thread_id,participant_id,datetime,DateTime.MinValue);
     ParticipantTask pt = new ParticipantTask(us, vmp);
     pt.AddParticipantToThread();
     VerseThreadManager.getInstance().addParticipant(vmt,vmp);
     return vmp;
 }
 public MessageThreadMenuOptionItem(
     string menu_option_id,
     string link_val,
     string select_action,
     string display_text,
     VerseMessageThread vmt)
     : base(menu_option_id, link_val, select_action, display_text)
 {
     this.vmt = vmt;
 }
        public int addMessageToThread(VerseMessageThread vmt, String message_text)
        {
            DateTime datetime = DateTime.Now;
            VerseMessage vm = new VerseMessage(-1, vmt.thread_id, datetime, message_text, us.user_profile.id);
            //dont do this in a seperate thread now, because we need to know if it's succesful.
            int code = AddMessageToThreadDB(message_text,datetime,vmt,vm);
            if(code == MESSAGE_SENT_CODE_SUCCESSFUL)
            {
                //this is a little messy. we should be consistent in the way we update memory and db.

                vmt.addMessage(vm);

                updateThreadLastModifiedTime(vmt, vm);
                VerseMessageParticipant vmp = vmt.getParticipant(us.user_profile.id);
                updateParticipantThreadLastAccessedTime (vmp);

                return MESSAGE_SENT_CODE_SUCCESSFUL;
            }
            else
            {
                return MESSAGE_SENT_CODE_ERROR;
            }
        }
        public VerseMessageThread createThreadAndAddPrivateMessage(String message_text, long recip_id, String start_verse, String end_verse, String subject)
        {
            DateTime datetime = DateTime.Now;
            VerseMessageThread vmt = new VerseMessageThread(
                -1,
                start_verse,
                end_verse,
                Int32.Parse(us.user_profile.getDefaultTranslationId()),
                subject,
                datetime,
                datetime,
                us.user_profile.id,
                VerseMessageThread.THREAD_STATE_ACTIVE);
            //create thread
            int code = AddThreadToDB(vmt);

            if (code == THREAD_CREATED_CODE_SUCCESSFUL)
            {
                code = addMessageToThread(vmt, message_text); // TODO check result
                if (code == MESSAGE_SENT_CODE_SUCCESSFUL)
                {
                    addParticipantToThread(vmt,us.user_profile.id, datetime, datetime.AddSeconds(1));
                    addNewParticipantToThread(vmt, recip_id);
                    VerseThreadManager.getInstance().addThread(vmt);
                    //TODO.complete jere.
                }
                else
                {
                    //TODO: Roll back THREAD
                }
            }
            return vmt;
        }
        private int AddMessageToThreadDB(String message_text, DateTime datetime_sent, VerseMessageThread vmt, VerseMessage vm)
        {
            MySqlConnection conn = DBManager.getConnection();
            try
            {
                conn.Open();
                //later on we will do db updates in seperate thread.
                string sqlQuery =
                    "INSERT INTO versemessages VALUES (NULL, " + vmt.thread_id + ",'" + datetime_sent.ToString("yyyy-MM-dd HH:mm:ss") + "',@message_text," + us.user_profile.id + ")";
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                cmd.Parameters.Add("@message_text", MySql.Data.MySqlClient.MySqlDbType.Text);
                cmd.Parameters["@message_text"].Value = message_text;

                int output = cmd.ExecuteNonQuery();
                long row_id = cmd.LastInsertedId;
                vm.message_id = row_id; //TODO: Check if this actually works.
                return MESSAGE_SENT_CODE_SUCCESSFUL;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return MESSAGE_SENT_CODE_ERROR;
            }
            finally
            {
                conn.Close();
            }
        }
        private int AddThreadToDB(VerseMessageThread vmt)
        {
            MySqlConnection conn = DBManager.getConnection();
             try
             {
                 conn.Open();
                 //later on we will do db updates in seperate thread.
                 string sqlQuery =
                     "INSERT INTO versemessagethreads VALUES (NULL, '" +
                                                vmt.start_verse + "','" +
                                                vmt.end_verse + "','" +
                                                vmt.translation + "','" +
                                                vmt.subject+ "','" +
                                                vmt.datetime_created.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
                                                vmt.datetime_last_modified.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
                                                us.user_profile.id + "','" +
                                                /*vmt.is_private + "','" +*/
                                                vmt.thread_state+ "')";

                 MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);

                 int output = cmd.ExecuteNonQuery();
                 long row_id = cmd.LastInsertedId;
                 vmt.thread_id = row_id; //TODO: Check if this actually works.
                 return THREAD_CREATED_CODE_SUCCESSFUL;
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return THREAD_CREATED_CODE_ERROR;
             }
             finally
             {
                 conn.Close();
             }
        }
 public void removeParticipantFromThread(VerseMessageThread vmt)
 {
     long user_id = us.user_profile.id;
     if (vmt.getParticipant(user_id) != null)
     {
         VerseMessageParticipant vmp = vmt.getParticipant(user_id);
         ParticipantTask pt = new ParticipantTask(us, vmp);
         //TODO change this not to be done in thread.
         pt.RemoveParticipantFromThread();
         VerseThreadManager.getInstance().removeParticipant(vmt, vmp);
     }
 }
 public void updateThreadLastModifiedTime(VerseMessageThread vmt, VerseMessage vm)
 {
     if (vmt != null)
      {
          DateTime datetime = DateTime.Now;
          vmt.datetime_last_modified = datetime;
          MessageTask mt = new MessageTask(us, vm);
          mt.UpdateLastAccessedTime();
      }
 }
Example #10
0
        static VerseThreadManager()
        {
            string sqlQuery = "SELECT thread_id, verse_start, verse_end, translation, subject, datetime_created, datetime_last_modified, user_id_created, state  FROM versemessagethreads";
            MySqlConnection conn = DBManager.getConnection();
            MySqlDataReader rdr = null;
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                rdr = cmd.ExecuteReader();
                long thread_id = -1;
                String start_verse = "";
                String end_verse = "";
                int translation = -1;
                String subject = "";
                DateTime datetime_created;
                DateTime datetime_last_modified;
                VerseMessageThread tmp_vmt = null;
                long user_created_id = -1;
                /*Boolean is_private = true;*/
                int state = -1;
                while (rdr.Read())
                {
                    thread_id = long.Parse((rdr[0]).ToString());
                    start_verse = (rdr[1]).ToString();
                    end_verse = (rdr[2]).ToString();
                    translation = Int32.Parse((rdr[3]).ToString());
                    subject = (rdr[4]).ToString();
                    datetime_created = DateTime.Parse(rdr[5].ToString());
                    datetime_last_modified = DateTime.Parse(rdr[6].ToString());

                    user_created_id = long.Parse(rdr[7].ToString());
                    //is_private = Boolean.Parse(rdr[6].ToString());
                    state = Int32.Parse(rdr[8].ToString());

                    tmp_vmt = new VerseMessageThread(
                        thread_id,
                        start_verse,
                        end_verse,
                        translation,
                        subject,
                        datetime_created,
                        datetime_last_modified,
                        user_created_id,
                        /*is_private,*/
                        state);
                    threads.Add(thread_id, tmp_vmt);
                }
                rdr.Close();
                conn.Close();

                sqlQuery = "SELECT user_id, thread_id FROM versemsgparticipants";
                conn = DBManager.getConnection();
                rdr = null;
                conn.Open();
                cmd = new MySqlCommand(sqlQuery, conn);
                rdr = cmd.ExecuteReader();
                long t_id = -1;
                long u_id = -1;
                List<long> list;
                while (rdr.Read())
                {
                    u_id = long.Parse((rdr[0]).ToString());
                    t_id = long.Parse((rdr[1]).ToString());
                    if (users_threads.ContainsKey(u_id))
                    {
                        list = users_threads[u_id];
                    }
                    else
                    {
                        list = new List<long>();
                        users_threads.Add(u_id, list);
                    }
                    list.Add(t_id);
                }
                rdr.Close();
                conn.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (rdr != null)
                    rdr.Close();
                conn.Close();
            }
        }
Example #11
0
 public void removeParticipant(VerseMessageThread vmt, VerseMessageParticipant vmp)
 {
     if (vmp != null && vmt != null)
     {
         long u_id = vmp.user_id;
         if (users_threads.ContainsKey(u_id))
         {
             if (users_threads[u_id].Contains(vmp.thread_id))
             {
                 users_threads[u_id].Remove(vmp.thread_id);
             }
         }
         vmt.removeParticipant(vmp);
     }
 }
Example #12
0
 public void addThread(VerseMessageThread vmt)
 {
     threads.Add(vmt.thread_id,vmt);
 }
Example #13
0
 public void addParticipant(VerseMessageThread vmt, VerseMessageParticipant vmp)
 {
     if (vmp != null && vmt!= null)
     {
         long u_id = vmp.user_id;
         if (users_threads.ContainsKey(u_id))
         {
             if (!users_threads[u_id].Contains(vmp.thread_id))
             {
                 users_threads[u_id].Add(vmp.thread_id);
             }
         }
         else
         {
             List<long> list = new List<long>();
             users_threads.Add(u_id, list);
             list.Add(vmp.thread_id);
         }
         vmt.addParticipant(vmp);
     }
 }
        protected void appendMessageThread(
            UserSession us,
            MessageToSend ms,
            VerseMessageThread vmt)
        {
            Boolean is_new = false;
            String verse_ref = "";
            String message;
            List<VerseMessage> messages = vmt.getMessages();
            VerseMessage first_vm = messages.First();
            VerseMessage last_vm = messages.Last();

            ms.AppendLine("");
            ms.Append(createMessageLink(MENU_LINK_NAME, "*", MessageInboxHandler.OPEN_THREAD + vmt.thread_id));
            //determine if there is a new message in this thread by comparing last updated and read dates.
            ms.Append(" ");

            DateTime last_mod_date = vmt.datetime_last_modified;
            VerseMessageParticipant vmp = vmt.getParticipant(us.user_profile.id);

            DateTime last_acc_date = DateTime.MaxValue;
            if (vmp != null)
                last_acc_date = vmp.datetime_last_read;
            is_new = last_mod_date > last_acc_date;
            String subject = vmt.subject;
            ms.Append("From: ");
            if (first_vm.sender_id == us.user_profile.id)
            {
                ms.AppendLine("You ", TextMarkup.Bold);
            }
            else
            {
                ms.AppendLine(" " + UserNameManager.getInstance().getUserName(first_vm.sender_id), TextMarkup.Bold);
            }

            ms.Append("To: ");
            List<VerseMessageParticipant> parts = vmt.getListOfParticipants();
            String receivers = getRecieverString(us, parts,first_vm.sender_id);

            ms.AppendLine(receivers, TextMarkup.Bold);

            if (!VerseMessageThread.NOTIFICATION_THREAD.Equals(vmt.start_verse))
            {
                verse_ref = BibleHelper.getVerseSectionReference(us, vmt.start_verse, vmt.end_verse);
                ms.AppendLine("Verse: " + verse_ref);
            }
            if (!(subject == null || subject.Equals("") || subject.Equals("NULL")))
            {
                ms.AppendLine("Subject: '" + subject + "'");
                //ms.Append();
                //ms.AppendLine("'");
            }
            message = last_vm.message_text;
            if(!(message== null || message.Equals("") || message.Equals("NULL")))
                ms.AppendLine("Newest Message: " + StringUtils.getTextSummary(message, 4) + "...'  ("+messages.Count+" messages)");

            //ms.AppendLine("");
            if (last_vm != null)
            {
                ms.Append("Last Updated by ");
                if (last_vm.sender_id == us.user_profile.id)
                {
                    ms.Append("You (");
                }
                else
                {
                    ms.Append(UserNameManager.getInstance().getUserName(last_vm.sender_id) + " (");
                }
                if (is_new)
                {
                    ms.Append(DateUtils.RelativeDate(last_mod_date),TextMarkup.Bold);
                    ms.AppendLine(")");
                }
                else
                {
                    ms.AppendLine(DateUtils.RelativeDate(last_mod_date) + ")");
                }
            }

            ms.Append(createMessageLink(MENU_LINK_NAME, "[DELETE]", MessageInboxHandler.DELETE_THREAD + vmt.thread_id));
            ms.AppendLine(" ");
            ms.Append("\r\n");
        }