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
790d8fae
Commit
790d8fae
authored
Dec 10, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auth cookie header for downloading attachment images.
parent
2ed64d4b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
10 deletions
+68
-10
build.gradle
app/build.gradle
+1
-1
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+9
-1
MessageListAdapter.java
...ket/android/layouthelper/chatroom/MessageListAdapter.java
+6
-2
MessageViewHolder.java
...cket/android/layouthelper/chatroom/MessageViewHolder.java
+6
-2
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+2
-1
dependencies.gradle
dependencies.gradle
+2
-0
build.gradle
rocket-chat-android-widgets/build.gradle
+2
-0
RocketChatMessageAttachmentsLayout.java
...id/widget/message/RocketChatMessageAttachmentsLayout.java
+40
-3
No files found.
app/build.gradle
View file @
790d8fae
...
...
@@ -97,7 +97,7 @@ dependencies {
compile
'com.google.firebase:firebase-core:10.0.0'
compile
'com.google.firebase:firebase-crash:10.0.0'
compile
'com.squareup.okhttp3:okhttp:3.4.1'
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
'com.facebook.stetho:stetho:1.4.1'
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
790d8fae
...
...
@@ -23,7 +23,9 @@ import chat.rocket.android.model.ServerConfig;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.model.internal.LoadMessageProcedure
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmModelListAdapter
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
...
...
@@ -48,6 +50,8 @@ public class RoomFragment extends AbstractChatRoomFragment
private
String
roomId
;
private
RealmObjectObserver
<
RoomSubscription
>
roomObserver
;
private
String
hostname
;
private
String
userId
;
private
String
token
;
private
LoadMoreScrollListener
scrollListener
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageComposerManager
messageComposerManager
;
...
...
@@ -79,6 +83,10 @@ public class RoomFragment extends AbstractChatRoomFragment
.
equalTo
(
"serverConfigId"
,
serverConfigId
)
.
isNotNull
(
"hostname"
)
.
findFirst
()).
getHostname
();
userId
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
()).
get_id
();
token
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
).
findFirst
()).
getToken
();
roomObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
))
.
setOnUpdateListener
(
this
::
onRenderRoom
);
...
...
@@ -102,7 +110,7 @@ public class RoomFragment extends AbstractChatRoomFragment
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
"rid"
,
roomId
)
.
findAllSorted
(
"ts"
,
Sort
.
DESCENDING
),
context
->
new
MessageListAdapter
(
context
,
hostname
)
context
->
new
MessageListAdapter
(
context
,
hostname
,
userId
,
token
)
);
listView
.
setAdapter
(
adapter
);
adapter
.
setOnItemClickListener
(
this
);
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageListAdapter.java
View file @
790d8fae
...
...
@@ -15,12 +15,16 @@ import java.util.List;
public
class
MessageListAdapter
extends
ExtRealmModelListAdapter
<
Message
,
PairedMessage
,
MessageViewHolder
>
{
private
final
String
hostname
;
private
final
String
userId
;
private
final
String
token
;
private
boolean
hasNext
;
private
boolean
isLoaded
;
public
MessageListAdapter
(
Context
context
,
String
hostname
)
{
public
MessageListAdapter
(
Context
context
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
context
);
this
.
hostname
=
hostname
;
this
.
userId
=
userId
;
this
.
token
=
token
;
}
/**
...
...
@@ -53,7 +57,7 @@ public class MessageListAdapter
}
@Override
protected
MessageViewHolder
onCreateRealmModelViewHolder
(
int
viewType
,
View
itemView
)
{
return
new
MessageViewHolder
(
itemView
,
hostname
);
return
new
MessageViewHolder
(
itemView
,
hostname
,
userId
,
token
);
}
@Override
protected
List
<
PairedMessage
>
mapResultsToViewModel
(
List
<
Message
>
results
)
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageViewHolder.java
View file @
790d8fae
...
...
@@ -23,6 +23,8 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
private
final
TextView
timestamp
;
private
final
View
userAndTimeContainer
;
private
final
String
hostname
;
private
final
String
userId
;
private
final
String
token
;
private
final
RocketChatMessageLayout
body
;
private
final
RocketChatMessageUrlsLayout
urls
;
private
final
RocketChatMessageAttachmentsLayout
attachments
;
...
...
@@ -32,7 +34,7 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
/**
* constructor WITH hostname.
*/
public
MessageViewHolder
(
View
itemView
,
String
hostname
)
{
public
MessageViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
itemView
);
avatar
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
user_avatar
);
username
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
username
);
...
...
@@ -45,6 +47,8 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
newDayContainer
=
itemView
.
findViewById
(
R
.
id
.
newday_container
);
newDayText
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
newday_text
);
this
.
hostname
=
hostname
;
this
.
userId
=
userId
;
this
.
token
=
token
;
}
/**
...
...
@@ -57,7 +61,7 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
.
timestampInto
(
timestamp
)
.
bodyInto
(
body
)
.
urlsInto
(
urls
)
.
attachmentsInto
(
attachments
,
hostname
);
.
attachmentsInto
(
attachments
,
hostname
,
userId
,
token
);
if
(
pairedMessage
.
target
!=
null
)
{
int
syncstate
=
pairedMessage
.
target
.
getSyncstate
();
...
...
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
790d8fae
...
...
@@ -105,7 +105,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show urls in RocketChatMessageUrlsLayout.
*/
public
MessageRenderer
attachmentsInto
(
RocketChatMessageAttachmentsLayout
attachmentsLayout
,
String
hostname
)
{
String
hostname
,
String
userId
,
String
token
)
{
if
(!
shouldHandle
(
attachmentsLayout
))
{
return
this
;
}
...
...
@@ -116,6 +116,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
}
else
{
attachmentsLayout
.
setVisibility
(
View
.
VISIBLE
);
attachmentsLayout
.
setHostname
(
hostname
);
attachmentsLayout
.
setCredential
(
userId
,
token
);
attachmentsLayout
.
setAttachments
(
attachments
);
}
...
...
dependencies.gradle
View file @
790d8fae
...
...
@@ -17,7 +17,9 @@ ext {
rxJava
=
'io.reactivex:rxjava:1.2.2'
boltsTask
=
'com.parse.bolts:bolts-tasks:1.4.0'
timber
=
'com.jakewharton.timber:timber:4.3.1'
okhttp3
=
'com.squareup.okhttp3:okhttp:3.4.1'
picasso
=
'com.squareup.picasso:picasso:2.5.2'
picasso2Okhttp3Downloader
=
'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
}
subprojects
{
project
->
...
...
rocket-chat-android-widgets/build.gradle
View file @
790d8fae
...
...
@@ -40,5 +40,7 @@ dependencies {
compile
rootProject
.
ext
.
supportAppCompat
compile
rootProject
.
ext
.
supportDesign
compile
'org.nibor.autolink:autolink:0.5.0'
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
rootProject
.
ext
.
picasso2Okhttp3Downloader
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageAttachmentsLayout.java
View file @
790d8fae
...
...
@@ -14,7 +14,13 @@ import android.widget.LinearLayout;
import
android.widget.TextView
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
com.jakewharton.picasso.OkHttp3Downloader
;
import
com.squareup.picasso.Picasso
;
import
java.io.IOException
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -25,6 +31,10 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
private
LayoutInflater
inflater
;
private
String
hostname
;
private
String
userId
;
private
String
token
;
private
OkHttp3Downloader
downloader
;
public
RocketChatMessageAttachmentsLayout
(
Context
context
)
{
super
(
context
);
initialize
(
context
,
null
);
...
...
@@ -56,6 +66,32 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
this
.
hostname
=
hostname
;
}
public
void
setCredential
(
String
userId
,
String
token
)
{
this
.
userId
=
userId
;
this
.
token
=
token
;
}
private
OkHttp3Downloader
getDownloader
()
{
if
(
downloader
==
null
)
{
Interceptor
interceptor
=
new
Interceptor
()
{
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
// uid/token is required to download attachment files.
// see: RocketChat:lib/fileUpload.coffee
Request
newRequest
=
chain
.
request
().
newBuilder
()
.
header
(
"Cookie"
,
"rc_uid="
+
userId
+
";rc_token="
+
token
)
.
build
();
return
chain
.
proceed
(
newRequest
);
}
};
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
()
.
addInterceptor
(
interceptor
)
.
build
();
downloader
=
new
OkHttp3Downloader
(
okHttpClient
);
}
return
downloader
;
}
public
void
setAttachments
(
String
attachmentsString
)
{
removeAllViews
();
...
...
@@ -87,9 +123,10 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
View
attachmentView
=
inflater
.
inflate
(
R
.
layout
.
message_inline_attachment
,
this
,
false
);
imageURL
=
absolutize
(
imageURL
);
Picasso
.
with
(
getContext
())
.
load
(
imageURL
)
new
Picasso
.
Builder
(
getContext
())
.
downloader
(
getDownloader
())
.
build
()
.
load
(
absolutize
(
imageURL
))
.
placeholder
(
R
.
drawable
.
image_dummy
)
.
error
(
R
.
drawable
.
image_error
)
.
into
((
ImageView
)
attachmentView
.
findViewById
(
R
.
id
.
image
));
...
...
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