Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive combined text messages on Android #1287

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -576,21 +576,25 @@ public Map<Integer, User> getUsers() {
public int HISTORY_USER_MSG_MAX = 100;

public Vector<MyTextMessage> getUserTextMsgs(int userid) {
Vector<MyTextMessage> msgs;
if(usertxtmsgs.get(userid) == null) {
Vector<MyTextMessage> msgs = usertxtmsgs.get(userid);
if (msgs == null) {
msgs = new Vector<MyTextMessage>();
usertxtmsgs.put(userid, msgs);
}
msgs = usertxtmsgs.get(userid);
if(msgs.size() > HISTORY_USER_MSG_MAX)
if (msgs.size() > HISTORY_USER_MSG_MAX)
msgs.remove(0);

MyTextMessage.merge(msgs);

return msgs;
}

public Vector<MyTextMessage> getChatLogTextMsgs() {
if(chatlogtxtmsgs.size()>HISTORY_CHATLOG_MSG_MAX)
if (chatlogtxtmsgs.size() > HISTORY_CHATLOG_MSG_MAX)
chatlogtxtmsgs.remove(0);

int c = chatlogtxtmsgs.size();
MyTextMessage.merge(chatlogtxtmsgs);
Log.d(TAG, "Messages changed from " + c + " to " + chatlogtxtmsgs.size());
return chatlogtxtmsgs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import dk.bearware.Constants;
Expand All @@ -39,12 +41,7 @@ public class MyTextMessage extends TextMessage {
public Date time = Calendar.getInstance().getTime();

public MyTextMessage(TextMessage msg, String name) {
this.nChannelID = msg.nChannelID;
this.nFromUserID = msg.nFromUserID;
this.nMsgType = msg.nMsgType;
this.nToUserID = msg.nToUserID;
this.szFromUsername = msg.szFromUsername;
this.szMessage = msg.szMessage;
super(msg);
this.szNickName = name;
}

Expand Down Expand Up @@ -98,6 +95,34 @@ public Vector<MyTextMessage> split() {
result.addAll(newmsg.split());
return result;
}

public static void merge(Vector<MyTextMessage> msgs) {
Map<Integer, Vector<MyTextMessage> > mergemsgs = new HashMap<>();
Vector<MyTextMessage> removemsgs = new Vector<>();
for (MyTextMessage m : msgs) {
int key = (m.nMsgType << 16) | m.nFromUserID;
Vector<MyTextMessage> moremessages = mergemsgs.get(key);
if (m.bMore) {
if (moremessages == null) {
moremessages = new Vector<>();
mergemsgs.put(key, moremessages);
}
moremessages.add(m);
}
else if (moremessages != null) {
String content = "";
for (MyTextMessage moremessage : moremessages) {
content += moremessage.szMessage;
removemsgs.add(moremessage);
}
m.szMessage = content + m.szMessage;
mergemsgs.remove(key);
}
}
for (MyTextMessage m : removemsgs) {
msgs.remove(m);
}
}

public static final int MSGTYPE_LOG_INFO = 0x80000000;
public static final int MSGTYPE_LOG_ERROR = 0x40000000;
Expand Down