Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.zulip.android.ZulipApp;
import com.zulip.android.models.Message;
import com.zulip.android.models.Stream;
import com.zulip.android.util.ZLog;

import java.sql.SQLException;
Expand Down Expand Up @@ -35,7 +36,7 @@ public Cursor getChildrenCursor(Cursor groupCursor) {
try {
results = ZulipApp.get().getDao(Message.class).queryRaw("SELECT DISTINCT subject, count(case when messages.id > " + pointer + " or messages." + Message.MESSAGE_READ_FIELD + " = 0 then 1 end) as unreadcount FROM messages " +
"JOIN streams ON streams.id=messages.stream " +
"WHERE streams.id=" + groupCursor.getInt(0) + " group by subject").getResults();
"WHERE streams.id=" + groupCursor.getInt(0) + " and streams." + Stream.SUBSCRIBED_FIELD + " = " + "1 group by subject").getResults();
} catch (SQLException e) {
ZLog.logException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ private void markThisMessageAsRead(Message message) {
} catch (SQLException e) {
ZLog.logException(e);
}
zulipApp.markMessageAsRead(message);
}
zulipApp.markMessageAsRead(message);
} catch (NullPointerException e) {
Log.w("scrolling", "Could not find a location to scroll to!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.zulip.android.activities;

import android.Manifest;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.ArrayList;

import android.animation.Animator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand Down Expand Up @@ -641,11 +634,12 @@ public Cursor call() throws Exception {
+ " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream ";
if (!etSearchStream.getText().toString().equals("") && !etSearchStream.getText().toString().isEmpty()) {
//append where clause
query += " WHERE s.name LIKE '%" + etSearchStream.getText().toString() + "%'";
query += " WHERE s.name LIKE '%" + etSearchStream.getText().toString() + "%'" + " and s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
//set visibility of this image false
ivSearchStreamCancel.setVisibility(View.VISIBLE);
} else {
//set visibility of this image false
query += " WHERE s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
ivSearchStreamCancel.setVisibility(View.GONE);
}
//append group by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "zulip-%s.db";
// any time you make changes to your database objects, you may have to
// increase the database version
private static final int DATABASE_VERSION = 6;
private static final int DATABASE_VERSION = 7;

public DatabaseHelper(ZulipApp app, String email) {
super(app, String.format(DATABASE_NAME, MD5Util.md5Hex(email)), null,
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/zulip/android/models/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public Void call() throws Exception {
for (Message m : messages) {
Person person = Person.getOrUpdate(app, m.getSenderEmail(), m.getSenderFullName(), m.getAvatarUrl());
m.setSender(person);
Stream stream = null;
if (m.getType() == MessageType.STREAM_MESSAGE) {
stream = Stream.getByName(app, m.getRecipients());
}
m.setStream(stream);
messageDao.createOrUpdate(m);
}
return null;
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/zulip/android/models/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Stream {
private String description;

@SerializedName("subscribers")
private List<Integer> subscribers;
private List<String> subscribers;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These subscribers is the list of email right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


@SerializedName("pin_to_top")
private boolean pinToTop;
Expand Down Expand Up @@ -211,4 +211,12 @@ public static Stream streamCheckBeforeMessageSend(ZulipApp app, CharSequence str
return null;
}

public void setFetchColor(String fetchedColor) {
this.fetchedColor = fetchedColor;
getParsedColor();
}

public void setInHomeView(boolean inHomeView) {
this.inHomeView = inHomeView;
}
}
115 changes: 111 additions & 4 deletions app/src/main/java/com/zulip/android/networking/AsyncGetEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.zulip.android.networking.response.events.EventsBranch;
import com.zulip.android.networking.response.events.GetEventResponse;
import com.zulip.android.networking.response.events.MessageWrapper;
import com.zulip.android.networking.response.events.MutedTopicsWrapper;
import com.zulip.android.networking.response.events.SubscriptionWrapper;
import com.zulip.android.util.MutedTopics;
import com.zulip.android.util.TypeSwapper;
import com.zulip.android.util.ZLog;
Expand Down Expand Up @@ -132,7 +134,7 @@ public Void call() throws Exception {

RuntimeExceptionDao<Stream, Object> streamDao = app
.getDao(Stream.class);
Log.i("stream", "" + subscriptions.size() + " streams");
Log.i("stream", "" + subscriptions.size() + " subscribed streams");

// Mark all existing subscriptions as not subscribed
streamDao.updateBuilder().updateColumnValue(
Expand All @@ -148,6 +150,19 @@ public Void call() throws Exception {
ZLog.logException(e);
}
}

// get unsubscribed streams
List<Stream> unsubscribed = response.getUnsubscribed();
for (Stream stream : unsubscribed) {
stream.getParsedColor();
stream.setSubscribed(false);
try {
streamDao.createOrUpdate(stream);
} catch (Exception e) {
ZLog.logException(e);
}
}

//MUST UPDATE AFTER SUBSCRIPTIONS ARE STORED IN DB
mMutedTopics.addToMutedTopics(response.getMutedTopics());

Expand Down Expand Up @@ -175,8 +190,7 @@ public Void call() throws Exception {
} else {
personDao.update(person);
}
}
catch(Exception e) {
} catch (Exception e) {
ZLog.logException(e);
}
}
Expand Down Expand Up @@ -289,13 +303,35 @@ public void run() {
*/
private void processEvents(GetEventResponse events) {
// In task thread
// get subscription events
List<EventsBranch> subscriptions = events.getEventsOfBranchType(EventsBranch.BranchType.SUBSCRIPTIONS);

if (!subscriptions.isEmpty()) {
Log.i("AsyncGetEvents", "Received " + subscriptions.size()
+ " streams event");
try {
processSubsciptions(subscriptions);
} catch (Exception e) {
ZLog.logException(e);
}
}

// get muted topics events
List<EventsBranch> mutedTopics = events.getEventsOfBranchType(EventsBranch.BranchType.MUTED_TOPICS);
if (!mutedTopics.isEmpty()) {
Log.i("AsyncGetEvents", "Received " + mutedTopics.size()
+ " muted_topics event");
processMutedTopics(mutedTopics);
}

// get messages events
List<Message> messages = events.getEventsOf(EventsBranch.BranchType.MESSAGE, new TypeSwapper<MessageWrapper, Message>() {
@Override
public Message convert(MessageWrapper messageWrapper) {
return messageWrapper.getMessage();
}
});
if (!messages.isEmpty()) {
if (messages != null && !messages.isEmpty()) {
Log.i("AsyncGetEvents", "Received " + messages.size()
+ " messages");
Message.createMessages(app, messages);
Expand Down Expand Up @@ -332,4 +368,75 @@ public void run() {
}
}

/**
* Create or update streams extract from {@param subscriptionWrapperList}. This function takes
* care of 3 cases : add, remove and update subscription streams
*
* @param subscriptionWrapperList list of {@link SubscriptionWrapper}
*/
private void processSubsciptions(List<EventsBranch> subscriptionWrapperList) throws Exception {
RuntimeExceptionDao<Stream, Object> streamDao = app
.getDao(Stream.class);

for (EventsBranch wrapper : subscriptionWrapperList) {
SubscriptionWrapper subscriptionwrapper = (SubscriptionWrapper) wrapper;
List<Stream> streams = subscriptionwrapper.getStreams();
if (subscriptionwrapper.getOperation().equalsIgnoreCase(SubscriptionWrapper.OPERATION_ADD)) {

// add new subscriptions
for (Stream stream : streams) {
stream.getParsedColor();
stream.setSubscribed(true);
streamDao.createOrUpdate(stream);
}
} else if (subscriptionwrapper.getOperation().equalsIgnoreCase(SubscriptionWrapper.OPERATION_UPDATE)) {

// update existing subscriptions
Stream stream = subscriptionwrapper.getUpdatedStream(app);
streamDao.createOrUpdate(stream);
} else if (subscriptionwrapper.getOperation().equalsIgnoreCase(SubscriptionWrapper.OPERATION_REMOVE)) {

// unsubscribe streams
for (Stream stream : streams) {
stream.getParsedColor();
stream.setSubscribed(false);
streamDao.createOrUpdate(stream);
}
} else {
Log.d("AsyncEvents", "unknown operation for subscription type event");
return;
}
}

// update the message list and streams drawer
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mActivity.onReadyToDisplay(true);
mActivity.checkAndSetupStreamsDrawer();
}
});
}

/**
* Update the muted topics list from {@param genericMutedTopics}
*
* @param genericMutedTopics list of {@link MutedTopicsWrapper}
*/
private void processMutedTopics(List<EventsBranch> genericMutedTopics) {
// update muted topics from events
for (EventsBranch wrapper : genericMutedTopics) {
MutedTopicsWrapper mutedTopics = (MutedTopicsWrapper) wrapper;
mMutedTopics.addToMutedTopics(mutedTopics.getMutedTopics());
}

// update the message list and streams drawer
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mActivity.onReadyToDisplay(true);
mActivity.checkAndSetupStreamsDrawer();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class UserConfigurationResponse {
private List<Stream> realmDefaultStreams;

@SerializedName("unsubscribed")
private List<?> unsubscribed;
private List<Stream> unsubscribed;

@SerializedName("subscriptions")
private List<Stream> subscriptions;
Expand Down Expand Up @@ -216,7 +216,7 @@ public List<Stream> getRealmDefaultStreams() {
return realmDefaultStreams;
}

public List<?> getUnsubscribed() {
public List<Stream> getUnsubscribed() {
return unsubscribed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public String getType() {

public enum BranchType {
MESSAGE(MessageWrapper.class, "message"),
PRESENCE(PresenceWrapper.class, "presence");
PRESENCE(PresenceWrapper.class, "presence"),
SUBSCRIPTIONS(SubscriptionWrapper.class, "subscription"),
MUTED_TOPICS(MutedTopicsWrapper.class, "muted_topics");

private final Class<? extends EventsBranch> klazz;
private final String key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,23 @@ public void setResult(String result) {
this.result = result;
}

/**
* Function to get events of branch type {@param branchType} from {@link GetEventResponse#events}
* list.
*
* @param branchType {@link EventsBranch.BranchType}
* @return list of events of branch type {@param branchType}
*/
public List<EventsBranch> getEventsOfBranchType(EventsBranch.BranchType branchType) {
List<EventsBranch> branches = this.getEvents();

List<EventsBranch> retVal = new ArrayList<>();
for (EventsBranch eventBranch : branches) {
if (eventBranch.getClass().equals(branchType.getKlazz())) {
retVal.add(eventBranch);
}
}

return retVal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@

import java.util.List;


/**
* This class is used to deserialize the message type event {@link EventsBranch.BranchType#MESSAGE}
*
* example : {"flags":[],"message":{"reactions":[],"recipient_id":38,
* "sender_email":"[email protected]","timestamp":1485172576,"display_recipient":"logs",
* "sender_id":10,"sender_full_name":"Zulip Error Bot","sender_domain":"zulip.com",
* "content":"<div class=\"codehilite\"><pre><span></span>10.0.3.1 POST 200 4.1s (db: 217ms/2q) /api/v1/users/me/presence ([email protected] via ZulipAndroid) ([email protected])\n</pre></div>",
* "stream_id":15,"gravatar_hash":"de425733f46e97dae34e4282037edd7e",
* "avatar_url":"https://secure.gravatar.com/avatar/de425733f46e97dae34e4282037edd7e?d=identicon",
* "client":"Internal","content_type":"text/html","subject_links":[],"is_mentioned":false,
* "sender_short_name":"error-bot","type":"stream","id":1522,"subject":"localhost:9991: slow queries"},
* "type":"message","id":8}
*/
public class MessageWrapper extends EventsBranch {
@SerializedName("message")
private Message message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.zulip.android.networking.response.events;

import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
* This class is used to deserialize muted_topic type event
* {@link EventsBranch.BranchType#MUTED_TOPICS}.
*
* example: {"muted_topics":[["devel","(no topic)"],["foraaron","(no topic)"],["announce","Streams"]],
* "type":"muted_topics","id":20}
*/

public class MutedTopicsWrapper extends EventsBranch{
@SerializedName("muted_topics")
private List<List<String>> mutedTopics;

public List<List<String>> getMutedTopics() {
return this.mutedTopics;
}

public void setMutedTopics(List<List<String>> mutedTopics) {
this.mutedTopics = mutedTopics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.google.gson.annotations.SerializedName;
import com.zulip.android.models.Presence;


/**
* This class is used to deserialize the presence type event {@link EventsBranch.BranchType#PRESENCE}
*
* example : {"id":0,"server_timestamp":1485171896.1950330734,"type":"presence","email":"[email protected]",
* "presence":{"ZulipAndroid":{"status":"active","timestamp":1485171896,"client":"ZulipAndroid","pushable":null}}}
*/
public class PresenceWrapper extends EventsBranch {

@SerializedName("server_timestamp")
Expand Down
Loading