mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 20:19:42 +01:00
Cancel existing notifications on joining room
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
2e7b0b8634
commit
f3fc375ad9
@ -79,6 +79,7 @@ import com.nextcloud.talk.models.json.rooms.RoomsOverall;
|
|||||||
import com.nextcloud.talk.presenters.MentionAutocompletePresenter;
|
import com.nextcloud.talk.presenters.MentionAutocompletePresenter;
|
||||||
import com.nextcloud.talk.utils.ApiUtils;
|
import com.nextcloud.talk.utils.ApiUtils;
|
||||||
import com.nextcloud.talk.utils.KeyboardUtils;
|
import com.nextcloud.talk.utils.KeyboardUtils;
|
||||||
|
import com.nextcloud.talk.utils.NotificationUtils;
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||||
@ -124,14 +125,12 @@ import retrofit2.Response;
|
|||||||
public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener,
|
public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener,
|
||||||
MessagesListAdapter.Formatter<Date>, MessagesListAdapter.OnMessageLongClickListener {
|
MessagesListAdapter.Formatter<Date>, MessagesListAdapter.OnMessageLongClickListener {
|
||||||
private static final String TAG = "ChatController";
|
private static final String TAG = "ChatController";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NcApi ncApi;
|
NcApi ncApi;
|
||||||
@Inject
|
@Inject
|
||||||
UserUtils userUtils;
|
UserUtils userUtils;
|
||||||
@Inject
|
@Inject
|
||||||
Cache cache;
|
Cache cache;
|
||||||
|
|
||||||
@BindView(R.id.messagesListView)
|
@BindView(R.id.messagesListView)
|
||||||
MessagesList messagesListView;
|
MessagesList messagesListView;
|
||||||
@BindView(R.id.messageInputView)
|
@BindView(R.id.messageInputView)
|
||||||
@ -157,22 +156,17 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
private int globalLastKnownFutureMessageId = -1;
|
private int globalLastKnownFutureMessageId = -1;
|
||||||
private int globalLastKnownPastMessageId = -1;
|
private int globalLastKnownPastMessageId = -1;
|
||||||
private MessagesListAdapter<ChatMessage> adapter;
|
private MessagesListAdapter<ChatMessage> adapter;
|
||||||
|
|
||||||
private CharSequence myFirstMessage;
|
private CharSequence myFirstMessage;
|
||||||
|
|
||||||
private Autocomplete mentionAutocomplete;
|
private Autocomplete mentionAutocomplete;
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
private boolean lookingIntoFuture = false;
|
private boolean lookingIntoFuture = false;
|
||||||
|
|
||||||
private int newMessagesCount = 0;
|
private int newMessagesCount = 0;
|
||||||
private Boolean startCallFromNotification = null;
|
private Boolean startCallFromNotification = null;
|
||||||
private String roomId;
|
private String roomId;
|
||||||
private boolean voiceOnly;
|
private boolean voiceOnly;
|
||||||
|
|
||||||
private boolean isFirstMessagesProcessing = true;
|
private boolean isFirstMessagesProcessing = true;
|
||||||
private boolean isHelloClicked;
|
private boolean isHelloClicked;
|
||||||
|
|
||||||
private final short VIEW_TYPE_DATE_HEADER = 130;
|
|
||||||
public ChatController(Bundle args) {
|
public ChatController(Bundle args) {
|
||||||
super(args);
|
super(args);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
@ -735,6 +729,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
List<ChatMessage> chatMessageList = chatOverall.getOcs().getData();
|
List<ChatMessage> chatMessageList = chatOverall.getOcs().getData();
|
||||||
|
|
||||||
if (isFirstMessagesProcessing) {
|
if (isFirstMessagesProcessing) {
|
||||||
|
NotificationUtils.cancelExistingNotifications(getApplicationContext(), conversationUser);
|
||||||
|
|
||||||
isFirstMessagesProcessing = false;
|
isFirstMessagesProcessing = false;
|
||||||
if (loadingProgressBar != null) {
|
if (loadingProgressBar != null) {
|
||||||
loadingProgressBar.setVisibility(View.GONE);
|
loadingProgressBar.setVisibility(View.GONE);
|
||||||
@ -834,6 +830,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
} else if (response.code() == 304 && !isFromTheFuture) {
|
} else if (response.code() == 304 && !isFromTheFuture) {
|
||||||
if (isFirstMessagesProcessing) {
|
if (isFirstMessagesProcessing) {
|
||||||
|
NotificationUtils.cancelExistingNotifications(getApplicationContext(), conversationUser);
|
||||||
|
|
||||||
isFirstMessagesProcessing = false;
|
isFirstMessagesProcessing = false;
|
||||||
loadingProgressBar.setVisibility(View.GONE);
|
loadingProgressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
@ -935,7 +933,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageLongClick(IMessage message) {
|
public void onMessageLongClick(IMessage message) {
|
||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
|
@ -24,8 +24,15 @@ import android.annotation.TargetApi;
|
|||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationChannelGroup;
|
import android.app.NotificationChannelGroup;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.service.notification.StatusBarNotification;
|
||||||
|
|
||||||
|
import com.nextcloud.talk.R;
|
||||||
|
import com.nextcloud.talk.models.database.UserEntity;
|
||||||
|
|
||||||
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
public class NotificationUtils {
|
public class NotificationUtils {
|
||||||
public static final String NOTIFICATION_CHANNEL_CALLS = "NOTIFICATION_CHANNEL_CALLS";
|
public static final String NOTIFICATION_CHANNEL_CALLS = "NOTIFICATION_CHANNEL_CALLS";
|
||||||
@ -64,4 +71,29 @@ public class NotificationUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cancelExistingNotifications(Context context, UserEntity conversationUser) {
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
|
|
||||||
|
NotificationManager notificationManager =
|
||||||
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
CRC32 crc32 = new CRC32();
|
||||||
|
String groupName = String.format(context.getResources().getString(R.string
|
||||||
|
.nc_notification_channel), conversationUser.getUserId(), conversationUser.getBaseUrl());
|
||||||
|
crc32.update(groupName.getBytes());
|
||||||
|
String crc32GroupString = Long.toString(crc32.getValue());
|
||||||
|
|
||||||
|
if (notificationManager != null) {
|
||||||
|
StatusBarNotification statusBarNotifications[] = notificationManager.getActiveNotifications();
|
||||||
|
for (StatusBarNotification statusBarNotification : statusBarNotifications) {
|
||||||
|
|
||||||
|
if (statusBarNotification.getGroupKey().equals(crc32GroupString)) {
|
||||||
|
notificationManager.cancel(statusBarNotification.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user