Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 81c76a7

Browse files
Sam1301timabbott
authored andcommitted
Add documentation.
1 parent b645481 commit 81c76a7

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,12 @@ public Message deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
243243
} else {
244244
Message.ZulipDirectMessage msg = naiveGson.fromJson(json, Message.ZulipDirectMessage.class);
245245
if (msg.getDisplayRecipient() != null) {
246+
// set the correct person id for message recipients
246247
List<Person> people = msg.getDisplayRecipient();
247248
for (Person person : people) {
249+
// this is needed as the json field name for person id is
250+
// "user_id" in realm configuration response and "id" in
251+
// GET v1/messages response.
248252
person.setId(person.getRecipientId());
249253
}
250254

app/src/main/java/com/zulip/android/models/Message.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ public void setRecipients(Person[] list) {
430430
this.recipientsCache = list;
431431

432432
try {
433+
/* Since person ids were auto-generated before, we needed to get the person object "to"
434+
and "from" from the database to have the correct id. After shifting to server
435+
generated ids, the list passed already has person objects "to"(list[0]) and
436+
"from"(list[1]) having correct ids. */
433437
Person to = list[0];
434438

435439
if (list.length == 1) {

app/src/main/java/com/zulip/android/models/Person.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class Person {
6262
@SerializedName("is_mirror_dummy")
6363
private boolean isMirrorDummy;
6464

65+
/**
66+
* used to get person id in case of {@link Message.ZulipDirectMessage}
67+
*/
6568
@SerializedName("id")
6669
private int recipientId;
6770

@@ -115,6 +118,19 @@ public static Person getByEmail(Dao<Person, ?> dao, String email) {
115118
}
116119

117120
@SuppressWarnings("WeakerAccess")
121+
/**
122+
* Returns person object {@link Person} from the database if exists or newly created object using
123+
* the passed parameters.
124+
* Note: always call this method with valid Person id {@link Person#id} passed as argument.
125+
*
126+
* @param app Zulip god object {@link ZulipApp}
127+
* @param email person email {@link Person#email}
128+
* @param name person name {@link Person#name}
129+
* @param avatarURL person avatar url {@link Person#avatarURL}
130+
* @param personId person id {@link Person#id}
131+
* @param personCache person cache used ofr faster fetching of results
132+
* @return {@link Person} object
133+
*/
118134
public static Person getOrUpdate(ZulipApp app, String email, String name,
119135
String avatarURL, int personId, Map<String, Person> personCache) {
120136

@@ -133,6 +149,9 @@ public static Person getOrUpdate(ZulipApp app, String email, String name,
133149

134150
if (person == null) {
135151
person = new Person(name, email, avatarURL);
152+
153+
// use the person id passed to generate person skeleton object which is consistent
154+
// with server id.
136155
person.setId(personId);
137156
app.getDao(Person.class).create(person);
138157
} else {
@@ -152,6 +171,18 @@ public static Person getOrUpdate(ZulipApp app, String email, String name,
152171
return person;
153172
}
154173

174+
/**
175+
* This function is used to call {@link Person#getOrUpdate(ZulipApp, String, String, String, int, Map)}
176+
* with no cache.
177+
* Note: always call this method with valid Person id {@link Person#id} passed as argument.
178+
*
179+
* @param app Zulip god object {@link ZulipApp}
180+
* @param email person email {@link Person#email}
181+
* @param name person name {@link Person#name}
182+
* @param avatarURL person avatar url {@link Person#avatarURL}
183+
* @param personId person id {@link Person#id}
184+
* @return {@link Person} object
185+
* */
155186
public static Person getOrUpdate(ZulipApp app, String email, String name,
156187
String avatarURL, int personId) {
157188
return getOrUpdate(app, email, name, avatarURL, personId, null);

app/src/main/java/com/zulip/android/networking/AsyncGetEvents.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public Void call() throws Exception {
190190
person.setActive(true);
191191
try {
192192
if (person.getEmail().equalsIgnoreCase(app.getYou().getEmail())) {
193-
// change the id
193+
// change the id of "you" to correct server id after login
194+
// this statement also updates app.getYou with updated id
194195
personDao.updateId(app.getYou(), person.getId());
195196
}
196197
personDao.createOrUpdate(person);

app/src/main/java/com/zulip/android/util/CustomHtmlToSpannedConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private static void startSpan(SpannableStringBuilder text, Attributes attributes
242242
int id = Integer.parseInt(stringId);
243243
email = Person.getById(ZulipApp.get(), id).getEmail();
244244
} else {
245-
// for historical messages
245+
// for historical messages, revert to use of this attribute
246246
email = attributes.getValue("data-user-email");
247247
}
248248

0 commit comments

Comments
 (0)