Exemple #1
0
        public void InitializeMessages(int zchatsession, string connectionString, string searchString = "")
        {
            SQLiteConnection connection = new SQLiteConnection(connectionString);
            string queryString = "select z_pk from zwamessage where zchatsession = " + zchatsession.ToString() + " order by zmessagedate asc";
            if (searchString != "")
            {
                //search performed!

                // hopefully nobody tries anything funny here
                queryString = "select z_pk from zwamessage where ztext like \"" + searchString+ "\" order by zmessagedate asc";
            }
            SQLiteCommand command = new SQLiteCommand(queryString, connection);

            lvMessageView.Items.Clear();

            try
            {
                connection.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    WAMessage currentMessage = new WAMessage(Convert.ToInt32(reader[0]), connectionString);

                    WAGroupMember messageOwner = new WAGroupMember(currentMessage.ZGROUPMEMBER, connectionString);

                    ListViewItem currentListViewItem;

                    if (currentMessage.ZISFROMME == 1)
                    {
                        currentListViewItem = new ListViewItem("WhatsApp Owner");
                    }
                    else
                    {
                        string messageOwnerName = "";

                        // appending again somehow fixes the blank string problem
                        messageOwnerName += messageOwner.ZCONTACTNAME;

                        //if (messageOwnerName.Length == 0 && IsGroupMessage == false)
                        //{
                        //    //messageOwnerName = "Hello";
                        //}

                        //hackish but works
                        bool isNotOwner = true;
                        if (messageOwnerName.Length == 0)
                        {
                            messageOwnerName = this.Text;
                            isNotOwner = true;
                        }
                        currentListViewItem = new ListViewItem(messageOwnerName);

                        //really wtf?
                        if (isNotOwner)
                        {
                            currentListViewItem.BackColor = Color.Wheat;
                        }

                    }

                    currentListViewItem.SubItems.Add(currentMessage.ZTEXT);
                    currentListViewItem.SubItems.Add(MiscHelper.HandleWeirdEpochAddTimezoneInformation(currentMessage.ZMESSAGEDATE));

                    string eventType = "";
                    if (currentMessage.Z_GROUPEVENTTYPE == 0)
                    {
                        eventType = "Message";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 1)
                    {
                        eventType = "Group Creation";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 2)
                    {
                        eventType = "Joined Group";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 3)
                    {
                        eventType = "Left Group";
                    }
                    else
                    {
                        eventType = "Unknown (" + currentMessage.Z_GROUPEVENTTYPE.ToString() + ")";
                    }

                    currentListViewItem.SubItems.Add(eventType);

                    lvMessageView.Items.Add(currentListViewItem);

                }
                reader.Close();

            }
            catch (Exception ex)
            {
                // oh no
            }
        }
Exemple #2
0
        public void InitializeMessages(int zchatsession, string connectionString, string searchString = "")
        {
            SQLiteConnection connection  = new SQLiteConnection(connectionString);
            string           queryString = "select z_pk from zwamessage where zchatsession = " + zchatsession.ToString() + " order by zmessagedate asc";

            if (searchString != "")
            {
                //search performed!

                // hopefully nobody tries anything funny here
                queryString = "select z_pk from zwamessage where ztext like \"" + searchString + "\" order by zmessagedate asc";
            }
            SQLiteCommand command = new SQLiteCommand(queryString, connection);

            lvMessageView.Items.Clear();

            try
            {
                connection.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    WAMessage currentMessage = new WAMessage(Convert.ToInt32(reader[0]), connectionString);

                    WAGroupMember messageOwner = new WAGroupMember(currentMessage.ZGROUPMEMBER, connectionString);

                    ListViewItem currentListViewItem;

                    if (currentMessage.ZISFROMME == 1)
                    {
                        currentListViewItem = new ListViewItem("WhatsApp Owner");
                    }
                    else
                    {
                        string messageOwnerName = "";



                        // appending again somehow fixes the blank string problem
                        messageOwnerName += messageOwner.ZCONTACTNAME;

                        //if (messageOwnerName.Length == 0 && IsGroupMessage == false)
                        //{
                        //    //messageOwnerName = "Hello";
                        //}

                        //hackish but works
                        bool isNotOwner = true;
                        if (messageOwnerName.Length == 0)
                        {
                            messageOwnerName = this.Text;
                            isNotOwner       = true;
                        }
                        currentListViewItem = new ListViewItem(messageOwnerName);

                        //really wtf?
                        if (isNotOwner)
                        {
                            currentListViewItem.BackColor = Color.Wheat;
                        }
                    }


                    currentListViewItem.SubItems.Add(currentMessage.ZTEXT);
                    currentListViewItem.SubItems.Add(MiscHelper.HandleWeirdEpochAddTimezoneInformation(currentMessage.ZMESSAGEDATE));

                    string eventType = "";
                    if (currentMessage.Z_GROUPEVENTTYPE == 0)
                    {
                        eventType = "Message";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 1)
                    {
                        eventType = "Group Creation";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 2)
                    {
                        eventType = "Joined Group";
                    }
                    else if (currentMessage.Z_GROUPEVENTTYPE == 3)
                    {
                        eventType = "Left Group";
                    }
                    else
                    {
                        eventType = "Unknown (" + currentMessage.Z_GROUPEVENTTYPE.ToString() + ")";
                    }

                    currentListViewItem.SubItems.Add(eventType);

                    lvMessageView.Items.Add(currentListViewItem);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                // oh no
            }
        }