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
dc6dd5ec
Commit
dc6dd5ec
authored
Apr 24, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Getting from the network into Realm
parent
13837af2
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
239 additions
and
1 deletion
+239
-1
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+36
-0
RoomPresenter.java
.../chat/rocket/android/fragment/chatroom/RoomPresenter.java
+5
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+5
-0
Migration.java
...rc/main/java/chat/rocket/persistence/realm/Migration.java
+22
-0
RealmStore.java
...c/main/java/chat/rocket/persistence/realm/RealmStore.java
+1
-1
RealmPermission.java
.../rocket/persistence/realm/models/ddp/RealmPermission.java
+60
-0
RealmRole.java
...a/chat/rocket/persistence/realm/models/ddp/RealmRole.java
+42
-0
RealmRoomRole.java
...at/rocket/persistence/realm/models/ddp/RealmRoomRole.java
+68
-0
No files found.
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
dc6dd5ec
...
...
@@ -12,10 +12,12 @@ import bolts.Task;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.persistence.realm.models.ddp.RealmPermission
;
import
chat.rocket.persistence.realm.models.ddp.RealmPublicSetting
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.persistence.realm.models.ddp.RealmMessage
;
import
chat.rocket.persistence.realm.models.ddp.RealmRoom
;
import
chat.rocket.persistence.realm.models.ddp.RealmRoomRole
;
import
chat.rocket.persistence.realm.models.ddp.RealmSpotlightRoom
;
import
chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser
;
import
chat.rocket.persistence.realm.models.internal.MethodCall
;
...
...
@@ -401,6 +403,40 @@ public class MethodCallHelper {
});
}
public
Task
<
Void
>
getPermissions
()
{
return
call
(
"permissions/get"
,
TIMEOUT_MS
)
.
onSuccessTask
(
CONVERT_TO_JSON_ARRAY
)
.
onSuccessTask
(
task
->
{
final
JSONArray
permissions
=
task
.
getResult
();
for
(
int
i
=
0
;
i
<
permissions
.
length
();
i
++)
{
RealmPermission
.
customizeJson
(
permissions
.
getJSONObject
(
i
));
}
return
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
delete
(
RealmPermission
.
class
);
realm
.
createOrUpdateAllFromJson
(
RealmPermission
.
class
,
permissions
);
return
null
;
});
});
}
public
Task
<
Void
>
getRoomRoles
(
final
String
roomId
)
{
return
call
(
"getRoomRoles"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
roomId
))
.
onSuccessTask
(
CONVERT_TO_JSON_ARRAY
)
.
onSuccessTask
(
task
->
{
final
JSONArray
roomRoles
=
task
.
getResult
();
for
(
int
i
=
0
;
i
<
roomRoles
.
length
();
i
++)
{
RealmRoomRole
.
customizeJson
(
roomRoles
.
getJSONObject
(
i
));
}
return
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
delete
(
RealmRoomRole
.
class
);
realm
.
createOrUpdateAllFromJson
(
RealmRoomRole
.
class
,
roomRoles
);
return
null
;
});
});
}
public
Task
<
Void
>
searchSpotlightUsers
(
String
term
)
{
return
searchSpotlight
(
RealmSpotlightUser
.
class
,
"users"
,
term
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomPresenter.java
View file @
dc6dd5ec
...
...
@@ -56,6 +56,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
public
void
bindView
(
@NonNull
RoomContract
.
View
view
)
{
super
.
bindView
(
view
);
getRoomRoles
();
getRoomInfo
();
getRoomHistoryStateInfo
();
getMessages
();
...
...
@@ -183,6 +184,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
addSubscription
(
subscription
);
}
private
void
getRoomRoles
()
{
methodCallHelper
.
getRoomRoles
(
roomId
);
}
private
void
getRoomInfo
()
{
final
Disposable
subscription
=
roomRepository
.
getById
(
roomId
)
.
distinctUntilChanged
()
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
dc6dd5ec
...
...
@@ -270,6 +270,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
return
connectDDPClient
()
.
flatMap
(
_val
->
Single
.
fromEmitter
(
emitter
->
{
fetchPublicSettings
();
fetchPermissions
();
registerListeners
();
emitter
.
onSuccess
(
true
);
}));
...
...
@@ -279,6 +280,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
return
new
MethodCallHelper
(
realmHelper
,
ddpClientRef
).
getPublicSettings
();
}
private
Task
<
Void
>
fetchPermissions
()
{
return
new
MethodCallHelper
(
realmHelper
,
ddpClientRef
).
getPermissions
();
}
//@DebugLog
private
void
registerListeners
()
{
if
(!
Thread
.
currentThread
().
getName
().
equals
(
"RC_thread_"
+
hostname
))
{
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/Migration.java
View file @
dc6dd5ec
...
...
@@ -6,6 +6,9 @@ import io.realm.RealmMigration;
import
io.realm.RealmObjectSchema
;
import
io.realm.RealmSchema
;
import
chat.rocket.persistence.realm.models.ddp.RealmPermission
;
import
chat.rocket.persistence.realm.models.ddp.RealmRole
;
import
chat.rocket.persistence.realm.models.ddp.RealmRoomRole
;
import
chat.rocket.persistence.realm.models.ddp.RealmSpotlightRoom
;
import
chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser
;
...
...
@@ -38,6 +41,25 @@ public class Migration implements RealmMigration {
RealmObjectSchema
roomSchema
=
schema
.
get
(
"RealmSpotlightUser"
);
roomSchema
.
addField
(
RealmSpotlightUser
.
Columns
.
NAME
,
String
.
class
);
oldVersion
++;
}
if
(
oldVersion
==
3
)
{
schema
.
create
(
"RealmRole"
)
.
addField
(
RealmRole
.
Columns
.
ID
,
String
.
class
,
FieldAttribute
.
PRIMARY_KEY
)
.
addField
(
RealmRole
.
Columns
.
NAME
,
String
.
class
);
schema
.
create
(
"RealmPermission"
)
.
addField
(
RealmPermission
.
Columns
.
ID
,
String
.
class
,
FieldAttribute
.
PRIMARY_KEY
)
.
addField
(
RealmPermission
.
Columns
.
NAME
,
String
.
class
)
.
addRealmListField
(
RealmPermission
.
Columns
.
ROLES
,
schema
.
get
(
"RealmRole"
));
schema
.
create
(
"RealmRoomRole"
)
.
addField
(
RealmRoomRole
.
Columns
.
ID
,
String
.
class
,
FieldAttribute
.
PRIMARY_KEY
)
.
addField
(
RealmRoomRole
.
Columns
.
ROOM_ID
,
String
.
class
)
.
addRealmObjectField
(
RealmRoomRole
.
Columns
.
USER
,
schema
.
get
(
"RealmUser"
))
.
addRealmListField
(
RealmRoomRole
.
Columns
.
ROLES
,
schema
.
get
(
"RealmRole"
));
}
}
}
persistence-realm/src/main/java/chat/rocket/persistence/realm/RealmStore.java
View file @
dc6dd5ec
...
...
@@ -15,7 +15,7 @@ public class RealmStore {
.
name
(
name
+
".realm"
)
.
modules
(
new
RocketChatLibraryModule
())
.
migration
(
new
Migration
())
.
schemaVersion
(
3
)
.
schemaVersion
(
4
)
.
build
();
}
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/models/ddp/RealmPermission.java
0 → 100644
View file @
dc6dd5ec
package
chat
.
rocket
.
persistence
.
realm
.
models
.
ddp
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
import
io.realm.annotations.PrimaryKey
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
RealmPermission
extends
RealmObject
{
public
static
JSONObject
customizeJson
(
JSONObject
permissionsJson
)
throws
JSONException
{
permissionsJson
.
put
(
Columns
.
NAME
,
permissionsJson
.
getString
(
Columns
.
ID
));
JSONArray
roleStrings
=
permissionsJson
.
getJSONArray
(
Columns
.
ROLES
);
JSONArray
roles
=
new
JSONArray
();
for
(
int
i
=
0
,
size
=
roleStrings
.
length
();
i
<
size
;
i
++)
{
roles
.
put
(
RealmRole
.
customizeJson
(
roleStrings
.
getString
(
i
)));
}
permissionsJson
.
remove
(
Columns
.
ROLES
);
permissionsJson
.
put
(
Columns
.
ROLES
,
roles
);
return
permissionsJson
;
}
public
interface
Columns
{
String
ID
=
"_id"
;
String
NAME
=
"name"
;
String
ROLES
=
"roles"
;
}
@PrimaryKey
private
String
_id
;
private
String
name
;
private
RealmList
<
RealmRole
>
roles
;
public
String
getId
()
{
return
_id
;
}
public
void
setId
(
String
id
)
{
this
.
_id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
RealmList
<
RealmRole
>
getRoles
()
{
return
roles
;
}
public
void
setRoles
(
RealmList
<
RealmRole
>
roles
)
{
this
.
roles
=
roles
;
}
}
persistence-realm/src/main/java/chat/rocket/persistence/realm/models/ddp/RealmRole.java
0 → 100644
View file @
dc6dd5ec
package
chat
.
rocket
.
persistence
.
realm
.
models
.
ddp
;
import
io.realm.RealmObject
;
import
io.realm.annotations.PrimaryKey
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
RealmRole
extends
RealmObject
{
public
static
JSONObject
customizeJson
(
String
roleString
)
throws
JSONException
{
JSONObject
roleObject
=
new
JSONObject
();
roleObject
.
put
(
Columns
.
ID
,
roleString
);
roleObject
.
put
(
Columns
.
NAME
,
roleString
);
return
roleObject
;
}
public
interface
Columns
{
String
ID
=
"id"
;
String
NAME
=
"name"
;
}
@PrimaryKey
private
String
id
;
private
String
name
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
persistence-realm/src/main/java/chat/rocket/persistence/realm/models/ddp/RealmRoomRole.java
0 → 100644
View file @
dc6dd5ec
package
chat
.
rocket
.
persistence
.
realm
.
models
.
ddp
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
import
io.realm.annotations.PrimaryKey
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
RealmRoomRole
extends
RealmObject
{
public
static
JSONObject
customizeJson
(
JSONObject
roomRoles
)
throws
JSONException
{
JSONArray
roleStrings
=
roomRoles
.
getJSONArray
(
Columns
.
ROLES
);
JSONArray
roles
=
new
JSONArray
();
for
(
int
i
=
0
,
size
=
roleStrings
.
length
();
i
<
size
;
i
++)
{
roles
.
put
(
RealmRole
.
customizeJson
(
roleStrings
.
getString
(
i
)));
}
roomRoles
.
remove
(
Columns
.
ROLES
);
roomRoles
.
put
(
Columns
.
ROLES
,
roles
);
return
roomRoles
;
}
public
interface
Columns
{
String
ID
=
"_id"
;
String
ROOM_ID
=
"rid"
;
String
USER
=
"u"
;
String
ROLES
=
"roles"
;
}
@PrimaryKey
private
String
_id
;
private
String
rid
;
private
RealmUser
u
;
private
RealmList
<
RealmRole
>
roles
;
public
String
getId
()
{
return
_id
;
}
public
void
setId
(
String
id
)
{
this
.
_id
=
id
;
}
public
String
getRoomId
()
{
return
rid
;
}
public
void
setRoomId
(
String
roomId
)
{
this
.
rid
=
roomId
;
}
public
RealmUser
getUser
()
{
return
u
;
}
public
void
setUser
(
RealmUser
user
)
{
this
.
u
=
user
;
}
public
RealmList
<
RealmRole
>
getRoles
()
{
return
roles
;
}
public
void
setRoles
(
RealmList
<
RealmRole
>
roles
)
{
this
.
roles
=
roles
;
}
}
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