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
21d1e564
Commit
21d1e564
authored
Dec 13, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove stream-notify-user userId/notification subscription
parent
b5b67f3f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
168 deletions
+0
-168
Notifier.java
.../main/java/chat/rocket/android/notification/Notifier.java
+0
-8
StreamNotifyUserNotifier.java
...rocket/android/notification/StreamNotifyUserNotifier.java
+0
-113
StreamNotifyUserNotification.java
...roid/service/ddp/stream/StreamNotifyUserNotification.java
+0
-41
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+0
-6
No files found.
app/src/main/java/chat/rocket/android/notification/Notifier.java
deleted
100644 → 0
View file @
b5b67f3f
package
chat
.
rocket
.
android
.
notification
;
/**
* notifier.
*/
public
interface
Notifier
{
void
publishNotificationIfNeeded
();
}
app/src/main/java/chat/rocket/android/notification/StreamNotifyUserNotifier.java
deleted
100644 → 0
View file @
b5b67f3f
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/ddp/stream/StreamNotifyUserNotification.java
deleted
100644 → 0
View file @
b5b67f3f
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/observer/CurrentUserObserver.java
View file @
21d1e564
...
@@ -6,7 +6,6 @@ import chat.rocket.android.api.MethodCallHelper;
...
@@ -6,7 +6,6 @@ import chat.rocket.android.api.MethodCallHelper;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.service.Registerable
;
import
chat.rocket.android.service.Registerable
;
import
chat.rocket.android.service.ddp.stream.StreamNotifyUserNotification
;
import
chat.rocket.android.service.ddp.stream.StreamNotifyUserSubscriptionsChanged
;
import
chat.rocket.android.service.ddp.stream.StreamNotifyUserSubscriptionsChanged
;
import
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.Realm
;
...
@@ -67,11 +66,6 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
...
@@ -67,11 +66,6 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
}
}
return
null
;
return
null
;
});
});
Registerable
listener
=
new
StreamNotifyUserNotification
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
listener
.
register
();
listeners
.
add
(
listener
);
}
}
@DebugLog
@DebugLog
...
...
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