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
9cf77f45
Commit
9cf77f45
authored
Dec 17, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upload to FileSystem.
parent
2c65f620
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
10 deletions
+27
-10
FileUploadingHelper.java
...ain/java/chat/rocket/android/api/FileUploadingHelper.java
+4
-4
FileUploading.java
...ava/chat/rocket/android/model/internal/FileUploading.java
+1
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+2
-2
FileUploadingWithUfsObserver.java
...ndroid/service/observer/FileUploadingWithUfsObserver.java
+20
-4
No files found.
app/src/main/java/chat/rocket/android/api/FileUploadingHelper.java
View file @
9cf77f45
...
...
@@ -39,21 +39,21 @@ public class FileUploadingHelper extends MethodCallHelper {
.
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
public
Task
<
JSONObject
>
ufsCreate
(
String
filename
,
long
filesize
,
String
mimeType
,
public
Task
<
JSONObject
>
ufsCreate
(
String
filename
,
long
filesize
,
String
mimeType
,
String
store
,
String
roomId
)
{
return
call
(
"ufsCreate"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
new
JSONObject
()
.
put
(
"name"
,
filename
)
.
put
(
"size"
,
filesize
)
.
put
(
"type"
,
mimeType
)
.
put
(
"store"
,
"rocketchat_uploads"
)
.
put
(
"store"
,
store
)
.
put
(
"rid"
,
roomId
)
)).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
public
Task
<
JSONObject
>
ufsComplete
(
String
fileId
,
String
token
)
{
public
Task
<
JSONObject
>
ufsComplete
(
String
fileId
,
String
token
,
String
store
)
{
return
call
(
"ufsComplete"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
fileId
)
.
put
(
"rocketchat_uploads"
)
.
put
(
store
)
.
put
(
token
)
).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
...
...
app/src/main/java/chat/rocket/android/model/internal/FileUploading.java
View file @
9cf77f45
...
...
@@ -9,6 +9,7 @@ import io.realm.annotations.PrimaryKey;
public
class
FileUploading
extends
RealmObject
{
public
static
final
String
STORAGE_TYPE_S3
=
"AmazonS3"
;
public
static
final
String
STORAGE_TYPE_GRID_FS
=
"GridFS"
;
public
static
final
String
STORAGE_TYPE_FILE_SYSTEM
=
"FileSystem"
;
@PrimaryKey
private
String
uplId
;
private
int
syncstate
;
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
9cf77f45
...
...
@@ -19,7 +19,7 @@ import chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber;
import
chat.rocket.android.service.ddp.base.UserDataSubscriber
;
import
chat.rocket.android.service.observer.CurrentUserObserver
;
import
chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver
;
import
chat.rocket.android.service.observer.FileUploading
ToGridF
sObserver
;
import
chat.rocket.android.service.observer.FileUploading
WithUf
sObserver
;
import
chat.rocket.android.service.observer.LoadMessageProcedureObserver
;
import
chat.rocket.android.service.observer.MethodCallObserver
;
import
chat.rocket.android.service.observer.NewMessageObserver
;
...
...
@@ -53,7 +53,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
ReactiveNotificationManager
.
class
,
NotificationItemObserver
.
class
,
FileUploadingToS3Observer
.
class
,
FileUploading
ToGridF
sObserver
.
class
FileUploading
WithUf
sObserver
.
class
};
private
final
Context
appContext
;
private
final
String
serverConfigId
;
...
...
app/src/main/java/chat/rocket/android/service/observer/FileUploading
ToGridF
sObserver.java
→
app/src/main/java/chat/rocket/android/service/observer/FileUploading
WithUf
sObserver.java
View file @
9cf77f45
...
...
@@ -26,10 +26,10 @@ import org.json.JSONObject;
/**
* execute file uploading and requesting sendMessage with attachment.
*/
public
class
FileUploading
ToGridF
sObserver
extends
AbstractModelObserver
<
FileUploading
>
{
public
class
FileUploading
WithUf
sObserver
extends
AbstractModelObserver
<
FileUploading
>
{
private
FileUploadingHelper
methodCall
;
public
FileUploading
ToGridF
sObserver
(
Context
context
,
String
hostname
,
public
FileUploading
WithUf
sObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
FileUploadingHelper
(
realmHelper
,
ddpClient
);
...
...
@@ -38,7 +38,11 @@ public class FileUploadingToGridFsObserver extends AbstractModelObserver<FileUpl
// resume pending operations.
RealmResults
<
FileUploading
>
pendingUploadRequests
=
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
)
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
();
for
(
FileUploading
req
:
pendingUploadRequests
)
{
req
.
setSyncstate
(
SyncState
.
NOT_SYNCED
);
...
...
@@ -51,7 +55,11 @@ public class FileUploadingToGridFsObserver extends AbstractModelObserver<FileUpl
.
or
()
.
equalTo
(
"syncstate"
,
SyncState
.
FAILED
)
.
endGroup
()
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
().
deleteAllFromRealm
();
return
null
;
}).
continueWith
(
new
LogcatIfError
());
...
...
@@ -60,7 +68,11 @@ public class FileUploadingToGridFsObserver extends AbstractModelObserver<FileUpl
@Override
public
RealmResults
<
FileUploading
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
();
}
...
...
@@ -93,13 +105,17 @@ public class FileUploadingToGridFsObserver extends AbstractModelObserver<FileUpl
final
long
filesize
=
fileUploading
.
getFilesize
();
final
String
mimeType
=
fileUploading
.
getMimeType
();
final
Uri
fileUri
=
Uri
.
parse
(
fileUploading
.
getUri
());
final
String
store
=
FileUploading
.
STORAGE_TYPE_GRID_FS
.
equals
(
fileUploading
.
getStorageType
())
?
"rocketchat_uploads"
:
(
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
.
equals
(
fileUploading
.
getStorageType
())
?
"fileSystem"
:
null
);
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
)
)
).
onSuccessTask
(
_task
->
methodCall
.
ufsCreate
(
filename
,
filesize
,
mimeType
,
roomId
)
).
onSuccessTask
(
_task
->
methodCall
.
ufsCreate
(
filename
,
filesize
,
mimeType
,
store
,
roomId
)
).
onSuccessTask
(
task
->
{
final
JSONObject
info
=
task
.
getResult
();
final
String
fileId
=
info
.
getString
(
"fileId"
);
...
...
@@ -136,7 +152,7 @@ public class FileUploadingToGridFsObserver extends AbstractModelObserver<FileUpl
}
}
return
methodCall
.
ufsComplete
(
fileId
,
token
);
return
methodCall
.
ufsComplete
(
fileId
,
token
,
store
);
}).
onSuccessTask
(
task
->
methodCall
.
sendFileMessage
(
roomId
,
null
,
task
.
getResult
())
).
onSuccessTask
(
task
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
...
...
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