]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/storage/configuration/ConfigurationStore.java
558d4f86d5218f6c874f12a0121e2ca0de4cc875
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / storage / configuration / ConfigurationStore.java
1 package org.asamk.signal.manager.storage.configuration;
2
3 import org.asamk.signal.manager.api.PhoneNumberSharingMode;
4 import org.asamk.signal.manager.storage.keyValue.KeyValueEntry;
5 import org.asamk.signal.manager.storage.keyValue.KeyValueStore;
6 import org.asamk.signal.manager.storage.recipients.RecipientStore;
7
8 import java.sql.Connection;
9 import java.sql.SQLException;
10
11 public class ConfigurationStore {
12
13 private final KeyValueStore keyValueStore;
14 private final RecipientStore recipientStore;
15
16 private final KeyValueEntry<Boolean> readReceipts = new KeyValueEntry<>("config-read-receipts", Boolean.class);
17 private final KeyValueEntry<Boolean> unidentifiedDeliveryIndicators = new KeyValueEntry<>(
18 "config-unidentified-delivery-indicators",
19 Boolean.class);
20 private final KeyValueEntry<Boolean> typingIndicators = new KeyValueEntry<>("config-typing-indicators",
21 Boolean.class);
22 private final KeyValueEntry<Boolean> linkPreviews = new KeyValueEntry<>("config-link-previews", Boolean.class);
23 private final KeyValueEntry<Boolean> phoneNumberUnlisted = new KeyValueEntry<>("config-phone-number-unlisted",
24 Boolean.class);
25 private final KeyValueEntry<PhoneNumberSharingMode> phoneNumberSharingMode = new KeyValueEntry<>(
26 "config-phone-number-sharing-mode",
27 PhoneNumberSharingMode.class);
28 private final KeyValueEntry<String> usernameLinkColor = new KeyValueEntry<>("username-link-color", String.class);
29
30 public ConfigurationStore(final KeyValueStore keyValueStore, RecipientStore recipientStore) {
31 this.keyValueStore = keyValueStore;
32 this.recipientStore = recipientStore;
33 }
34
35 public Boolean getReadReceipts() {
36 return keyValueStore.getEntry(readReceipts);
37 }
38
39 public void setReadReceipts(final boolean value) {
40 if (keyValueStore.storeEntry(readReceipts, value)) {
41 recipientStore.rotateSelfStorageId();
42 }
43 }
44
45 public void setReadReceipts(final Connection connection, final boolean value) throws SQLException {
46 if (keyValueStore.storeEntry(connection, readReceipts, value)) {
47 recipientStore.rotateSelfStorageId(connection);
48 }
49 }
50
51 public Boolean getUnidentifiedDeliveryIndicators() {
52 return keyValueStore.getEntry(unidentifiedDeliveryIndicators);
53 }
54
55 public void setUnidentifiedDeliveryIndicators(final boolean value) {
56 if (keyValueStore.storeEntry(unidentifiedDeliveryIndicators, value)) {
57 recipientStore.rotateSelfStorageId();
58 }
59 }
60
61 public void setUnidentifiedDeliveryIndicators(
62 final Connection connection, final boolean value
63 ) throws SQLException {
64 if (keyValueStore.storeEntry(connection, unidentifiedDeliveryIndicators, value)) {
65 recipientStore.rotateSelfStorageId(connection);
66 }
67 }
68
69 public Boolean getTypingIndicators() {
70 return keyValueStore.getEntry(typingIndicators);
71 }
72
73 public void setTypingIndicators(final boolean value) {
74 if (keyValueStore.storeEntry(typingIndicators, value)) {
75 recipientStore.rotateSelfStorageId();
76 }
77 }
78
79 public void setTypingIndicators(final Connection connection, final boolean value) throws SQLException {
80 if (keyValueStore.storeEntry(connection, typingIndicators, value)) {
81 recipientStore.rotateSelfStorageId(connection);
82 }
83 }
84
85 public Boolean getLinkPreviews() {
86 return keyValueStore.getEntry(linkPreviews);
87 }
88
89 public void setLinkPreviews(final boolean value) {
90 if (keyValueStore.storeEntry(linkPreviews, value)) {
91 recipientStore.rotateSelfStorageId();
92 }
93 }
94
95 public void setLinkPreviews(final Connection connection, final boolean value) throws SQLException {
96 if (keyValueStore.storeEntry(connection, linkPreviews, value)) {
97 recipientStore.rotateSelfStorageId(connection);
98 }
99 }
100
101 public Boolean getPhoneNumberUnlisted() {
102 return keyValueStore.getEntry(phoneNumberUnlisted);
103 }
104
105 public void setPhoneNumberUnlisted(final boolean value) {
106 if (keyValueStore.storeEntry(phoneNumberUnlisted, value)) {
107 recipientStore.rotateSelfStorageId();
108 }
109 }
110
111 public void setPhoneNumberUnlisted(final Connection connection, final boolean value) throws SQLException {
112 if (keyValueStore.storeEntry(connection, phoneNumberUnlisted, value)) {
113 recipientStore.rotateSelfStorageId(connection);
114 }
115 }
116
117 public PhoneNumberSharingMode getPhoneNumberSharingMode() {
118 return keyValueStore.getEntry(phoneNumberSharingMode);
119 }
120
121 public void setPhoneNumberSharingMode(final PhoneNumberSharingMode value) {
122 if (keyValueStore.storeEntry(phoneNumberSharingMode, value)) {
123 recipientStore.rotateSelfStorageId();
124 }
125 }
126
127 public void setPhoneNumberSharingMode(
128 final Connection connection, final PhoneNumberSharingMode value
129 ) throws SQLException {
130 if (keyValueStore.storeEntry(connection, phoneNumberSharingMode, value)) {
131 recipientStore.rotateSelfStorageId(connection);
132 }
133 }
134
135 public String getUsernameLinkColor() {
136 return keyValueStore.getEntry(usernameLinkColor);
137 }
138
139 public void setUsernameLinkColor(final String color) {
140 if (keyValueStore.storeEntry(usernameLinkColor, color)) {
141 recipientStore.rotateSelfStorageId();
142 }
143 }
144
145 public void setUsernameLinkColor(final Connection connection, final String color) throws SQLException {
146 if (keyValueStore.storeEntry(connection, usernameLinkColor, color)) {
147 recipientStore.rotateSelfStorageId(connection);
148 }
149 }
150 }