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
a0af78fd
Commit
a0af78fd
authored
Dec 11, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Plain Diff
FIX #72 Merge branch 'stream-notify-user-notification' into develop
parents
7c464ecc
c69e62f5
Changes
27
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
391 additions
and
85 deletions
+391
-85
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+21
-0
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+64
-0
ViewDataCache.java
...c/main/java/chat/rocket/android/helper/ViewDataCache.java
+0
-1
Notifier.java
.../main/java/chat/rocket/android/notification/Notifier.java
+8
-0
StreamNotifyUserNotifier.java
...rocket/android/notification/StreamNotifyUserNotifier.java
+113
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+6
-2
AbstractDDPDocEventSubscriber.java
...et/android/service/ddp/AbstractDDPDocEventSubscriber.java
+4
-2
AbstractBaseSubscriber.java
...cket/android/service/ddp/base/AbstractBaseSubscriber.java
+2
-2
ActiveUsersSubscriber.java
...ocket/android/service/ddp/base/ActiveUsersSubscriber.java
+2
-2
LoginServiceConfigurationSubscriber.java
...service/ddp/base/LoginServiceConfigurationSubscriber.java
+3
-3
UserDataSubscriber.java
...t/rocket/android/service/ddp/base/UserDataSubscriber.java
+2
-2
AbstractStreamNotifyEventSubscriber.java
...rvice/ddp/stream/AbstractStreamNotifyEventSubscriber.java
+39
-17
AbstractStreamNotifyUserEventSubscriber.java
...e/ddp/stream/AbstractStreamNotifyUserEventSubscriber.java
+24
-0
StreamNotifyUserNotification.java
...roid/service/ddp/stream/StreamNotifyUserNotification.java
+41
-0
StreamNotifyUserSubscriptionsChanged.java
...vice/ddp/stream/StreamNotifyUserSubscriptionsChanged.java
+6
-17
StreamRoomMessage.java
.../rocket/android/service/ddp/stream/StreamRoomMessage.java
+5
-8
StreamRoomMessageManager.java
...et/android/service/internal/StreamRoomMessageManager.java
+5
-3
AbstractModelObserver.java
...ocket/android/service/observer/AbstractModelObserver.java
+4
-2
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+10
-4
GetUsersOfRoomsProcedureObserver.java
...id/service/observer/GetUsersOfRoomsProcedureObserver.java
+3
-3
LoadMessageProcedureObserver.java
...ndroid/service/observer/LoadMessageProcedureObserver.java
+3
-3
MethodCallObserver.java
...t/rocket/android/service/observer/MethodCallObserver.java
+3
-2
NewMessageObserver.java
...t/rocket/android/service/observer/NewMessageObserver.java
+3
-3
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+4
-3
TokenLoginObserver.java
...t/rocket/android/service/observer/TokenLoginObserver.java
+3
-2
rocket_chat_notification_24dp.xml
app/src/main/res/drawable/rocket_chat_notification_24dp.xml
+12
-0
dimens.xml
app/src/main/res/values/dimens.xml
+1
-4
No files found.
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
a0af78fd
package
chat
.
rocket
.
android
.
activity
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.model.ServerConfig
;
...
...
@@ -34,6 +36,25 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
}
};
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
if
(
savedInstanceState
==
null
)
{
Intent
intent
=
getIntent
();
if
(
intent
!=
null
)
{
if
(
intent
.
hasExtra
(
"serverConfigId"
))
{
SharedPreferences
.
Editor
editor
=
RocketChatCache
.
get
(
this
).
edit
();
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
,
intent
.
getStringExtra
(
"serverConfigId"
));
if
(
intent
.
hasExtra
(
"roomId"
))
{
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
intent
.
getStringExtra
(
"roomId"
));
}
editor
.
apply
();
}
}
}
}
private
void
updateServerConfigIdIfNeeded
(
SharedPreferences
prefs
)
{
String
newServerConfigId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
,
null
);
if
(
serverConfigId
==
null
)
{
...
...
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
a0af78fd
package
chat
.
rocket
.
android
.
helper
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.widget.ImageView
;
import
bolts.Task
;
import
bolts.TaskCompletionSource
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Target
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
timber.log.Timber
;
import
static
android
.
R
.
attr
.
bitmap
;
/**
* Helper for rendering user avatar image.
*/
...
...
@@ -85,4 +95,58 @@ public class Avatar {
.
endConfig
()
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
);
}
public
Task
<
Bitmap
>
getBitmap
(
Context
context
,
int
size
)
{
TaskCompletionSource
<
Bitmap
>
task
=
new
TaskCompletionSource
<>();
// Picasso can be triggered only on Main Thread.
if
(
Looper
.
myLooper
()
!=
Looper
.
getMainLooper
())
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
{
getBitmap
(
context
,
size
).
continueWith
(
_task
->
{
if
(
_task
.
isFaulted
())
{
task
.
setError
(
_task
.
getError
());
}
else
{
task
.
setResult
(
_task
.
getResult
());
}
return
null
;
});
});
return
task
.
getTask
();
}
Picasso
.
with
(
context
)
.
load
(
getImageUrl
())
.
error
(
getTextDrawable
(
context
))
.
into
(
new
Target
()
{
@Override
public
void
onBitmapLoaded
(
Bitmap
bitmap
,
Picasso
.
LoadedFrom
from
)
{
if
(
bitmap
!=
null
)
{
task
.
trySetResult
(
bitmap
);
}
}
@Override
public
void
onBitmapFailed
(
Drawable
errorDrawable
)
{
task
.
trySetResult
(
drawableToBitmap
(
errorDrawable
,
size
));
}
@Override
public
void
onPrepareLoad
(
Drawable
placeHolderDrawable
)
{
}
});
return
task
.
getTask
();
}
private
static
Bitmap
drawableToBitmap
(
Drawable
drawable
,
int
size
)
{
if
(
drawable
instanceof
BitmapDrawable
)
{
BitmapDrawable
bitmapDrawable
=
(
BitmapDrawable
)
drawable
;
if
(
bitmapDrawable
.
getBitmap
()
!=
null
)
{
return
bitmapDrawable
.
getBitmap
();
}
}
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
drawable
.
setBounds
(
0
,
0
,
canvas
.
getWidth
(),
canvas
.
getHeight
());
drawable
.
draw
(
canvas
);
return
bitmap
;
}
}
app/src/main/java/chat/rocket/android/helper/ViewDataCache.java
View file @
a0af78fd
...
...
@@ -11,7 +11,6 @@ public class ViewDataCache {
/**
* stores str if not stored. returns true if already stored.
*/
@DebugLog
public
static
boolean
isStored
(
String
str
,
View
view
)
{
if
(
view
.
getTag
()
!=
null
&&
view
.
getTag
()
instanceof
String
&&
((
String
)
view
.
getTag
()).
equals
(
str
))
{
...
...
app/src/main/java/chat/rocket/android/notification/Notifier.java
0 → 100644
View file @
a0af78fd
package
chat
.
rocket
.
android
.
notification
;
/**
* notifier.
*/
public
interface
Notifier
{
void
publishNotificationIfNeeded
();
}
app/src/main/java/chat/rocket/android/notification/StreamNotifyUserNotifier.java
0 → 100644
View file @
a0af78fd
package
chat
.
rocket
.
android
.
notification
;
import
android.app.Notification
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationManagerCompat
;
import
android.support.v4.content.ContextCompat
;
import
bolts.Task
;
import
chat.rocket.android.R
;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* utility class for notification.
*/
public
class
StreamNotifyUserNotifier
implements
Notifier
{
private
final
Context
context
;
private
final
String
hostname
;
private
final
String
title
;
private
final
String
text
;
private
final
JSONObject
payload
;
public
StreamNotifyUserNotifier
(
Context
context
,
String
hostname
,
String
title
,
String
text
,
JSONObject
payload
)
{
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
title
=
title
;
this
.
text
=
text
;
this
.
payload
=
payload
;
}
@Override
public
void
publishNotificationIfNeeded
()
{
if
(!
shouldNotify
())
{
return
;
}
generateNotificationAsync
().
onSuccess
(
task
->
{
NotificationManagerCompat
.
from
(
context
)
.
notify
(
generateNotificationId
(),
task
.
getResult
());
return
null
;
});
}
private
boolean
shouldNotify
()
{
// TODO: should check if target message is already read or not.
return
true
;
}
private
int
generateNotificationId
()
{
// TODO: should summary notification by user or room.
return
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
);
}
private
Task
<
Notification
>
generateNotificationAsync
()
{
int
size
=
context
.
getResources
().
getDimensionPixelSize
(
R
.
dimen
.
notification_avatar_size
);
return
getUsername
()
.
onSuccessTask
(
task
->
new
Avatar
(
hostname
,
task
.
getResult
()).
getBitmap
(
context
,
size
))
.
continueWithTask
(
task
->
{
Bitmap
icon
=
task
.
isFaulted
()
?
null
:
task
.
getResult
();
return
Task
.
forResult
(
generateNotification
(
icon
));
});
}
private
Task
<
String
>
getUsername
()
{
try
{
return
Task
.
forResult
(
payload
.
getJSONObject
(
"sender"
).
getString
(
"username"
));
}
catch
(
Exception
exception
)
{
return
Task
.
forError
(
exception
);
}
}
private
Notification
generateNotification
(
Bitmap
largeIcon
)
{
Intent
intent
=
new
Intent
(
context
,
MainActivity
.
class
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"hostname"
,
hostname
).
findFirst
());
if
(
config
!=
null
)
{
intent
.
putExtra
(
"serverConfigId"
,
config
.
getServerConfigId
());
try
{
intent
.
putExtra
(
"roomId"
,
payload
.
getString
(
"rid"
));
}
catch
(
JSONException
exception
)
{
}
}
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
context
.
getApplicationContext
(),
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
),
intent
,
PendingIntent
.
FLAG_ONE_SHOT
);
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
.
setContentTitle
(
title
)
.
setContentText
(
text
)
.
setAutoCancel
(
true
)
.
setColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorPrimary
))
.
setSmallIcon
(
R
.
drawable
.
rocket_chat_notification_24dp
)
.
setContentIntent
(
pendingIntent
);
if
(
largeIcon
!=
null
)
{
builder
.
setLargeIcon
(
largeIcon
);
}
if
(
text
.
length
()
>
20
)
{
return
new
NotificationCompat
.
BigTextStyle
(
builder
)
.
bigText
(
text
)
.
build
();
}
else
{
return
builder
.
build
();
}
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
a0af78fd
...
...
@@ -209,11 +209,15 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
listenersRegistered
=
true
;
final
ServerConfig
config
=
defaultRealm
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
final
String
hostname
=
config
.
getHostname
();
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
try
{
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
RealmHelper
.
class
,
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
String
.
class
,
RealmHelper
.
class
,
DDPClientWraper
.
class
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
serverConfigRealm
,
ddpClient
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
hostname
,
serverConfigRealm
,
ddpClient
);
if
(
obj
instanceof
Registerable
)
{
Registerable
registerable
=
(
Registerable
)
obj
;
...
...
app/src/main/java/chat/rocket/android/service/ddp/AbstractDDPDocEventSubscriber.java
View file @
a0af78fd
...
...
@@ -18,14 +18,16 @@ import timber.log.Timber;
public
abstract
class
AbstractDDPDocEventSubscriber
implements
Registerable
{
protected
final
Context
context
;
protected
final
String
hostname
;
protected
final
RealmHelper
realmHelper
;
protected
final
DDPClientWraper
ddpClient
;
private
String
subscriptionId
;
private
Subscription
rxSubscription
;
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
}
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/AbstractBaseSubscriber.java
View file @
a0af78fd
...
...
@@ -7,9 +7,9 @@ import chat.rocket.android.service.ddp.AbstractDDPDocEventSubscriber;
import
org.json.JSONArray
;
abstract
class
AbstractBaseSubscriber
extends
AbstractDDPDocEventSubscriber
{
protected
AbstractBaseSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractBaseSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
protected
final
JSONArray
getSubscriptionParams
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/ActiveUsersSubscriber.java
View file @
a0af78fd
...
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* "activeUsers" subscriber.
*/
public
class
ActiveUsersSubscriber
extends
AbstractBaseSubscriber
{
public
ActiveUsersSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
public
ActiveUsersSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/LoginServiceConfigurationSubscriber.java
View file @
a0af78fd
...
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* meteor.loginServiceConfiguration subscriber
*/
public
class
LoginServiceConfigurationSubscriber
extends
AbstractBaseSubscriber
{
public
LoginServiceConfigurationSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
LoginServiceConfigurationSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/UserDataSubscriber.java
View file @
a0af78fd
...
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* "userData" subscriber.
*/
public
class
UserDataSubscriber
extends
AbstractBaseSubscriber
{
public
UserDataSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
public
UserDataSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/AbstractStreamNotifyEventSubscriber.java
View file @
a0af78fd
...
...
@@ -7,13 +7,14 @@ import chat.rocket.android.realm_helper.RealmHelper;
import
chat.rocket.android.service.ddp.AbstractDDPDocEventSubscriber
;
import
chat.rocket.android_ddp.DDPSubscription
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
abstract
class
AbstractStreamNotifyEventSubscriber
extends
AbstractDDPDocEventSubscriber
{
protected
AbstractStreamNotifyEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
protected
AbstractStreamNotifyEventSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
protected
final
boolean
shouldTruncateTableOnInitialize
()
{
...
...
@@ -24,11 +25,35 @@ abstract class AbstractStreamNotifyEventSubscriber extends AbstractDDPDocEventSu
return
getSubscriptionName
().
equals
(
callbackName
);
}
protected
abstract
String
getSubscriptionParam
();
@Override
protected
final
JSONArray
getSubscriptionParams
()
throws
JSONException
{
return
new
JSONArray
().
put
(
getSubscriptionParam
()).
put
(
false
);
}
protected
abstract
String
getPrimaryKeyForModel
();
@Override
protected
void
onDocumentChanged
(
DDPSubscription
.
Changed
docEvent
)
{
@Override
protected
final
void
onDocumentAdded
(
DDPSubscription
.
Added
docEvent
)
{
// do nothing.
}
@Override
protected
final
void
onDocumentRemoved
(
DDPSubscription
.
Removed
docEvent
)
{
// do nothing.
}
@Override
protected
final
void
onDocumentChanged
(
DDPSubscription
.
Changed
docEvent
)
{
try
{
JSONArray
args
=
docEvent
.
fields
.
getJSONArray
(
"args"
);
if
(!
docEvent
.
fields
.
getString
(
"eventName"
).
equals
(
getSubscriptionParam
()))
{
return
;
}
handleArgs
(
docEvent
.
fields
.
getJSONArray
(
"args"
));
}
catch
(
Exception
exception
)
{
Timber
.
w
(
exception
,
"failed to save stream-notify event."
);
}
}
protected
void
handleArgs
(
JSONArray
args
)
throws
JSONException
{
String
msg
=
args
.
length
()
>
0
?
args
.
getString
(
0
)
:
null
;
JSONObject
target
=
args
.
getJSONObject
(
args
.
length
()
-
1
);
if
(
"removed"
.
equals
(
msg
))
{
...
...
@@ -42,8 +67,5 @@ abstract class AbstractStreamNotifyEventSubscriber extends AbstractDDPDocEventSu
realm
.
createOrUpdateObjectFromJson
(
getModelClass
(),
customizeFieldJson
(
target
))
).
continueWith
(
new
LogcatIfError
());
}
}
catch
(
Exception
exception
)
{
Timber
.
w
(
exception
,
"failed to save stream-notify event."
);
}
}
}
app/src/main/java/chat/rocket/android/service/ddp/stream/AbstractStreamNotifyUserEventSubscriber.java
0 → 100644
View file @
a0af78fd
package
chat
.
rocket
.
android
.
service
.
ddp
.
stream
;
import
android.content.Context
;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
abstract
class
AbstractStreamNotifyUserEventSubscriber
extends
AbstractStreamNotifyEventSubscriber
{
protected
final
String
userId
;
protected
AbstractStreamNotifyUserEventSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
this
.
userId
=
userId
;
}
@Override
protected
final
String
getSubscriptionName
()
{
return
"stream-notify-user"
;
}
@Override
protected
final
String
getSubscriptionParam
()
{
return
userId
+
"/"
+
getSubscriptionSubParam
();
}
protected
abstract
String
getSubscriptionSubParam
();
}
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamNotifyUserNotification.java
0 → 100644
View file @
a0af78fd
package
chat
.
rocket
.
android
.
service
.
ddp
.
stream
;
import
android.content.Context
;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.notification.Notifier
;
import
chat.rocket.android.notification.StreamNotifyUserNotifier
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
io.realm.RealmObject
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
StreamNotifyUserNotification
extends
AbstractStreamNotifyUserEventSubscriber
{
public
StreamNotifyUserNotification
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
}
@Override
protected
String
getSubscriptionSubParam
()
{
return
"notification"
;
}
@Override
protected
void
handleArgs
(
JSONArray
args
)
throws
JSONException
{
JSONObject
target
=
args
.
getJSONObject
(
args
.
length
()
-
1
);
Notifier
notifier
=
new
StreamNotifyUserNotifier
(
context
,
hostname
,
target
.
getString
(
"title"
),
target
.
getString
(
"text"
),
target
.
getJSONObject
(
"payload"
));
notifier
.
publishNotificationIfNeeded
();
}
@Override
protected
Class
<?
extends
RealmObject
>
getModelClass
()
{
// not used because handleArgs is override.
return
null
;
}
@Override
protected
String
getPrimaryKeyForModel
()
{
// not used because handleArgs is override.
return
null
;
}
}
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamNotifyUserSubscriptionsChanged.java
View file @
a0af78fd
...
...
@@ -5,26 +5,15 @@ import chat.rocket.android.api.DDPClientWraper;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
io.realm.RealmObject
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
public
class
StreamNotifyUserSubscriptionsChanged
extends
AbstractStreamNotifyEventSubscriber
{
private
final
String
userId
;
public
StreamNotifyUserSubscriptionsChanged
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
realmHelper
,
ddpClient
);
this
.
userId
=
userId
;
}
@Override
protected
String
getSubscriptionName
()
{
return
"stream-notify-user"
;
public
class
StreamNotifyUserSubscriptionsChanged
extends
AbstractStreamNotifyUserEventSubscriber
{
public
StreamNotifyUserSubscriptionsChanged
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
}
@Override
protected
JSONArray
getSubscriptionParams
()
throws
JSONException
{
return
new
JSONArray
()
.
put
(
userId
+
"/subscriptions-changed"
)
.
put
(
false
);
@Override
protected
String
getSubscriptionSubParam
()
{
return
"subscriptions-changed"
;
}
@Override
protected
Class
<?
extends
RealmObject
>
getModelClass
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamRoomMessage.java
View file @
a0af78fd
...
...
@@ -5,7 +5,6 @@ import chat.rocket.android.api.DDPClientWraper;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
io.realm.RealmObject
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -15,9 +14,9 @@ import org.json.JSONObject;
public
class
StreamRoomMessage
extends
AbstractStreamNotifyEventSubscriber
{
private
String
roomId
;
public
StreamRoomMessage
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
roomId
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
StreamRoomMessage
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
roomId
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
this
.
roomId
=
roomId
;
}
...
...
@@ -25,10 +24,8 @@ public class StreamRoomMessage extends AbstractStreamNotifyEventSubscriber {
return
"stream-room-messages"
;
}
@Override
protected
JSONArray
getSubscriptionParams
()
throws
JSONException
{
return
new
JSONArray
()
.
put
(
roomId
)
.
put
(
false
);
@Override
protected
String
getSubscriptionParam
()
{
return
roomId
;
}
@Override
protected
Class
<?
extends
RealmObject
>
getModelClass
()
{
...
...
app/src/main/java/chat/rocket/android/service/internal/StreamRoomMessageManager.java
View file @
a0af78fd
...
...
@@ -15,14 +15,16 @@ public class StreamRoomMessageManager implements Registerable {
private
StreamRoomMessage
streamRoomMessage
;
private
final
Context
context
;
private
final
String
hostname
;
private
final
RealmHelper
realmHelper
;
private
final
DDPClientWraper
ddpClient
;
private
final
AbstractRocketChatCacheObserver
cacheObserver
;
private
final
Handler
handler
;
public
StreamRoomMessageManager
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
public
StreamRoomMessageManager
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
...
...
@@ -37,7 +39,7 @@ public class StreamRoomMessageManager implements Registerable {
private
void
registerStreamNotifyMessage
(
String
roomId
)
{
handler
.
post
(()
->
{
streamRoomMessage
=
new
StreamRoomMessage
(
context
,
realmHelper
,
ddpClient
,
roomId
);
streamRoomMessage
=
new
StreamRoomMessage
(
context
,
hostname
,
realmHelper
,
ddpClient
,
roomId
);
streamRoomMessage
.
register
();
});
}
...
...
app/src/main/java/chat/rocket/android/service/observer/AbstractModelObserver.java
View file @
a0af78fd
...
...
@@ -11,13 +11,15 @@ abstract class AbstractModelObserver<T extends RealmObject>
implements
Registerable
,
RealmListObserver
.
Query
<
T
>,
RealmListObserver
.
OnUpdateListener
<
T
>
{
protected
final
Context
context
;
protected
final
String
hostname
;
protected
final
RealmHelper
realmHelper
;
protected
final
DDPClientWraper
ddpClient
;
private
final
RealmListObserver
observer
;
protected
AbstractModelObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
protected
AbstractModelObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
observer
=
realmHelper
.
createListObserver
(
this
).
setOnUpdateListener
(
this
);
...
...
app/src/main/java/chat/rocket/android/service/observer/CurrentUserObserver.java
View file @
a0af78fd
...
...
@@ -6,6 +6,7 @@ import chat.rocket.android.api.MethodCallHelper;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.service.Registerable
;
import
chat.rocket.android.service.ddp.stream.StreamNotifyUserNotification
;
import
chat.rocket.android.service.ddp.stream.StreamNotifyUserSubscriptionsChanged
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
...
...
@@ -23,9 +24,9 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
private
ArrayList
<
Registerable
>
listeners
;
public
CurrentUserObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
CurrentUserObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
currentUserExists
=
false
;
}
...
...
@@ -59,11 +60,16 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
Registerable
listener
=
new
StreamNotifyUserSubscriptionsChanged
(
context
,
realmHelper
,
ddpClient
,
userId
);
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
listener
.
register
();
listeners
.
add
(
listener
);
return
null
;
});
Registerable
listener
=
new
StreamNotifyUserNotification
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
listener
.
register
();
listeners
.
add
(
listener
);
}
@DebugLog
...
...
app/src/main/java/chat/rocket/android/service/observer/GetUsersOfRoomsProcedureObserver.java
View file @
a0af78fd
...
...
@@ -21,9 +21,9 @@ public class GetUsersOfRoomsProcedureObserver
private
final
MethodCallHelper
methodCall
;
public
GetUsersOfRoomsProcedureObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
GetUsersOfRoomsProcedureObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
...
...
app/src/main/java/chat/rocket/android/service/observer/LoadMessageProcedureObserver.java
View file @
a0af78fd
...
...
@@ -22,9 +22,9 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
private
final
MethodCallHelper
methodCall
;
public
LoadMessageProcedureObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
LoadMessageProcedureObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
...
...
app/src/main/java/chat/rocket/android/service/observer/MethodCallObserver.java
View file @
a0af78fd
...
...
@@ -23,8 +23,9 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
/**
* constructor.
*/
public
MethodCallObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
MethodCallObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
MethodCall
>
pendingMethodCalls
=
realm
.
where
(
MethodCall
.
class
)
...
...
app/src/main/java/chat/rocket/android/service/observer/NewMessageObserver.java
View file @
a0af78fd
...
...
@@ -20,9 +20,9 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
private
final
MethodCallHelper
methodCall
;
public
NewMessageObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
NewMessageObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
realmHelper
.
executeTransaction
(
realm
->
{
...
...
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
a0af78fd
...
...
@@ -25,11 +25,12 @@ public class SessionObserver extends AbstractModelObserver<Session> {
/**
* constructor.
*/
public
SessionObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
SessionObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
count
=
0
;
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
realmHelper
,
ddpClient
);
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
...
...
app/src/main/java/chat/rocket/android/service/observer/TokenLoginObserver.java
View file @
a0af78fd
...
...
@@ -14,8 +14,9 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
private
final
MethodCallHelper
methodCall
;
public
TokenLoginObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
public
TokenLoginObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
...
...
app/src/main/res/drawable/rocket_chat_notification_24dp.xml
0 → 100644
View file @
a0af78fd
<vector
android:height=
"24dp"
android:viewportHeight=
"48.0"
android:viewportWidth=
"48.0"
android:width=
"24dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<path
android:fillColor=
"#A3000000"
android:pathData=
"M44.99,23.47C44.99,21.42 44.38,19.45 43.16,17.62C42.07,15.97 40.54,14.52 38.62,13.29C34.91,10.92 30.03,9.62 24.88,9.62C23.16,9.62 21.47,9.77 19.82,10.05C18.8,9.1 17.61,8.24 16.35,7.57C9.6,4.3 4,7.49 4,7.49C4,7.49 9.21,11.76 8.36,15.49C6.03,17.8 4.77,20.58 4.77,23.47C4.77,23.48 4.77,23.49 4.77,23.5C4.77,23.51 4.77,23.51 4.77,23.52C4.77,26.42 6.03,29.2 8.36,31.5C9.21,35.24 4,39.5 4,39.5C4,39.5 9.6,42.69 16.35,39.43C17.61,38.75 18.8,37.89 19.82,36.94C21.47,37.23 23.16,37.37 24.88,37.37C30.03,37.37 34.91,36.07 38.62,33.7C40.54,32.48 42.07,31.02 43.16,29.38C44.38,27.55 44.99,25.58 44.99,23.53C44.99,23.52 44.99,23.51 44.99,23.5L44.99,23.47ZM24.88,12.53C34.41,12.53 42.14,17.45 42.14,23.52C42.14,29.6 34.41,34.52 24.88,34.52C22.76,34.52 20.73,34.28 18.85,33.83C16.94,36.12 12.74,39.31 8.67,38.28C9.99,36.86 11.96,34.45 11.54,30.5C9.09,28.6 7.63,26.17 7.63,23.52C7.63,17.45 15.35,12.53 24.88,12.53Z"
android:strokeColor=
"#00000000"
android:strokeWidth=
"1"
/>
<path
android:fillColor=
"#A3000000"
android:pathData=
"M24.88,26.17C26.15,26.17 27.17,25.14 27.17,23.88C27.17,22.61 26.15,21.59 24.88,21.59C23.62,21.59 22.59,22.61 22.59,23.88C22.59,25.14 23.62,26.17 24.88,26.17ZM32.85,26.17C34.12,26.17 35.14,25.14 35.14,23.88C35.14,22.61 34.12,21.59 32.85,21.59C31.59,21.59 30.56,22.61 30.56,23.88C30.56,25.14 31.59,26.17 32.85,26.17ZM16.91,26.17C18.18,26.17 19.2,25.14 19.2,23.88C19.2,22.62 18.18,21.59 16.91,21.59C15.65,21.59 14.62,22.62 14.62,23.88C14.62,25.14 15.65,26.17 16.91,26.17L16.91,26.17Z"
android:strokeColor=
"#00000000"
android:strokeWidth=
"1"
/>
<path
android:fillColor=
"#33000000"
android:pathData=
"M24.88,33.08C22.76,33.08 20.73,32.86 18.85,32.48C17.17,34.23 13.69,36.59 10.1,36.5C9.62,37.22 9.11,37.8 8.67,38.28C12.74,39.31 16.94,36.12 18.85,33.83C20.73,34.28 22.76,34.52 24.88,34.52C34.34,34.52 42.01,29.68 42.13,23.67C42.01,28.88 34.34,33.08 24.88,33.08L24.88,33.08Z"
android:strokeColor=
"#00000000"
android:strokeWidth=
"1"
/>
</vector>
app/src/main/res/values/dimens.xml
View file @
a0af78fd
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name=
"avatar_image_size_normal"
>
24dp
</dimen>
<dimen
name=
"avatar_image_size_large"
>
48dp
</dimen>
<dimen
name=
"avatar_text_size_normal"
>
11sp
</dimen>
<dimen
name=
"avatar_text_size_large"
>
28sp
</dimen>
<dimen
name=
"notification_avatar_size"
>
48dp
</dimen>
</resources>
\ No newline at end of file
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