Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
fixes for group chat session creation and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed May 31, 2018
1 parent bbbbc24 commit 9f2f328
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ private ChatSession findOrCreateSession(String address, boolean groupChat, boole
//create a session
if (session == null) {
ImEntity participant = findOrCreateParticipant(xAddr.getAddress(), true);
session = mSessionManager.createChatSession(participant, true);
session = mSessionManager.createChatSession(participant, isNew);
if (session != null && session.getParticipant() != null)
((ChatGroup) session.getParticipant()).setName(muc.getSubject());
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/org/awesomeapp/messenger/provider/Imps.java
Original file line number Diff line number Diff line change
Expand Up @@ -2563,9 +2563,16 @@ public static boolean messageExists (ContentResolver resolver, String id, int me
Uri.Builder builder = Messages.OTR_MESSAGES_CONTENT_URI_BY_PACKET_ID.buildUpon();
builder.appendPath(id);

String[] args = {messageType+""};
String[] args = new String[1];
String selection = null;

Cursor c = resolver.query(builder.build(),null, Imps.Messages.TYPE + "=?", args, null);
if (messageType != -1)
{
args[0] = messageType+"";
selection = Imps.Messages.TYPE + "=?";
}

Cursor c = resolver.query(builder.build(),null, selection, args, null);
if (c != null)
{
if (c.getCount() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,20 @@ private void copyHistoryMessages(Contact oldParticipant) {

Uri insertOrUpdateChat(String message) {

ContentValues values = new ContentValues(2);
ContentValues values = new ContentValues(4);

values.put(Imps.Chats.LAST_MESSAGE_DATE, System.currentTimeMillis());
values.put(Imps.Chats.LAST_UNREAD_MESSAGE, message);

values.put(Imps.Chats.GROUP_CHAT, mIsGroupChat);
// ImProvider.insert() will replace the chat if it already exist.
return mContentResolver.insert(mChatURI, values);
values.put(Imps.Chats.USE_ENCRYPTION,mEnableOmemoGroups);

int result = mContentResolver.update(mChatURI, values, null, null);

if (result < 1)
// ImProvider.insert() will replace the chat if it already exist.
return mContentResolver.insert(mChatURI, values);
else
return mChatURI;
}

// Pattern for recognizing a URL, based off RFC 3986
Expand Down Expand Up @@ -1129,7 +1135,8 @@ public boolean onIncomingMessage(ChatSession ses, final org.awesomeapp.messenger
&& msg.getType() == Imps.MessageType.INCOMING)
return false;

if (Imps.messageExists(mContentResolver,msg.getID(),msg.getType()))
//we already have an encrypted message with this idea, so don't override that
if (Imps.messageExists(mContentResolver,msg.getID(),-1))
return false;

String body = msg.getBody();
Expand Down Expand Up @@ -1181,17 +1188,15 @@ else if (displayType.equals("image"))
}
else {
//if it wasn't a media file or we had an issue downloading, then it is chat


insertOrUpdateChat(body);

Uri messageUri = null;

if (msg.getID() == null)
messageUri = insertMessageInDb(nickname, body, time, msg.getType(), null);
else
messageUri = insertMessageInDb(nickname, body, time, msg.getType(), 0, msg.getID(), null);

insertOrUpdateChat(body);

if (messageUri == null) {
Log.e(TAG,"error saving message to the db: " + msg.getID());
return false; //couldn't write to database
Expand Down

0 comments on commit 9f2f328

Please sign in to comment.