This repository was archived by the owner on Jul 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-11
lines changed Expand file tree Collapse file tree 3 files changed +35
-11
lines changed Original file line number Diff line number Diff 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 ())) {
Original file line number Diff line number Diff line change 1313import com .j256 .ormlite .stmt .SelectArg ;
1414import com .j256 .ormlite .table .DatabaseTable ;
1515import com .zulip .android .ZulipApp ;
16+ import com .zulip .android .util .ZLog ;
1617
1718import org .apache .commons .lang .builder .EqualsBuilder ;
1819import 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments