Skip to content

Commit

Permalink
fix LastSeen updating
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Aug 11, 2021
1 parent 8dea25b commit 29fec16
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
4 changes: 0 additions & 4 deletions app/src/main/java/co/tinode/tindroid/MessageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,6 @@ void runMessagesLoader() {
}
}

public void submitForExecution(Runnable runnable) {
mMessageSender.submit(runnable);
}

/**
* Show progress indicator based on current status
*
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/co/tinode/tindroid/MessagesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,8 @@ public void afterTextChanged(Editable editable) {
long msgId = failure.getLong(AttachmentHandler.ARG_MSG_ID, -1L);
if (BaseDb.getInstance().getStore().getMessageById(msgId) != null) {
runMessagesLoader(mTopicName);
if (state == WorkInfo.State.FAILED) {
String error = failure.getString(AttachmentHandler.ARG_ERROR);
Toast.makeText(activity, error, Toast.LENGTH_SHORT).show();
}
String error = failure.getString(AttachmentHandler.ARG_ERROR);
Toast.makeText(activity, error, Toast.LENGTH_SHORT).show();
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.0.0'

// For FCM push notifications
classpath 'com.google.gms:google-services:4.3.9'
classpath 'com.google.gms:google-services:4.3.10'

// Crashlytics
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
Expand Down
23 changes: 7 additions & 16 deletions tinodesdk/src/main/java/co/tinode/tinodesdk/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class Topic<DP, DR, SP, SR> implements LocalData, Comparable<Topic> {
// Timestamp of the last key press that the server was notified of, milliseconds
protected long mLastKeyPress = 0;
protected boolean mOnline = false;
protected LastSeen mLastSeen = null;
// ID of the last applied delete transaction. Different from 'clear' which is the highest known.
protected int mMaxDel = 0;
/**
Expand Down Expand Up @@ -99,7 +98,6 @@ protected Topic(Tinode tinode, Subscription<SP, SR> sub) {
if (sub.online != null) {
mOnline = sub.online;
}
mLastSeen = sub.seen;
}

protected Topic(Tinode tinode, String name, Description<DP, DR> desc) {
Expand Down Expand Up @@ -235,14 +233,7 @@ public void setTypes(String typeOfDescPublic, String typeOfDescPrivate,
* @param sub updated topic parameters
*/
protected boolean update(Subscription<SP, SR> sub) {
boolean changed;

if (mLastSeen == null) {
changed = true;
mLastSeen = sub.seen;
} else {
changed = mLastSeen.merge(sub.seen);
}
boolean changed = false;

if (mDesc.merge(sub)) {
changed = true;
Expand Down Expand Up @@ -784,32 +775,32 @@ protected void persist(boolean on) {
* Update timestamp and user agent of when the topic was last online.
*/
public void setLastSeen(Date when, String ua) {
mLastSeen = new LastSeen(when, ua);
mDesc.seen = new LastSeen(when, ua);
}

/**
* Update timestamp of when the topic was last online.
*/
protected void setLastSeen(Date when) {
if (mLastSeen != null) {
mLastSeen.when = when;
if (mDesc.seen != null) {
mDesc.seen.when = when;
} else {
mLastSeen = new LastSeen(when);
mDesc.seen = new LastSeen(when);
}
}

/**
* Get timestamp when the topic was last online, if available.
*/
public Date getLastSeen() {
return mLastSeen != null ? mLastSeen.when : null;
return mDesc.seen != null ? mDesc.seen.when : null;
}

/**
* Get user agent string associated with the time when the topic was last online.
*/
public String getLastSeenUA() {
return mLastSeen != null ? mLastSeen.ua : null;
return mDesc.seen != null ? mDesc.seen.ua : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ public <SP,SR> boolean merge(Subscription<SP,SR> sub) {

}

if (sub.seen != null) {
if (seen == null) {
seen = sub.seen;
changed = true;
} else {
changed = seen.merge(sub.seen) || changed;
}
}

return changed;
}

Expand All @@ -211,7 +220,7 @@ public boolean merge(MetaSetDesc<DP,DR> desc) {
defacs = desc.defacs;
changed = true;
} else {
changed = defacs.merge(desc.defacs) || changed;
changed = defacs.merge(desc.defacs);
}
}

Expand Down

0 comments on commit 29fec16

Please sign in to comment.