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

Commit 3a4f5f6

Browse files
jainkuniyatimabbott
authored andcommitted
Toast when message is sent to unsubscribed stream
Fixes: #255 and #256
1 parent 2455df9 commit 3a4f5f6

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,16 +1255,17 @@ private void sendMessage() {
12551255
streamActv.requestFocus();
12561256
return;
12571257
} else {
1258-
try {
1259-
Cursor streamCursor = makeStreamCursor(streamActv.getText().toString());
1260-
if (streamCursor.getCount() == 0) {
1261-
streamActv.setError(getString(R.string.stream_not_exists));
1262-
streamActv.requestFocus();
1263-
return;
1264-
}
1265-
} catch (SQLException e) {
1266-
ZLog.logException(e);
1267-
Log.e("SQLException", "SQL not correct", e);
1258+
Stream stream = Stream.streamCheckBeforeMessageSend(app, streamActv.getText().toString());
1259+
//check whether stream exists or not
1260+
if (stream == null) {
1261+
streamActv.setError(getString(R.string.stream_not_exists));
1262+
streamActv.requestFocus();
1263+
return;
1264+
}// check whether user is subscribed or not
1265+
else if (!stream.isSubscribed()) {
1266+
Toast.makeText(ZulipActivity.this, getString(R.string.message_not_subscribed)
1267+
+ " " + streamActv.getText().toString() + " " + getString(R.string.keyword_stream), Toast.LENGTH_SHORT).show();
1268+
return;
12681269
}
12691270
}
12701271
if (TextUtils.isEmpty(topicActv.getText().toString())) {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.j256.ormlite.stmt.SelectArg;
1414
import com.j256.ormlite.table.DatabaseTable;
1515
import com.zulip.android.ZulipApp;
16+
import com.zulip.android.util.ZLog;
1617

1718
import org.apache.commons.lang.builder.EqualsBuilder;
1819
import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -190,4 +191,24 @@ public int getId() {
190191
return id;
191192
}
192193

193-
}
194+
/**
195+
* Checks stream name is valid or not
196+
* @param app ZulipApp
197+
* @param streamName Checks this stream name is valid or not
198+
* @return null if stream does not exist else cursor
199+
*/
200+
public static Stream streamCheckBeforeMessageSend(ZulipApp app, CharSequence streamName) {
201+
if (streamName == null) {
202+
return null;
203+
}
204+
try {
205+
return app.getDao(Stream.class)
206+
.queryBuilder().where()
207+
.eq(Stream.NAME_FIELD, new SelectArg(Stream.NAME_FIELD, streamName)).queryForFirst();
208+
} catch (SQLException e) {
209+
ZLog.logException(e);
210+
}
211+
return null;
212+
}
213+
214+
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@
116116
<string name="camera_content_desp">take photo</string>
117117
<string name="menu_one_day_before">One Day Before</string>
118118
<string name="enter_date">Enter Date</string>
119+
<string name="message_not_subscribed">Not subscribed to</string>
120+
<string name="keyword_stream">stream</string>
119121
</resources>

0 commit comments

Comments
 (0)