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
cf4e33d5
Commit
cf4e33d5
authored
Mar 23, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GCP uploading
parent
4f259cc3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
19 deletions
+56
-19
FileUploadingHelper.java
...ain/java/chat/rocket/android/api/FileUploadingHelper.java
+21
-10
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+2
-2
FileUploadingToUrlObserver.java
.../android/service/observer/FileUploadingToUrlObserver.java
+26
-5
FileUploading.java
...cket/persistence/realm/models/internal/FileUploading.java
+1
-0
RocketChatMessageAttachmentsLayout.java
...id/widget/message/RocketChatMessageAttachmentsLayout.java
+6
-2
No files found.
app/src/main/java/chat/rocket/android/api/FileUploadingHelper.java
View file @
cf4e33d5
...
@@ -21,16 +21,14 @@ public class FileUploadingHelper extends MethodCallHelper {
...
@@ -21,16 +21,14 @@ public class FileUploadingHelper extends MethodCallHelper {
super
(
realmHelper
,
ddpClientRef
);
super
(
realmHelper
,
ddpClientRef
);
}
}
public
Task
<
JSONObject
>
uploadRequest
(
String
filename
,
long
filesize
,
String
mimeType
,
public
Task
<
JSONObject
>
upload
S3
Request
(
String
filename
,
long
filesize
,
String
mimeType
,
String
roomId
)
{
String
roomId
)
{
return
call
(
"slingshot/uploadRequest"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
return
uploadRequest
(
"rocketchat-uploads"
,
filename
,
filesize
,
mimeType
,
roomId
);
.
put
(
"rocketchat-uploads"
)
}
.
put
(
new
JSONObject
()
.
put
(
"name"
,
filename
)
public
Task
<
JSONObject
>
uploadGoogleRequest
(
String
filename
,
long
filesize
,
String
mimeType
,
.
put
(
"size"
,
filesize
)
String
roomId
)
{
.
put
(
"type"
,
mimeType
))
return
uploadRequest
(
"rocketchat-uploads-gs"
,
filename
,
filesize
,
mimeType
,
roomId
);
.
put
(
new
JSONObject
().
put
(
"rid"
,
roomId
)))
.
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
}
public
Task
<
Void
>
sendFileMessage
(
String
roomId
,
String
storageType
,
JSONObject
fileObj
)
{
public
Task
<
Void
>
sendFileMessage
(
String
roomId
,
String
storageType
,
JSONObject
fileObj
)
{
...
@@ -59,4 +57,17 @@ public class FileUploadingHelper extends MethodCallHelper {
...
@@ -59,4 +57,17 @@ public class FileUploadingHelper extends MethodCallHelper {
.
put
(
token
)
.
put
(
token
)
).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
}
private
Task
<
JSONObject
>
uploadRequest
(
String
uploadType
,
String
filename
,
long
filesize
,
String
mimeType
,
String
roomId
)
{
return
call
(
"slingshot/uploadRequest"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
uploadType
)
.
put
(
new
JSONObject
()
.
put
(
"name"
,
filename
)
.
put
(
"size"
,
filesize
)
.
put
(
"type"
,
mimeType
))
.
put
(
new
JSONObject
().
put
(
"rid"
,
roomId
)))
.
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
cf4e33d5
...
@@ -22,7 +22,7 @@ import chat.rocket.android.service.ddp.base.ActiveUsersSubscriber;
...
@@ -22,7 +22,7 @@ import chat.rocket.android.service.ddp.base.ActiveUsersSubscriber;
import
chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber
;
import
chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber
;
import
chat.rocket.android.service.ddp.base.UserDataSubscriber
;
import
chat.rocket.android.service.ddp.base.UserDataSubscriber
;
import
chat.rocket.android.service.observer.CurrentUserObserver
;
import
chat.rocket.android.service.observer.CurrentUserObserver
;
import
chat.rocket.android.service.observer.FileUploadingTo
S3
Observer
;
import
chat.rocket.android.service.observer.FileUploadingTo
Url
Observer
;
import
chat.rocket.android.service.observer.FileUploadingWithUfsObserver
;
import
chat.rocket.android.service.observer.FileUploadingWithUfsObserver
;
import
chat.rocket.android.service.observer.GcmPushRegistrationObserver
;
import
chat.rocket.android.service.observer.GcmPushRegistrationObserver
;
import
chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver
;
import
chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver
;
...
@@ -50,7 +50,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -50,7 +50,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
GetUsersOfRoomsProcedureObserver
.
class
,
GetUsersOfRoomsProcedureObserver
.
class
,
NewMessageObserver
.
class
,
NewMessageObserver
.
class
,
CurrentUserObserver
.
class
,
CurrentUserObserver
.
class
,
FileUploadingTo
S3
Observer
.
class
,
FileUploadingTo
Url
Observer
.
class
,
FileUploadingWithUfsObserver
.
class
,
FileUploadingWithUfsObserver
.
class
,
PushSettingsObserver
.
class
,
PushSettingsObserver
.
class
,
GcmPushRegistrationObserver
.
class
GcmPushRegistrationObserver
.
class
...
...
app/src/main/java/chat/rocket/android/service/observer/FileUploadingTo
S3
Observer.java
→
app/src/main/java/chat/rocket/android/service/observer/FileUploadingTo
Url
Observer.java
View file @
cf4e33d5
...
@@ -31,10 +31,10 @@ import okio.Source;
...
@@ -31,10 +31,10 @@ import okio.Source;
/**
/**
* execute file uploading and requesting sendMessage with attachment.
* execute file uploading and requesting sendMessage with attachment.
*/
*/
public
class
FileUploadingTo
S3
Observer
extends
AbstractModelObserver
<
FileUploading
>
{
public
class
FileUploadingTo
Url
Observer
extends
AbstractModelObserver
<
FileUploading
>
{
private
FileUploadingHelper
methodCall
;
private
FileUploadingHelper
methodCall
;
public
FileUploadingTo
S3
Observer
(
Context
context
,
String
hostname
,
public
FileUploadingTo
Url
Observer
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientRef
ddpClientRef
)
{
RealmHelper
realmHelper
,
DDPClientRef
ddpClientRef
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClientRef
);
super
(
context
,
hostname
,
realmHelper
,
ddpClientRef
);
methodCall
=
new
FileUploadingHelper
(
realmHelper
,
ddpClientRef
);
methodCall
=
new
FileUploadingHelper
(
realmHelper
,
ddpClientRef
);
...
@@ -43,7 +43,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
...
@@ -43,7 +43,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
// resume pending operations.
// resume pending operations.
RealmResults
<
FileUploading
>
pendingUploadRequests
=
realm
.
where
(
FileUploading
.
class
)
RealmResults
<
FileUploading
>
pendingUploadRequests
=
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
beginGroup
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
or
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GOOGLE
)
.
endGroup
()
.
findAll
();
.
findAll
();
for
(
FileUploading
req
:
pendingUploadRequests
)
{
for
(
FileUploading
req
:
pendingUploadRequests
)
{
req
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
req
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
...
@@ -56,7 +60,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
...
@@ -56,7 +60,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
.
or
()
.
or
()
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
endGroup
()
.
endGroup
()
.
beginGroup
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
or
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GOOGLE
)
.
endGroup
()
.
findAll
().
deleteAllFromRealm
();
.
findAll
().
deleteAllFromRealm
();
return
null
;
return
null
;
}).
continueWith
(
new
LogIfError
());
}).
continueWith
(
new
LogIfError
());
...
@@ -66,7 +74,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
...
@@ -66,7 +74,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
public
RealmResults
<
FileUploading
>
queryItems
(
Realm
realm
)
{
public
RealmResults
<
FileUploading
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
FileUploading
.
class
)
return
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
beginGroup
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
or
()
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GOOGLE
)
.
endGroup
()
.
findAll
();
.
findAll
();
}
}
...
@@ -91,13 +103,20 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
...
@@ -91,13 +103,20 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
final
long
filesize
=
fileUploading
.
getFilesize
();
final
long
filesize
=
fileUploading
.
getFilesize
();
final
String
mimeType
=
fileUploading
.
getMimeType
();
final
String
mimeType
=
fileUploading
.
getMimeType
();
final
Uri
fileUri
=
Uri
.
parse
(
fileUploading
.
getUri
());
final
Uri
fileUri
=
Uri
.
parse
(
fileUploading
.
getUri
());
final
String
storageType
=
fileUploading
.
getStorageType
();
realmHelper
.
executeTransaction
(
realm
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
)
)
).
onSuccessTask
(
_task
->
methodCall
.
uploadRequest
(
filename
,
filesize
,
mimeType
,
roomId
)
).
onSuccessTask
(
_task
->
{
if
(
FileUploading
.
STORAGE_TYPE_GOOGLE
.
equals
(
storageType
))
{
return
methodCall
.
uploadGoogleRequest
(
filename
,
filesize
,
mimeType
,
roomId
);
}
else
{
return
methodCall
.
uploadS3Request
(
filename
,
filesize
,
mimeType
,
roomId
);
}
}
).
onSuccessTask
(
task
->
{
).
onSuccessTask
(
task
->
{
final
JSONObject
info
=
task
.
getResult
();
final
JSONObject
info
=
task
.
getResult
();
final
String
uploadUrl
=
info
.
getString
(
"upload"
);
final
String
uploadUrl
=
info
.
getString
(
"upload"
);
...
@@ -156,7 +175,9 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
...
@@ -156,7 +175,9 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
}
}
}).
onSuccessTask
(
task
->
{
}).
onSuccessTask
(
task
->
{
String
downloadUrl
=
task
.
getResult
();
String
downloadUrl
=
task
.
getResult
();
return
methodCall
.
sendFileMessage
(
roomId
,
"s3"
,
new
JSONObject
()
String
storage
=
FileUploading
.
STORAGE_TYPE_GOOGLE
.
equals
(
storageType
)
?
storageType
:
"s3"
;
return
methodCall
.
sendFileMessage
(
roomId
,
storage
,
new
JSONObject
()
.
put
(
"_id"
,
Uri
.
parse
(
downloadUrl
).
getLastPathSegment
())
.
put
(
"_id"
,
Uri
.
parse
(
downloadUrl
).
getLastPathSegment
())
.
put
(
"type"
,
mimeType
)
.
put
(
"type"
,
mimeType
)
.
put
(
"size"
,
filesize
)
.
put
(
"size"
,
filesize
)
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/models/internal/FileUploading.java
View file @
cf4e33d5
...
@@ -23,6 +23,7 @@ public class FileUploading extends RealmObject {
...
@@ -23,6 +23,7 @@ public class FileUploading extends RealmObject {
public
static
final
String
STORAGE_TYPE_S3
=
"AmazonS3"
;
public
static
final
String
STORAGE_TYPE_S3
=
"AmazonS3"
;
public
static
final
String
STORAGE_TYPE_GRID_FS
=
"GridFS"
;
public
static
final
String
STORAGE_TYPE_GRID_FS
=
"GridFS"
;
public
static
final
String
STORAGE_TYPE_FILE_SYSTEM
=
"FileSystem"
;
public
static
final
String
STORAGE_TYPE_FILE_SYSTEM
=
"FileSystem"
;
public
static
final
String
STORAGE_TYPE_GOOGLE
=
"GoogleCloudStorage"
;
@PrimaryKey
private
String
uplId
;
@PrimaryKey
private
String
uplId
;
private
int
syncstate
;
private
int
syncstate
;
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageAttachmentsLayout.java
View file @
cf4e33d5
...
@@ -158,9 +158,13 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -158,9 +158,13 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
titleView
.
setOnClickListener
(
new
OnClickListener
()
{
titleView
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
link
));
final
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
link
));
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
view
.
getContext
().
startActivity
(
intent
);
final
Context
context
=
view
.
getContext
();
if
(
intent
.
resolveActivity
(
context
.
getPackageManager
())
!=
null
)
{
context
.
startActivity
(
intent
);
}
}
}
});
});
TextViewCompat
.
setTextAppearance
(
titleView
,
TextViewCompat
.
setTextAppearance
(
titleView
,
...
...
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