Created
July 17, 2015 21:15
-
-
Save peterclemenko/e0150b90e994fbe4e95c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// select messages._id,chat_list.key_remote_jid,key_from_me,data from | |
// chat_list,messages where chat_list.key_remote_jid = | |
// messages.key_remote_jid | |
private long fetchMessages(GenericSqliteHelper helper, final ChatGroups groups, long lastLine) { | |
final ArrayList<MessageChat> messages = new ArrayList<MessageChat>(); | |
String sqlquery = M.e("select m.createTime, m.talker, m.isSend, m.content, c.nickname from message as m join rcontact as c on m.talker=c.username where m.type = 1 and createTime > ? order by createTime"); | |
RecordVisitor visitor = new RecordVisitor() { | |
@Override | |
public long cursor(Cursor cursor) { | |
long createTime = cursor.getLong(0); | |
// localtime or gmt? should be converted to gmt | |
Date date = new Date(createTime); | |
String talker = cursor.getString(1); | |
int isSend = cursor.getInt(2); | |
boolean incoming = isSend == 0; | |
String content = cursor.getString(3); | |
String nick = cursor.getString(4); | |
String from_id = talker; | |
String to_id = talker; | |
if (Cfg.DEBUG) { | |
Check.log(TAG + " (cursor) %s: %s(%s) %s %s", date, nick, talker, content, (incoming ? "INCOMING" | |
: "OUTGOING")); | |
} | |
String from_name, to; | |
if (talker.endsWith(M.e("@chatroom"))) { | |
List<String> lines = Arrays.asList(content.split("\n")); | |
if (incoming) { | |
from_id = lines.get(0).trim(); | |
from_id = from_id.substring(0, from_id.length() - 1); | |
from_name = groups.getName(from_id); | |
to = groups.getGroupToName(from_name, talker); | |
to_id = groups.getGroupToId(from_name, talker); | |
content = StringUtils.join(lines, "", 1); | |
} else { | |
from_name = myName; | |
from_id = myId; | |
to = groups.getGroupToName(myName, talker); | |
to_id = groups.getGroupToId(myName, talker); | |
} | |
} else { | |
from_name = incoming ? nick : myName; | |
from_id = incoming ? talker : myId; | |
to = incoming ? myName : nick; | |
to_id = incoming ? myId : talker; | |
} | |
if (Cfg.DEBUG) { | |
Check.log(TAG + " (cursor) %s -> %s", from_id, to_id); | |
} | |
MessageChat message = new MessageChat(PROGRAM, date, from_id, from_name, to_id, to, content, incoming); | |
messages.add(message); | |
return createTime; | |
} | |
}; | |
long lastCreationLine = helper.traverseRawQuery(sqlquery, new String[] { Long.toString(lastLine) }, visitor); | |
getModule().saveEvidence(messages); | |
return lastCreationLine; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment