Skip to content

Commit

Permalink
Merge pull request signalapp#377 from meskio/resend_message_on_fail2
Browse files Browse the repository at this point in the history
Allow to resend a failed message
  • Loading branch information
moxie0 committed Oct 15, 2013
2 parents f27c7c4 + 04eafd5 commit f49c627
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions res/menu/conversation_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@

<item android:title="@string/conversation_context__menu_forward_message"
android:id="@+id/menu_context_forward" />

<item android:title="@string/conversation_context__menu_resend_message"
android:id="@+id/menu_context_resend"
android:visible="false" />
</menu>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
<string name="conversation_context__menu_copy_text">Copy text</string>
<string name="conversation_context__menu_delete_message">Delete message</string>
<string name="conversation_context__menu_forward_message">Forward message</string>
<string name="conversation_context__menu_resend_message">Resend message</string>

<!-- conversation_insecure -->
<string name="conversation_insecure__menu_start_secure_session">Start Secure Session</string>
Expand Down
26 changes: 22 additions & 4 deletions src/org/thoughtcrime/securesms/ConversationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.v4.content.Loader;
import android.text.ClipboardManager;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -24,6 +25,7 @@
import org.thoughtcrime.securesms.database.loaders.ConversationLoader;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;

import java.sql.Date;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -58,19 +60,23 @@ public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMe
menu.clear();

inflater.inflate(R.menu.conversation_context, menu);

MessageRecord messageRecord = getMessageRecord();
if (messageRecord.isFailed()) {
MenuItem resend = menu.findItem(R.id.menu_context_resend);
resend.setVisible(true);
}
}

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
Cursor cursor = ((CursorAdapter)getListAdapter()).getCursor();
ConversationItem conversationItem = (ConversationItem)(((ConversationAdapter)getListAdapter()).newView(getActivity(), cursor, null));
MessageRecord messageRecord = conversationItem.getMessageRecord();

MessageRecord messageRecord = getMessageRecord();
switch(item.getItemId()) {
case R.id.menu_context_copy: handleCopyMessage(messageRecord); return true;
case R.id.menu_context_delete_message: handleDeleteMessage(messageRecord); return true;
case R.id.menu_context_details: handleDisplayDetails(messageRecord); return true;
case R.id.menu_context_forward: handleForwardMessage(messageRecord); return true;
case R.id.menu_context_resend: handleResendMessage(messageRecord); return true;
}

return false;
Expand All @@ -82,6 +88,12 @@ public void onAttach(Activity activity) {
this.listener = (ConversationFragmentListener)activity;
}

private MessageRecord getMessageRecord() {
Cursor cursor = ((CursorAdapter)getListAdapter()).getCursor();
ConversationItem conversationItem = (ConversationItem)(((ConversationAdapter)getListAdapter()).newView(getActivity(), cursor, null));
return conversationItem.getMessageRecord();
}

public void reload(Recipients recipients, long threadId) {
this.recipients = recipients;
this.threadId = threadId;
Expand Down Expand Up @@ -158,6 +170,12 @@ private void handleForwardMessage(MessageRecord message) {
startActivity(composeIntent);
}

private void handleResendMessage(MessageRecord message) {
long messageId = message.getId();
final Activity activity = getActivity();
MessageSender.resend(activity, messageId, message.isMms());
}

private void initializeResources() {
this.masterSecret = (MasterSecret)this.getActivity().getIntent()
.getParcelableExtra("master_secret");
Expand Down
5 changes: 5 additions & 0 deletions src/org/thoughtcrime/securesms/database/MmsDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ private void updateMailboxBitmask(long id, long maskOff, long maskOn) {
" WHERE " + ID + " = ?", new String[] {id + ""});
}

public void markAsSending(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENDING_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
}

public void markAsSentFailed(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/service/MmsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void process(MasterSecret masterSecret, Intent intent) {
Log.w("MmsSender", me);
if (messageId != -1)
database.markAsSentFailed(messageId);
}
}
} else if (intent.getAction().equals(SendReceiveService.SEND_MMS_CONNECTIVITY_ACTION)) {
handleConnectivityChange();
}
Expand Down
17 changes: 17 additions & 0 deletions src/org/thoughtcrime/securesms/sms/MessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ public static long send(Context context, MasterSecret masterSecret,
return threadId;
}

public static void resend(Context context, long messageId, boolean isMms)
{

Intent intent;
if (isMms) {
DatabaseFactory.getMmsDatabase(context).markAsSending(messageId);
intent = new Intent(SendReceiveService.SEND_MMS_ACTION, null,
context, SendReceiveService.class);
} else {
DatabaseFactory.getSmsDatabase(context).markAsSending(messageId);
intent = new Intent(SendReceiveService.SEND_SMS_ACTION, null,
context, SendReceiveService.class);
}
intent.putExtra("message_id", messageId);
context.startService(intent);
}

private static void sendMms(Context context, Recipients recipients, MasterSecret masterSecret,
SendReq sendRequest, long threadId, int distributionType, boolean secure)
throws MmsException
Expand Down

0 comments on commit f49c627

Please sign in to comment.