Commit f4cbe1ba authored by Yusuke Iwaki's avatar Yusuke Iwaki Committed by GitHub

Merge pull request #89 from RocketChat/feature/user-presence

Added calls for setting the away presence
parents 8876ac1e d8a73536
...@@ -7,9 +7,11 @@ import android.support.v7.widget.Toolbar; ...@@ -7,9 +7,11 @@ import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import chat.rocket.android.LaunchUtil; import chat.rocket.android.LaunchUtil;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.fragment.chatroom.HomeFragment; import chat.rocket.android.fragment.chatroom.HomeFragment;
import chat.rocket.android.fragment.chatroom.RoomFragment; import chat.rocket.android.fragment.chatroom.RoomFragment;
import chat.rocket.android.fragment.sidebar.SidebarMainFragment; import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.model.internal.Session; import chat.rocket.android.model.internal.Session;
import chat.rocket.android.realm_helper.RealmHelper; import chat.rocket.android.realm_helper.RealmHelper;
import chat.rocket.android.realm_helper.RealmObjectObserver; import chat.rocket.android.realm_helper.RealmObjectObserver;
...@@ -37,6 +39,34 @@ public class MainActivity extends AbstractAuthedActivity { ...@@ -37,6 +39,34 @@ public class MainActivity extends AbstractAuthedActivity {
} }
} }
@Override
protected void onStart() {
super.onStart();
setUserOnlineIfServerAvailable();
}
@Override
protected void onStop() {
setUserAwayIfServerAvailable();
super.onStop();
}
private void setUserOnlineIfServerAvailable() {
if (serverConfigId != null) {
new MethodCallHelper(this, serverConfigId).setUserOnline()
.continueWith(new LogcatIfError());
}
}
private void setUserAwayIfServerAvailable() {
if (serverConfigId != null) {
new MethodCallHelper(this, serverConfigId).setUserAway()
.continueWith(new LogcatIfError());
}
}
private void setupSidebar() { private void setupSidebar() {
SlidingPaneLayout pane = (SlidingPaneLayout) findViewById(R.id.sliding_pane); SlidingPaneLayout pane = (SlidingPaneLayout) findViewById(R.id.sliding_pane);
if (pane != null) { if (pane != null) {
......
...@@ -278,6 +278,15 @@ public class MethodCallHelper { ...@@ -278,6 +278,15 @@ public class MethodCallHelper {
.onSuccessTask(task -> Task.forResult(null)); .onSuccessTask(task -> Task.forResult(null));
} }
public Task<Void> setUserAway() {
return call("UserPresence:away", TIMEOUT_MS, JSONArray::new)
.onSuccessTask(task -> Task.forResult(null));
}
public Task<Void> setUserOnline() {
return call("UserPresence:online", TIMEOUT_MS, JSONArray::new)
.onSuccessTask(task -> Task.forResult(null));
}
public Task<JSONObject> getUsersOfRoom(final String roomId, final boolean showAll) { public Task<JSONObject> getUsersOfRoom(final String roomId, final boolean showAll) {
return call("getUsersOfRoom", TIMEOUT_MS, () -> new JSONArray().put(roomId).put(showAll)) return call("getUsersOfRoom", TIMEOUT_MS, () -> new JSONArray().put(roomId).put(showAll))
......
package chat.rocket.android.helper; package chat.rocket.android.helper;
import android.view.View; import android.view.View;
import hugo.weaving.DebugLog;
/** /**
* save String to setTag. * save String to setTag.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment