Skip to content

Commit bcbd2be

Browse files
rafaelmf3Rafael Marinho
andauthored
[CHA-649]: feature(CHA-769): add shared locations support (#182)
* feature(CHA-769): add shared locations support * format * fix model * fix import * fix model * fix model and test * fix tests * format * add test get active live locations from query channels * feat(cha-769): change url name * fix unit tests * clean up --------- Co-authored-by: Rafael Marinho <rafael.marinho@getstream.io>
1 parent b8669b4 commit bcbd2be

File tree

6 files changed

+451
-0
lines changed

6 files changed

+451
-0
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
4242
compileOnly 'org.projectlombok:lombok:1.18.32'
4343
annotationProcessor 'org.projectlombok:lombok:1.18.32'
44+
compileOnly 'org.jetbrains:annotations:24.1.0'
4445

4546
testCompileOnly 'org.projectlombok:lombok:1.18.32'
4647
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'

src/main/java/io/getstream/chat/java/models/Channel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ public static class ConfigOverridesRequestObject {
423423
@Nullable
424424
@JsonProperty("user_message_reminders")
425425
private Boolean userMessageReminders;
426+
427+
@Nullable
428+
@JsonProperty("shared_locations")
429+
private Boolean sharedLocations;
426430
}
427431

428432
@Builder
@@ -1234,6 +1238,10 @@ public static class ChannelGetResponse extends StreamResponseObject {
12341238
@Nullable
12351239
@JsonProperty("hide_messages_before")
12361240
private Date hideMessagesBefore;
1241+
1242+
@Nullable
1243+
@JsonProperty("active_live_locations")
1244+
private List<SharedLocation> activeLiveLocations;
12371245
}
12381246

12391247
@Data

src/main/java/io/getstream/chat/java/models/Message.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public class Message {
168168
@JsonProperty("pinned_at")
169169
private Date pinnedAt;
170170

171+
@Nullable
172+
@JsonProperty("shared_location")
173+
private SharedLocation sharedLocation;
174+
171175
@NotNull @JsonIgnore private Map<String, Object> additionalFields = new HashMap<>();
172176

173177
@JsonAnyGetter
@@ -491,6 +495,16 @@ public static class MessageRequestObject {
491495
@JsonProperty("pinned_at")
492496
private Date pinnedAt;
493497

498+
@Nullable
499+
@JsonProperty("shared_location")
500+
private SharedLocation sharedLocation;
501+
502+
@NotNull
503+
public MessageRequestObject setSharedLocation(@Nullable SharedLocation sharedLocation) {
504+
this.sharedLocation = sharedLocation;
505+
return this;
506+
}
507+
494508
@Singular @Nullable @JsonIgnore private Map<String, Object> additionalFields;
495509

496510
@JsonAnyGetter
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package io.getstream.chat.java.models;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
import io.getstream.chat.java.models.framework.StreamRequest;
5+
import io.getstream.chat.java.models.framework.StreamResponseObject;
6+
import io.getstream.chat.java.services.SharedLocationService;
7+
import io.getstream.chat.java.services.framework.Client;
8+
import java.util.Date;
9+
import java.util.List;
10+
import lombok.*;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
13+
import retrofit2.Call;
14+
15+
@Data
16+
@NoArgsConstructor
17+
public class SharedLocation {
18+
@JsonProperty("channel_cid")
19+
private String channelCid;
20+
21+
@JsonProperty("created_at")
22+
private Date createdAt;
23+
24+
@JsonProperty("created_by_device_id")
25+
private String createdByDeviceId;
26+
27+
@JsonProperty("end_at")
28+
private Date endAt;
29+
30+
private Double latitude;
31+
private Double longitude;
32+
33+
@JsonProperty("message_id")
34+
private String messageId;
35+
36+
@JsonProperty("updated_at")
37+
private Date updatedAt;
38+
39+
@JsonProperty("user_id")
40+
private String userId;
41+
42+
@Data
43+
@NoArgsConstructor
44+
public static class SharedLocationRequest {
45+
@JsonProperty("message_id")
46+
private String messageId;
47+
48+
@JsonProperty("created_by_device_id")
49+
private String createdByDeviceId;
50+
51+
@Nullable
52+
@JsonProperty("end_at")
53+
private String endAt;
54+
55+
@Nullable private Double latitude;
56+
57+
@Nullable private Double longitude;
58+
59+
@JsonProperty("user_id")
60+
private String userId;
61+
}
62+
63+
@Data
64+
@NoArgsConstructor
65+
@EqualsAndHashCode(callSuper = true)
66+
public static class SharedLocationResponse extends StreamResponseObject {
67+
@JsonProperty("created_by_device_id")
68+
private String createdByDeviceId;
69+
70+
@JsonProperty("end_at")
71+
private String endAt;
72+
73+
private Double latitude;
74+
private Double longitude;
75+
}
76+
77+
@Data
78+
@NoArgsConstructor
79+
@EqualsAndHashCode(callSuper = true)
80+
public static class ActiveLiveLocationsResponse extends StreamResponseObject {
81+
@JsonProperty("active_live_locations")
82+
private List<SharedLocation> activeLiveLocations;
83+
}
84+
85+
public static class UpdateLocationRequestData {
86+
@NotNull
87+
@JsonProperty("request")
88+
private SharedLocationRequest request;
89+
90+
public UpdateLocationRequestData() {}
91+
92+
public UpdateLocationRequestData(SharedLocationRequest request) {
93+
this.request = request;
94+
}
95+
96+
public SharedLocationRequest getRequest() {
97+
return request;
98+
}
99+
100+
public void setRequest(SharedLocationRequest request) {
101+
this.request = request;
102+
}
103+
104+
public static class UpdateLocationRequest extends StreamRequest<SharedLocationResponse> {
105+
private SharedLocationRequest request;
106+
private String userId;
107+
108+
public UpdateLocationRequest() {}
109+
110+
public UpdateLocationRequest(SharedLocationRequest request) {
111+
this.request = request;
112+
}
113+
114+
public UpdateLocationRequest request(SharedLocationRequest request) {
115+
this.request = request;
116+
return this;
117+
}
118+
119+
public UpdateLocationRequest userId(String userId) {
120+
this.userId = userId;
121+
return this;
122+
}
123+
124+
@Override
125+
protected Call<SharedLocationResponse> generateCall(Client client) {
126+
return client.create(SharedLocationService.class).updateLiveLocation(userId, request);
127+
}
128+
}
129+
}
130+
131+
public static class GetLocationsRequestData {
132+
public static class GetLocationsRequest extends StreamRequest<ActiveLiveLocationsResponse> {
133+
private String userId;
134+
135+
public GetLocationsRequest() {}
136+
137+
public GetLocationsRequest userId(String userId) {
138+
this.userId = userId;
139+
return this;
140+
}
141+
142+
@Override
143+
protected Call<ActiveLiveLocationsResponse> generateCall(Client client) {
144+
return client.create(SharedLocationService.class).getLiveLocations(userId);
145+
}
146+
}
147+
}
148+
149+
/**
150+
* Creates an update location request
151+
*
152+
* @return the created request
153+
*/
154+
@NotNull
155+
public static UpdateLocationRequestData.UpdateLocationRequest updateLocation() {
156+
return new UpdateLocationRequestData.UpdateLocationRequest();
157+
}
158+
159+
/**
160+
* Creates a get locations request
161+
*
162+
* @return the created request
163+
*/
164+
@NotNull
165+
public static GetLocationsRequestData.GetLocationsRequest getLocations() {
166+
return new GetLocationsRequestData.GetLocationsRequest();
167+
}
168+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.getstream.chat.java.services;
2+
3+
import io.getstream.chat.java.models.SharedLocation;
4+
import org.jetbrains.annotations.NotNull;
5+
import retrofit2.Call;
6+
import retrofit2.http.*;
7+
8+
public interface SharedLocationService {
9+
@GET("users/live_locations")
10+
Call<SharedLocation.ActiveLiveLocationsResponse> getLiveLocations(
11+
@NotNull @Query("user_id") String userId);
12+
13+
@PUT("users/live_locations")
14+
Call<SharedLocation.SharedLocationResponse> updateLiveLocation(
15+
@NotNull @Query("user_id") String userId,
16+
@NotNull @Body SharedLocation.SharedLocationRequest sharedLocationRequest);
17+
}

0 commit comments

Comments
 (0)