// Path: lib/src/main/java/io/xpush/chat/persist/MessageTable.java
// public class MessageTable {
// 
//     public static final String KEY_ROWID = "_id";
//     public static final String KEY_ID = "id";
//     public static final String KEY_CHANNEL = "channel";
//     public static final String KEY_SENDER = "sender";
//     public static final String KEY_IMAGE = "image";
//     public static final String KEY_COUNT = "count";
//     public static final String KEY_MESSAGE = "message";
//     public static final String KEY_TYPE = "type";
//     public static final String KEY_METADATA = "metadata";
//     public static final String KEY_UPDATED = "received";
//     public static String SQLITE_TABLE;
// 
//     public static final String[] ALL_PROJECTION = {
//         MessageTable.KEY_CHANNEL,
//         MessageTable.KEY_ID,
//         MessageTable.KEY_SENDER ,
//         MessageTable.KEY_IMAGE ,
//         MessageTable.KEY_COUNT ,
//         MessageTable.KEY_MESSAGE ,
//         MessageTable.KEY_TYPE ,
//         MessageTable.KEY_METADATA ,
//         MessageTable.KEY_UPDATED };
// 
//     public static void onCreate(SQLiteDatabase db, String tableName) {
//         SQLITE_TABLE = tableName;
// 
//         db.execSQL("DROP TABLE IF EXISTS " + tableName);
// 
//         String DATABASE_CREATE =
//                 "CREATE TABLE if not exists " + tableName + " (" +
//                         KEY_ROWID + " integer PRIMARY KEY autoincrement," +
//                         KEY_CHANNEL + ", " +
//                         KEY_ID + "," +
//                         KEY_SENDER + "," +
//                         KEY_IMAGE + "," +
//                         KEY_COUNT + " integer ," +
//                         KEY_MESSAGE + "," +
//                         KEY_TYPE + " integer , " +
//                         KEY_METADATA + " ,"+
//                         KEY_UPDATED + " integer );";
// 
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion, String tableName) {
//         SQLITE_TABLE = tableName;
// 
//         db.execSQL("DROP TABLE IF EXISTS " + tableName);
//         onCreate(db, tableName);
//     }
// }


import android.database.Cursor;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import io.xpush.chat.persist.MessageTable;
                    this.type = TYPE_IMAGE;
                }
            }

            // Message Metadata
            if( data.has("MD") ){
                this.metadata = data.getJSONObject("MD");
            }

            this.channel = data.getString("C");

            if( data.has("US") ){
                String usersStr = data.getString("US");
                this.users = new ArrayList<String>(Arrays.asList(usersStr.split("@!@")));
            }  else if( this.channel != null && this.channel.indexOf("@!@") > -1 && this.channel.lastIndexOf("^") > 0 ){
                String usersStr = this.channel.substring( 0, this.channel.lastIndexOf("^") );
                this.users = new ArrayList<String>(Arrays.asList(usersStr.split("@!@")));
            }

            this.message = URLDecoder.decode( data.getString("MG"), "UTF-8");
            this.updated = data.getLong("TS");

            this.id = channel +"_" + updated;

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public XPushMessage(Cursor cursor){
// Path: lib/src/main/java/io/xpush/chat/persist/MessageTable.java
// public class MessageTable {
// 
//     public static final String KEY_ROWID = "_id";
//     public static final String KEY_ID = "id";
//     public static final String KEY_CHANNEL = "channel";
//     public static final String KEY_SENDER = "sender";
//     public static final String KEY_IMAGE = "image";
//     public static final String KEY_COUNT = "count";
//     public static final String KEY_MESSAGE = "message";
//     public static final String KEY_TYPE = "type";
//     public static final String KEY_METADATA = "metadata";
//     public static final String KEY_UPDATED = "received";
//     public static String SQLITE_TABLE;
// 
//     public static final String[] ALL_PROJECTION = {
//         MessageTable.KEY_CHANNEL,
//         MessageTable.KEY_ID,
//         MessageTable.KEY_SENDER ,
//         MessageTable.KEY_IMAGE ,
//         MessageTable.KEY_COUNT ,
//         MessageTable.KEY_MESSAGE ,
//         MessageTable.KEY_TYPE ,
//         MessageTable.KEY_METADATA ,
//         MessageTable.KEY_UPDATED };
// 
//     public static void onCreate(SQLiteDatabase db, String tableName) {
//         SQLITE_TABLE = tableName;
// 
//         db.execSQL("DROP TABLE IF EXISTS " + tableName);
// 
//         String DATABASE_CREATE =
//                 "CREATE TABLE if not exists " + tableName + " (" +
//                         KEY_ROWID + " integer PRIMARY KEY autoincrement," +
//                         KEY_CHANNEL + ", " +
//                         KEY_ID + "," +
//                         KEY_SENDER + "," +
//                         KEY_IMAGE + "," +
//                         KEY_COUNT + " integer ," +
//                         KEY_MESSAGE + "," +
//                         KEY_TYPE + " integer , " +
//                         KEY_METADATA + " ,"+
//                         KEY_UPDATED + " integer );";
// 
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion, String tableName) {
//         SQLITE_TABLE = tableName;
// 
//         db.execSQL("DROP TABLE IF EXISTS " + tableName);
//         onCreate(db, tableName);
//     }
// }


// Path: lib/src/main/java/io/xpush/chat/models/XPushMessage.java
import android.database.Cursor;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import io.xpush.chat.persist.MessageTable;

                    this.type = TYPE_IMAGE;
                }
            }

            // Message Metadata
            if( data.has("MD") ){
                this.metadata = data.getJSONObject("MD");
            }

            this.channel = data.getString("C");

            if( data.has("US") ){
                String usersStr = data.getString("US");
                this.users = new ArrayList<String>(Arrays.asList(usersStr.split("@!@")));
            }  else if( this.channel != null && this.channel.indexOf("@!@") > -1 && this.channel.lastIndexOf("^") > 0 ){
                String usersStr = this.channel.substring( 0, this.channel.lastIndexOf("^") );
                this.users = new ArrayList<String>(Arrays.asList(usersStr.split("@!@")));
            }

            this.message = URLDecoder.decode( data.getString("MG"), "UTF-8");
            this.updated = data.getLong("TS");

            this.id = channel +"_" + updated;

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public XPushMessage(Cursor cursor){
        this.rowId= cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.KEY_MESSAGE));