Commit 3f049ecb authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix NPE

parent c77a90ae
...@@ -164,7 +164,7 @@ public class MainActivity extends AbstractAuthedActivity { ...@@ -164,7 +164,7 @@ public class MainActivity extends AbstractAuthedActivity {
protected void onRoomIdUpdated() { protected void onRoomIdUpdated() {
super.onRoomIdUpdated(); super.onRoomIdUpdated();
if (roomId != null) { if (roomId != null && RoomFragment.canCreate(RealmStore.get(serverConfigId))) {
showFragment(RoomFragment.create(serverConfigId, roomId)); showFragment(RoomFragment.create(serverConfigId, roomId));
closeSidebarIfNeeded(); closeSidebarIfNeeded();
} else { } else {
......
...@@ -67,6 +67,14 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -67,6 +67,14 @@ public class RoomFragment extends AbstractChatRoomFragment
public RoomFragment() { public RoomFragment() {
} }
public static boolean canCreate(RealmHelper realmHelper) {
User currentUser = realmHelper.executeTransactionForRead(realm ->
User.queryCurrentUser(realm).findFirst());
Session session = realmHelper.executeTransactionForRead(realm ->
Session.queryDefaultSession(realm).findFirst());
return currentUser != null && session != null;
}
/** /**
* create fragment with roomId. * create fragment with roomId.
*/ */
......
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