Skip to content

Commit 2d4018d

Browse files
mahibiAndyScherzinger
authored andcommitted
add user status option to account dialog (WIP)
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent 3b60fae commit 2d4018d

23 files changed

Lines changed: 1633 additions & 31 deletions

app/src/main/java/com/nextcloud/talk/api/NcApi.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
4141
import com.nextcloud.talk.models.json.signaling.SignalingOverall;
4242
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
43+
import com.nextcloud.talk.models.json.status.StatusOverall;
4344
import com.nextcloud.talk.models.json.userprofile.UserProfileFieldsOverall;
4445
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
4546

@@ -436,4 +437,13 @@ Observable<GenericOverall> notificationCalls(@Header("Authorization") String aut
436437
Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String authorization,
437438
@Url String url,
438439
@Field("lastReadMessage") int lastReadMessage);
440+
441+
/*
442+
* OCS Status API
443+
*/
444+
445+
@GET
446+
Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);
447+
448+
439449
}

app/src/main/java/com/nextcloud/talk/models/database/CapabilitiesUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static boolean hasExternalCapability(@Nullable UserEntity user, String ca
5656
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
5757
if (capabilities.getExternalCapability() != null &&
5858
capabilities.getExternalCapability().containsKey("v1")) {
59-
return capabilities.getExternalCapability().get("v1").contains("capabilityName");
59+
return capabilities.getExternalCapability().get("v1").contains(capabilityName);
6060
}
6161
} catch (IOException e) {
6262
Log.e(TAG, "Failed to get capabilities for the user");
@@ -175,6 +175,22 @@ public static boolean isReadStatusPrivate(@Nullable UserEntity user) {
175175
return false;
176176
}
177177

178+
public static boolean isUserStatusAvailable(@Nullable UserEntity user) {
179+
if (user != null && user.getCapabilities() != null) {
180+
try {
181+
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
182+
if (capabilities.getUserStatusCapability() != null &&
183+
capabilities.getUserStatusCapability().isEnabled() &&
184+
capabilities.getUserStatusCapability().isSupportsEmoji()) {
185+
return true;
186+
}
187+
} catch (IOException e) {
188+
Log.e(TAG, "Failed to get capabilities for the user");
189+
}
190+
}
191+
return false;
192+
}
193+
178194
public static String getAttachmentFolder(@Nullable UserEntity user) {
179195
if (user != null && user.getCapabilities() != null) {
180196
try {

app/src/main/java/com/nextcloud/talk/models/json/capabilities/Capabilities.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class Capabilities {
4646
@JsonField(name = "provisioning_api")
4747
ProvisioningCapability provisioningCapability;
4848

49+
@JsonField(name = "user_status")
50+
UserStatusCapability userStatusCapability;
51+
4952
public SpreedCapability getSpreedCapability() {
5053
return this.spreedCapability;
5154
}
@@ -66,6 +69,10 @@ public ProvisioningCapability getProvisioningCapability() {
6669
return this.provisioningCapability;
6770
}
6871

72+
public UserStatusCapability getUserStatusCapability() {
73+
return userStatusCapability;
74+
}
75+
6976
public void setSpreedCapability(SpreedCapability spreedCapability) {
7077
this.spreedCapability = spreedCapability;
7178
}
@@ -86,6 +93,10 @@ public void setProvisioningCapability(ProvisioningCapability provisioningCapabil
8693
this.provisioningCapability = provisioningCapability;
8794
}
8895

96+
public void setUserStatusCapability(UserStatusCapability userStatusCapability) {
97+
this.userStatusCapability = userStatusCapability;
98+
}
99+
89100
public boolean equals(final Object o) {
90101
if (o == this) {
91102
return true;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.nextcloud.talk.models.json.capabilities;
2+
3+
import com.bluelinelabs.logansquare.annotation.JsonField;
4+
import com.bluelinelabs.logansquare.annotation.JsonObject;
5+
6+
import org.parceler.Parcel;
7+
8+
@Parcel
9+
@JsonObject
10+
public class UserStatusCapability {
11+
@JsonField(name = "enabled")
12+
boolean enabled;
13+
14+
@JsonField(name = "supports_emoji")
15+
boolean supportsEmoji;
16+
17+
public boolean isEnabled() {
18+
return enabled;
19+
}
20+
21+
public void setEnabled(boolean enabled) {
22+
this.enabled = enabled;
23+
}
24+
25+
public boolean isSupportsEmoji() {
26+
return supportsEmoji;
27+
}
28+
29+
public void setSupportsEmoji(boolean supportsEmoji) {
30+
this.supportsEmoji = supportsEmoji;
31+
}
32+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
*
3+
* Nextcloud Talk application
4+
*
5+
* @author Tim Krüger
6+
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
package com.nextcloud.talk.models.json.status;
22+
23+
import com.bluelinelabs.logansquare.annotation.JsonField;
24+
import com.bluelinelabs.logansquare.annotation.JsonObject;
25+
26+
import org.parceler.Parcel;
27+
28+
import java.util.Objects;
29+
30+
@Parcel
31+
@JsonObject
32+
public class Status {
33+
34+
@JsonField(name = "userId")
35+
public String userId;
36+
37+
@JsonField(name = "message")
38+
public String message;
39+
40+
// TODO: Change to enum
41+
@JsonField(name = "messageId")
42+
public String messageId;
43+
44+
@JsonField(name = "messageIsPredefined")
45+
public boolean messageIsPredefined;
46+
47+
@JsonField(name = "icon")
48+
public String icon;
49+
50+
@JsonField(name = "clearAt")
51+
public long clearAt;
52+
53+
// TODO: Change to enum
54+
@JsonField(name = "status")
55+
public String status;
56+
57+
@JsonField(name = "statusIsUserDefined")
58+
public boolean statusIsUserDefined;
59+
60+
public String getMessage() {
61+
return message;
62+
}
63+
64+
public void setMessage(String message) {
65+
this.message = message;
66+
}
67+
68+
public String getMessageId() {
69+
return messageId;
70+
}
71+
72+
public void setMessageId(String messageId) {
73+
this.messageId = messageId;
74+
}
75+
76+
public boolean isMessageIsPredefined() {
77+
return messageIsPredefined;
78+
}
79+
80+
public void setMessageIsPredefined(boolean messageIsPredefined) {
81+
this.messageIsPredefined = messageIsPredefined;
82+
}
83+
84+
public String getIcon() {
85+
return icon;
86+
}
87+
88+
public void setIcon(String icon) {
89+
this.icon = icon;
90+
}
91+
92+
public long getClearAt() {
93+
return clearAt;
94+
}
95+
96+
public void setClearAt(long clearAt) {
97+
this.clearAt = clearAt;
98+
}
99+
100+
public String getStatus() {
101+
return status;
102+
}
103+
104+
public void setStatus(String status) {
105+
this.status = status;
106+
}
107+
108+
public boolean isStatusIsUserDefined() {
109+
return statusIsUserDefined;
110+
}
111+
112+
public void setStatusIsUserDefined(boolean statusIsUserDefined) {
113+
this.statusIsUserDefined = statusIsUserDefined;
114+
}
115+
116+
public String getUserId() {
117+
return this.userId;
118+
}
119+
120+
public void setUserId(String userId) {
121+
this.userId = userId;
122+
}
123+
124+
@Override
125+
public boolean equals(Object o) {
126+
if (this == o) {
127+
return true;
128+
}
129+
if (o == null || getClass() != o.getClass()) {
130+
return false;
131+
}
132+
Status status1 = (Status) o;
133+
return messageIsPredefined == status1.messageIsPredefined &&
134+
clearAt == status1.clearAt &&
135+
statusIsUserDefined == status1.statusIsUserDefined &&
136+
Objects.equals(userId, status1.userId) && Objects.equals(message, status1.message) &&
137+
Objects.equals(messageId, status1.messageId) && Objects.equals(icon, status1.icon) &&
138+
Objects.equals(status, status1.status);
139+
}
140+
141+
@Override
142+
public int hashCode() {
143+
return Objects.hash(userId, message, messageId, messageIsPredefined, icon, clearAt, status, statusIsUserDefined);
144+
}
145+
146+
@Override
147+
public String toString() {
148+
return "Status{" +
149+
"userId='" + userId + '\'' +
150+
", message='" + message + '\'' +
151+
", messageId='" + messageId + '\'' +
152+
", messageIsPredefined=" + messageIsPredefined +
153+
", icon='" + icon + '\'' +
154+
", clearAt=" + clearAt +
155+
", status='" + status + '\'' +
156+
", statusIsUserDefined=" + statusIsUserDefined +
157+
'}';
158+
}
159+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
*
3+
* Nextcloud Talk application
4+
*
5+
* @author Tim Krüger
6+
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
package com.nextcloud.talk.models.json.status;
22+
23+
import com.bluelinelabs.logansquare.annotation.JsonField;
24+
import com.bluelinelabs.logansquare.annotation.JsonObject;
25+
import com.nextcloud.talk.models.json.generic.GenericOCS;
26+
27+
import java.util.Objects;
28+
29+
@JsonObject
30+
public class StatusOCS extends GenericOCS {
31+
@JsonField(name = "data")
32+
public Status data;
33+
34+
public Status getData() {
35+
return this.data;
36+
}
37+
38+
public void setData(Status data) {
39+
this.data = data;
40+
}
41+
42+
@Override
43+
public boolean equals(Object o) {
44+
if (this == o) {
45+
return true;
46+
}
47+
if (o == null || getClass() != o.getClass()) {
48+
return false;
49+
}
50+
if (!super.equals(o)) {
51+
return false;
52+
}
53+
StatusOCS that = (StatusOCS) o;
54+
return Objects.equals(data, that.data);
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(super.hashCode(), data);
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return "StatusOCS{" +
65+
"data=" + data +
66+
'}';
67+
}
68+
69+
}

0 commit comments

Comments
 (0)