Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
2ae619c8
Commit
2ae619c8
authored
Nov 22, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement logout.
parent
9666e58b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
38 deletions
+86
-38
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+1
-0
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+16
-3
RetryLoginFragment.java
...et/android/fragment/server_config/RetryLoginFragment.java
+0
-1
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+22
-15
RoomListManager.java
...rocket/android/layouthelper/chatroom/RoomListManager.java
+22
-0
Session.java
...main/java/chat/rocket/android/model/internal/Session.java
+15
-7
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+8
-1
TokenLoginObserver.java
...t/rocket/android/service/observer/TokenLoginObserver.java
+2
-7
RealmHelper.java
...in/java/chat/rocket/android/realm_helper/RealmHelper.java
+0
-4
No files found.
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
2ae619c8
...
@@ -63,6 +63,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
...
@@ -63,6 +63,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
private
void
onRenderServerConfigSession
(
Session
session
)
{
private
void
onRenderServerConfigSession
(
Session
session
)
{
if
(
session
==
null
)
{
if
(
session
==
null
)
{
showFragment
(
new
LoginFragment
());
return
;
return
;
}
}
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
2ae619c8
...
@@ -59,6 +59,9 @@ public class MethodCallHelper {
...
@@ -59,6 +59,9 @@ public class MethodCallHelper {
}
}
String
errMessage
=
new
JSONObject
(
errMessageJson
).
getString
(
"message"
);
String
errMessage
=
new
JSONObject
(
errMessageJson
).
getString
(
"message"
);
return
Task
.
forError
(
new
Exception
(
errMessage
));
return
Task
.
forError
(
new
Exception
(
errMessage
));
}
else
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Error
)
{
String
errMessage
=
((
DDPClientCallback
.
RPC
.
Error
)
exception
).
error
.
getString
(
"message"
);
return
Task
.
forError
(
new
Exception
(
errMessage
));
}
else
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Timeout
)
{
}
else
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Timeout
)
{
return
Task
.
forError
(
new
MethodCall
.
Timeout
());
return
Task
.
forError
(
new
MethodCall
.
Timeout
());
}
else
{
}
else
{
...
@@ -158,14 +161,24 @@ public class MethodCallHelper {
...
@@ -158,14 +161,24 @@ public class MethodCallHelper {
.
put
(
"resume"
,
token
)
.
put
(
"resume"
,
token
)
)).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
)
)).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
)
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
)))
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
)))
.
onSuccessTask
(
this
::
saveToken
);
.
onSuccessTask
(
this
::
saveToken
)
.
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
Session
.
logError
(
realmHelper
,
task
.
getError
());
}
return
task
;
});
}
}
/**
/**
* Logout.
* Logout.
*/
*/
public
Task
<
String
>
logout
()
{
public
Task
<
Void
>
logout
()
{
return
call
(
"logout"
,
TIMEOUT_MS
);
return
call
(
"logout"
,
TIMEOUT_MS
).
onSuccessTask
(
task
->
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
delete
(
Session
.
class
);
return
null
;
}));
}
}
/**
/**
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/RetryLoginFragment.java
View file @
2ae619c8
...
@@ -51,7 +51,6 @@ public class RetryLoginFragment extends AbstractServerConfigFragment {
...
@@ -51,7 +51,6 @@ public class RetryLoginFragment extends AbstractServerConfigFragment {
if
(
task
.
isFaulted
())
{
if
(
task
.
isFaulted
())
{
view
.
setEnabled
(
true
);
view
.
setEnabled
(
true
);
waitingView
.
setVisibility
(
View
.
GONE
);
waitingView
.
setVisibility
(
View
.
GONE
);
Session
.
logError
(
RealmStore
.
get
(
serverConfigId
),
task
.
getError
());
}
}
return
null
;
return
null
;
});
});
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
2ae619c8
...
@@ -31,6 +31,7 @@ public class SidebarMainFragment extends AbstractFragment {
...
@@ -31,6 +31,7 @@ public class SidebarMainFragment extends AbstractFragment {
private
String
hostname
;
private
String
hostname
;
private
RealmListObserver
<
RoomSubscription
>
roomsObserver
;
private
RealmListObserver
<
RoomSubscription
>
roomsObserver
;
private
RealmObjectObserver
<
User
>
currentUserObserver
;
private
RealmObjectObserver
<
User
>
currentUserObserver
;
private
MethodCallHelper
methodCallHelper
;
public
SidebarMainFragment
()
{
public
SidebarMainFragment
()
{
}
}
...
@@ -68,6 +69,8 @@ public class SidebarMainFragment extends AbstractFragment {
...
@@ -68,6 +69,8 @@ public class SidebarMainFragment extends AbstractFragment {
currentUserObserver
=
realmHelper
currentUserObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
User
.
class
).
isNotEmpty
(
"emails"
))
.
createObjectObserver
(
realm
->
realm
.
where
(
User
.
class
).
isNotEmpty
(
"emails"
))
.
setOnUpdateListener
(
this
::
onRenderCurrentUser
);
.
setOnUpdateListener
(
this
::
onRenderCurrentUser
);
methodCallHelper
=
new
MethodCallHelper
(
serverConfigId
);
}
}
}
}
}
}
...
@@ -87,6 +90,7 @@ public class SidebarMainFragment extends AbstractFragment {
...
@@ -87,6 +90,7 @@ public class SidebarMainFragment extends AbstractFragment {
setupUserActionToggle
();
setupUserActionToggle
();
setupUserStatusButtons
();
setupUserStatusButtons
();
setupLogoutButton
();
roomListManager
=
new
RoomListManager
(
roomListManager
=
new
RoomListManager
(
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
channels_container
),
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
channels_container
),
...
@@ -111,24 +115,19 @@ public class SidebarMainFragment extends AbstractFragment {
...
@@ -111,24 +115,19 @@ public class SidebarMainFragment extends AbstractFragment {
}
}
private
void
setupUserStatusButtons
()
{
private
void
setupUserStatusButtons
()
{
rootView
.
findViewById
(
R
.
id
.
btn_status_online
).
setOnClickListener
(
view
->
{
rootView
.
findViewById
(
R
.
id
.
btn_status_online
).
setOnClickListener
(
view
->
updateCurrentUserStatus
(
User
.
STATUS_ONLINE
);
updateCurrentUserStatus
(
User
.
STATUS_ONLINE
));
});
rootView
.
findViewById
(
R
.
id
.
btn_status_away
).
setOnClickListener
(
view
->
rootView
.
findViewById
(
R
.
id
.
btn_status_away
).
setOnClickListener
(
view
->
{
updateCurrentUserStatus
(
User
.
STATUS_AWAY
));
updateCurrentUserStatus
(
User
.
STATUS_AWAY
);
rootView
.
findViewById
(
R
.
id
.
btn_status_busy
).
setOnClickListener
(
view
->
});
updateCurrentUserStatus
(
User
.
STATUS_BUSY
));
rootView
.
findViewById
(
R
.
id
.
btn_status_busy
).
setOnClickListener
(
view
->
{
rootView
.
findViewById
(
R
.
id
.
btn_status_invisible
).
setOnClickListener
(
view
->
updateCurrentUserStatus
(
User
.
STATUS_BUSY
);
updateCurrentUserStatus
(
User
.
STATUS_OFFLINE
));
});
rootView
.
findViewById
(
R
.
id
.
btn_status_invisible
).
setOnClickListener
(
view
->
{
updateCurrentUserStatus
(
User
.
STATUS_OFFLINE
);
});
}
}
private
void
updateCurrentUserStatus
(
String
status
)
{
private
void
updateCurrentUserStatus
(
String
status
)
{
if
(!
TextUtils
.
isEmpty
(
serverConfigId
))
{
if
(
methodCallHelper
!=
null
)
{
new
MethodCallHelper
(
serverConfigId
).
setUserStatus
(
status
)
methodCallHelper
.
setUserStatus
(
status
).
continueWith
(
new
LogcatIfError
());
.
continueWith
(
new
LogcatIfError
());
}
}
}
}
...
@@ -141,6 +140,14 @@ public class SidebarMainFragment extends AbstractFragment {
...
@@ -141,6 +140,14 @@ public class SidebarMainFragment extends AbstractFragment {
}
}
}
}
private
void
setupLogoutButton
()
{
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
if
(
methodCallHelper
!=
null
)
{
methodCallHelper
.
logout
().
continueWith
(
new
LogcatIfError
());
}
});
}
@Override
public
void
onResume
()
{
@Override
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
if
(
roomsObserver
!=
null
)
{
if
(
roomsObserver
!=
null
)
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/RoomListManager.java
View file @
2ae619c8
...
@@ -35,6 +35,9 @@ public class RoomListManager {
...
@@ -35,6 +35,9 @@ public class RoomListManager {
* update ViewGroups with room list.
* update ViewGroups with room list.
*/
*/
public
void
setRooms
(
List
<
RoomSubscription
>
roomSubscriptionList
)
{
public
void
setRooms
(
List
<
RoomSubscription
>
roomSubscriptionList
)
{
removeDeletedItem
(
channelsContainer
,
roomSubscriptionList
);
removeDeletedItem
(
dmContainer
,
roomSubscriptionList
);
for
(
RoomSubscription
roomSubscription
:
roomSubscriptionList
)
{
for
(
RoomSubscription
roomSubscription
:
roomSubscriptionList
)
{
String
name
=
roomSubscription
.
getName
();
String
name
=
roomSubscription
.
getName
();
if
(
TextUtils
.
isEmpty
(
name
))
{
if
(
TextUtils
.
isEmpty
(
name
))
{
...
@@ -61,6 +64,25 @@ public class RoomListManager {
...
@@ -61,6 +64,25 @@ public class RoomListManager {
this
.
listener
=
listener
;
this
.
listener
=
listener
;
}
}
private
void
removeDeletedItem
(
ViewGroup
parent
,
List
<
RoomSubscription
>
roomSubscriptionList
)
{
for
(
int
index
=
parent
.
getChildCount
()
-
1
;
index
>=
0
;
index
--)
{
RoomListItemView
roomListItemView
=
(
RoomListItemView
)
parent
.
getChildAt
(
index
);
final
String
targetRoomName
=
roomListItemView
.
getRoomName
();
if
(!
TextUtils
.
isEmpty
(
targetRoomName
))
{
boolean
found
=
false
;
for
(
RoomSubscription
roomSubscription
:
roomSubscriptionList
)
{
if
(
targetRoomName
.
equals
(
roomSubscription
.
getName
()))
{
found
=
true
;
break
;
}
}
if
(!
found
)
{
parent
.
removeViewAt
(
index
);
}
}
}
}
private
void
insertOrUpdateItem
(
ViewGroup
parent
,
RoomSubscription
roomSubscription
)
{
private
void
insertOrUpdateItem
(
ViewGroup
parent
,
RoomSubscription
roomSubscription
)
{
final
String
roomName
=
roomSubscription
.
getName
();
final
String
roomName
=
roomSubscription
.
getName
();
...
...
app/src/main/java/chat/rocket/android/model/internal/Session.java
View file @
2ae619c8
package
chat
.
rocket
.
android
.
model
.
internal
;
package
chat
.
rocket
.
android
.
model
.
internal
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
import
io.realm.RealmObject
;
import
io.realm.RealmObject
;
...
@@ -53,12 +54,19 @@ public class Session extends RealmObject {
...
@@ -53,12 +54,19 @@ public class Session extends RealmObject {
* Log the server connection is lost due to soem exception.
* Log the server connection is lost due to soem exception.
*/
*/
@DebugLog
public
static
void
logError
(
RealmHelper
realmHelper
,
Exception
exception
)
{
@DebugLog
public
static
void
logError
(
RealmHelper
realmHelper
,
Exception
exception
)
{
// TODO: should remove token if 403.
String
errString
=
exception
.
getMessage
();
realmHelper
.
executeTransaction
(
if
(!
TextUtils
.
isEmpty
(
errString
)
&&
errString
.
contains
(
"[403]"
))
{
realm
->
realm
.
createOrUpdateObjectFromJson
(
Session
.
class
,
new
JSONObject
()
realmHelper
.
executeTransaction
(
realm
->
{
.
put
(
"sessionId"
,
Session
.
DEFAULT_ID
)
realm
.
delete
(
Session
.
class
);
.
put
(
"tokenVerified"
,
false
)
return
null
;
.
put
(
"error"
,
exception
.
getMessage
())))
}).
continueWith
(
new
LogcatIfError
());
.
continueWith
(
new
LogcatIfError
());
}
else
{
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Session
.
class
,
new
JSONObject
()
.
put
(
"sessionId"
,
Session
.
DEFAULT_ID
)
.
put
(
"tokenVerified"
,
false
)
.
put
(
"error"
,
errString
)))
.
continueWith
(
new
LogcatIfError
());
}
}
}
}
}
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
2ae619c8
...
@@ -4,6 +4,8 @@ import android.content.Context;
...
@@ -4,6 +4,8 @@ import android.content.Context;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.model.internal.LoadMessageProcedure
;
import
chat.rocket.android.model.internal.MethodCall
;
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
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
...
@@ -60,6 +62,11 @@ public class SessionObserver extends AbstractModelObserver<Session> {
...
@@ -60,6 +62,11 @@ public class SessionObserver extends AbstractModelObserver<Session> {
}
}
@DebugLog
private
void
onLogout
()
{
@DebugLog
private
void
onLogout
()
{
realmHelper
.
executeTransaction
(
realm
->
{
// remove all tables. ONLY INTERNAL TABLES!.
realm
.
delete
(
MethodCall
.
class
);
realm
.
delete
(
LoadMessageProcedure
.
class
);
return
null
;
}).
continueWith
(
new
LogcatIfError
());
}
}
}
}
app/src/main/java/chat/rocket/android/service/observer/TokenLoginObserver.java
View file @
2ae619c8
...
@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
...
@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
import
android.content.Context
;
import
android.content.Context
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
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.api.DDPClientWraper
;
import
chat.rocket.android.api.DDPClientWraper
;
...
@@ -32,12 +33,6 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
...
@@ -32,12 +33,6 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
}
}
Session
session
=
results
.
get
(
0
);
Session
session
=
results
.
get
(
0
);
methodCall
.
loginWithToken
(
session
.
getToken
())
methodCall
.
loginWithToken
(
session
.
getToken
()).
continueWith
(
new
LogcatIfError
());
.
continueWith
(
task
->
{
if
(
task
.
isFaulted
())
{
Session
.
logError
(
realmHelper
,
task
.
getError
());
}
return
null
;
});
}
}
}
}
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmHelper.java
View file @
2ae619c8
...
@@ -168,8 +168,4 @@ public class RealmHelper {
...
@@ -168,8 +168,4 @@ public class RealmHelper {
RealmObjectObserver
.
Query
<
T
>
query
)
{
RealmObjectObserver
.
Query
<
T
>
query
)
{
return
new
RealmObjectObserver
<
T
>(
this
,
query
);
return
new
RealmObjectObserver
<
T
>(
this
,
query
);
}
}
public
void
delete
()
{
Realm
.
deleteRealm
(
realmConfiguration
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment