]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/storage/configuration/ConfigurationStore.java
ef4a4545073cf634ef512a049df1cfe3d6230c62
[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,
63 final boolean value
64 ) throws SQLException {
65 if (keyValueStore.storeEntry(connection, unidentifiedDeliveryIndicators, value)) {
66 recipientStore.rotateSelfStorageId(connection);
67 }
68 }
69
70 public Boolean getTypingIndicators() {
71 return keyValueStore.getEntry(typingIndicators);
72 }
73
74 public void setTypingIndicators(final boolean value) {
75 if (keyValueStore.storeEntry(typingIndicators, value)) {
76 recipientStore.rotateSelfStorageId();
77 }
78 }
79
80 public void setTypingIndicators(final Connection connection, final boolean value) throws SQLException {
81 if (keyValueStore.storeEntry(connection, typingIndicators, value)) {
82 recipientStore.rotateSelfStorageId(connection);
83 }
84 }
85
86 public Boolean getLinkPreviews() {
87 return keyValueStore.getEntry(linkPreviews);
88 }
89
90 public void setLinkPreviews(final boolean value) {
91 if (keyValueStore.storeEntry(linkPreviews, value)) {
92 recipientStore.rotateSelfStorageId();
93 }
94 }
95
96 public void setLinkPreviews(final Connection connection, final boolean value) throws SQLException {
97 if (keyValueStore.storeEntry(connection, linkPreviews, value)) {
98 recipientStore.rotateSelfStorageId(connection);
99 }
100 }
101
102 public Boolean getPhoneNumberUnlisted() {
103 return keyValueStore.getEntry(phoneNumberUnlisted);
104 }
105
106 public void setPhoneNumberUnlisted(final boolean value) {
107 if (keyValueStore.storeEntry(phoneNumberUnlisted, value)) {
108 recipientStore.rotateSelfStorageId();
109 }
110 }
111
112 public void setPhoneNumberUnlisted(final Connection connection, final boolean value) throws SQLException {
113 if (keyValueStore.storeEntry(connection, phoneNumberUnlisted, value)) {
114 recipientStore.rotateSelfStorageId(connection);
115 }
116 }
117
118 public PhoneNumberSharingMode getPhoneNumberSharingMode() {
119 return keyValueStore.getEntry(phoneNumberSharingMode);
120 }
121
122 public void setPhoneNumberSharingMode(final PhoneNumberSharingMode value) {
123 if (keyValueStore.storeEntry(phoneNumberSharingMode, value)) {
124 recipientStore.rotateSelfStorageId();
125 }
126 }
127
128 public void setPhoneNumberSharingMode(
129 final Connection connection,
130 final PhoneNumberSharingMode value
131 ) throws SQLException {
132 if (keyValueStore.storeEntry(connection, phoneNumberSharingMode, value)) {
133 recipientStore.rotateSelfStorageId(connection);
134 }
135 }
136
137 public String getUsernameLinkColor() {
138 return keyValueStore.getEntry(usernameLinkColor);
139 }
140
141 public void setUsernameLinkColor(final String color) {
142 if (keyValueStore.storeEntry(usernameLinkColor, color)) {
143 recipientStore.rotateSelfStorageId();
144 }
145 }
146
147 public void setUsernameLinkColor(final Connection connection, final String color) throws SQLException {
148 if (keyValueStore.storeEntry(connection, usernameLinkColor, color)) {
149 recipientStore.rotateSelfStorageId(connection);
150 }
151 }
152 }