From 7f54dcd9f9191b5ec87627d9a2e34408f733257e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Fri, 22 Oct 2021 17:36:59 +0200 Subject: [PATCH] Replace 'mute calls' by 'call notifications' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'mute calls' setting was only stored locally on the device. The new 'call notifications' setting is stored on the Nextcloud server and shared over all devices. See: - https://github.com/nextcloud/spreed/pull/6338 Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/api/NcApi.java | 7 +++ .../controllers/ConversationInfoController.kt | 11 ++++- .../talk/jobs/NotificationWorker.java | 7 +-- .../json/conversations/Conversation.java | 42 +++++++++++------ .../com/nextcloud/talk/utils/ApiUtils.java | 6 +++ .../DatabaseStorageModule.java | 47 +++++++++++++++++++ .../res/layout/notification_settings_item.xml | 9 ++-- app/src/main/res/values/strings.xml | 3 +- 8 files changed, 105 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index a1e6e2679..334c95f71 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -4,8 +4,10 @@ * * @author Mario Danic * @author Marcel Hibbe + * @author Tim Krüger * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) * Copyright (C) 2021 Marcel Hibbe + * Copyright (C) 2021 Tim Krüger * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -418,4 +420,9 @@ public interface NcApi { @DELETE Observable clearChatHistory(@Header("Authorization") String authorization, @Url String url); + + @FormUrlEncoded + @POST + Observable notificationCalls(@Header("Authorization") String authorization, @Url String url, + @Field("level") Integer level); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt index e731785fe..873946d95 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt @@ -3,6 +3,8 @@ * * @author Mario Danic * @author Andy Scherzinger + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de) * Copyright (C) 2017-2018 Mario Danic * @@ -609,7 +611,14 @@ class ConversationInfoController(args: Bundle) : } if (Conversation.ConversationType.ROOM_SYSTEM == conversation!!.type) { - binding.notificationSettingsView.muteCalls.visibility = View.GONE + binding.notificationSettingsView.callNotifications.visibility = View.GONE + } + + if (conversation!!.notificationCalls === null) { + binding.notificationSettingsView.callNotifications.visibility = View.GONE + } else { + binding.notificationSettingsView.callNotifications.value = + conversationCopy.notificationCalls == 1 } getListOfParticipants() diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 3331881d7..587b82ae0 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -142,11 +142,6 @@ public class NotificationWorker extends Worker { ArbitraryStorageEntity arbitraryStorageEntity; - if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(), - "mute_calls", intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) { - muteCall = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); - } - if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(), "important_conversation", intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) { importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); @@ -183,6 +178,8 @@ public class NotificationWorker extends Worker { showNotification(intent); } } + + muteCall = !(conversation.notificationCalls == 1); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java index dd893b5f7..1405de884 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java @@ -3,6 +3,8 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) * * This program is free software: you can redistribute it and/or modify @@ -35,6 +37,7 @@ import com.nextcloud.talk.models.json.participants.Participant; import org.parceler.Parcel; import java.util.HashMap; +import java.util.Objects; @Parcel @JsonObject @@ -101,6 +104,9 @@ public class Conversation { @JsonField(name = "unreadMentionDirect") public Boolean unreadMentionDirect; + @JsonField(name = "notificationCalls") + public Integer notificationCalls; + public boolean isPublic() { return (ConversationType.ROOM_PUBLIC_CALL.equals(type)); } @@ -261,6 +267,8 @@ public class Conversation { return unreadMentionDirect; } + public Integer getNotificationCalls() { return notificationCalls; } + public void setRoomId(String roomId) { this.roomId = roomId; } @@ -370,6 +378,7 @@ public class Conversation { this.unreadMentionDirect = unreadMentionDirect; } + @Override public boolean equals(Object o) { if (this == o) { @@ -405,46 +414,46 @@ public class Conversation { if (callFlag != that.callFlag) { return false; } - if (roomId != null ? !roomId.equals(that.roomId) : that.roomId != null) { + if (!Objects.equals(roomId, that.roomId)) { return false; } if (!token.equals(that.token)) { return false; } - if (name != null ? !name.equals(that.name) : that.name != null) { + if (!Objects.equals(name, that.name)) { return false; } - if (displayName != null ? !displayName.equals(that.displayName) : that.displayName != null) { + if (!Objects.equals(displayName, that.displayName)) { return false; } - if (description != null ? !description.equals(that.description) : that.description != null) { + if (!Objects.equals(description, that.description)) { return false; } if (type != that.type) { return false; } - if (participants != null ? !participants.equals(that.participants) : that.participants != null) { + if (!Objects.equals(participants, that.participants)) { return false; } if (participantType != that.participantType) { return false; } - if (sessionId != null ? !sessionId.equals(that.sessionId) : that.sessionId != null) { + if (!Objects.equals(sessionId, that.sessionId)) { return false; } - if (actorId != null ? !actorId.equals(that.actorId) : that.actorId != null) { + if (!Objects.equals(actorId, that.actorId)) { return false; } - if (actorType != null ? !actorType.equals(that.actorType) : that.actorType != null) { + if (!Objects.equals(actorType, that.actorType)) { return false; } - if (password != null ? !password.equals(that.password) : that.password != null) { + if (!Objects.equals(password, that.password)) { return false; } - if (lastMessage != null ? !lastMessage.equals(that.lastMessage) : that.lastMessage != null) { + if (!Objects.equals(lastMessage, that.lastMessage)) { return false; } - if (objectType != null ? !objectType.equals(that.objectType) : that.objectType != null) { + if (!Objects.equals(objectType, that.objectType)) { return false; } if (notificationLevel != that.notificationLevel) { @@ -456,13 +465,16 @@ public class Conversation { if (lobbyState != that.lobbyState) { return false; } - if (lobbyTimer != null ? !lobbyTimer.equals(that.lobbyTimer) : that.lobbyTimer != null) { + if (!Objects.equals(lobbyTimer, that.lobbyTimer)) { return false; } - if (canLeaveConversation != null ? !canLeaveConversation.equals(that.canLeaveConversation) : that.canLeaveConversation != null) { + if (!Objects.equals(canLeaveConversation, that.canLeaveConversation)) { return false; } - return canDeleteConversation != null ? canDeleteConversation.equals(that.canDeleteConversation) : that.canDeleteConversation == null; + if (!Objects.equals(notificationCalls, that.notificationCalls)) { + return false; + } + return Objects.equals(canDeleteConversation, that.canDeleteConversation); } protected boolean canEqual(final Object other) { @@ -499,6 +511,7 @@ public class Conversation { result = 31 * result + callFlag; result = 31 * result + (canLeaveConversation != null ? canLeaveConversation.hashCode() : 0); result = 31 * result + (canDeleteConversation != null ? canDeleteConversation.hashCode() : 0); + result = 31 * result + (notificationCalls != null ? notificationCalls.hashCode() : 0); return result; } @@ -533,6 +546,7 @@ public class Conversation { ", callFlag=" + callFlag + ", canLeaveConversation=" + canLeaveConversation + ", canDeleteConversation=" + canDeleteConversation + + ", notificationCalls=" + notificationCalls + '}'; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 51b7265c5..2a0687a14 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -2,6 +2,8 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017-2018 Mario Danic * * This program is free software: you can redistribute it and/or modify @@ -234,6 +236,10 @@ public class ApiUtils { return getUrlForRoom(version, baseUrl, token) + "/webinary/lobby"; } + public static String getUrlForRoomNotificationCalls(int version, String baseUrl, String token) { + return getUrlForRoom(version, baseUrl, token) + "/notify-calls"; + } + public static String getUrlForCall(int version, String baseUrl, String token) { return getUrlForApi(version, baseUrl) + "/call/" + token; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index 6712db869..3ec3b2eb8 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -2,6 +2,8 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017-2018 Mario Danic * * This program is free software: you can redistribute it and/or modify @@ -22,6 +24,8 @@ package com.nextcloud.talk.utils.preferences.preferencestorage; import android.os.Bundle; import android.text.TextUtils; +import android.util.Log; + import autodagger.AutoInjector; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; @@ -31,22 +35,31 @@ import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils; +import com.nextcloud.talk.utils.database.user.UserUtils; import com.yarolegovich.mp.io.StorageModule; + +import org.jetbrains.annotations.NotNull; + import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import javax.inject.Inject; + +import java.util.Collections; import java.util.Set; @AutoInjector(NextcloudTalkApplication.class) public class DatabaseStorageModule implements StorageModule { + private static final String TAG = "DatabaseStorageModule"; @Inject ArbitraryStorageUtils arbitraryStorageUtils; @Inject NcApi ncApi; + private UserEntity conversationUser; private String conversationToken; private long accountIdentifier; @@ -65,6 +78,40 @@ public class DatabaseStorageModule implements StorageModule { @Override public void saveBoolean(String key, boolean value) { + if(key.equals("call_notifications")) { + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{4}); + ncApi.notificationCalls(ApiUtils.getCredentials(conversationUser.getUsername(), + conversationUser.getToken()), + ApiUtils.getUrlForRoomNotificationCalls(apiVersion, + conversationUser.getBaseUrl(), + conversationToken), + value ? 1 : 0) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NotNull Disposable d) { + + } + + @Override + public void onNext(@NotNull GenericOverall genericOverall) { + + } + + @Override + public void onError(@NotNull Throwable e) { + Log.e(TAG, "Error when trying to toggle notification calls", e); + } + + @Override + public void onComplete() { + + } + } + ); + } + if (!key.equals("conversation_lobby")) { arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, Boolean.toString(value), conversationToken); } else { diff --git a/app/src/main/res/layout/notification_settings_item.xml b/app/src/main/res/layout/notification_settings_item.xml index 85e4a7c3f..4834b4942 100644 --- a/app/src/main/res/layout/notification_settings_item.xml +++ b/app/src/main/res/layout/notification_settings_item.xml @@ -54,13 +54,12 @@ apc:mp_title="@string/nc_plain_old_messages" /> + apc:mp_default_value="true" + apc:mp_key="call_notifications" + apc:mp_title="@string/nc_call_notifications" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f14f3959..501acb52c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -231,8 +231,7 @@ Always notify Notify when mentioned Never notify - Mute calls - Incoming calls will be silenced + Call notifications Important conversation Notifications in this conversation will override Do Not Disturb settings