mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
fix some bugs
* avoid using wrong DcContext after switching account in ConversationListActivity * avoid getContext() in ConversationFragment, use Rpc instead
This commit is contained in:
@@ -977,9 +977,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
DcContext dcContext = DcHelper.getContext(context);
|
||||
int accountId = getIntent().getIntExtra(ACCOUNT_ID_EXTRA, dcContext.getAccountId());
|
||||
if (accountId != dcContext.getAccountId()) {
|
||||
int selectedAccId = DcHelper.getContext(context).getAccountId();
|
||||
int accountId = getIntent().getIntExtra(ACCOUNT_ID_EXTRA, selectedAccId);
|
||||
if (accountId != selectedAccId) {
|
||||
switchedProfile = true;
|
||||
AccountManager.getInstance().switchAccount(context, accountId);
|
||||
initializeBackground();
|
||||
@@ -987,7 +987,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, -1);
|
||||
if(chatId == DcChat.DC_CHAT_NO_CHAT)
|
||||
throw new IllegalStateException("can't display a conversation for no chat.");
|
||||
dcChat = dcContext.getChat(chatId);
|
||||
dcChat = DcHelper.getContext(context).getChat(chatId);
|
||||
recipient = new Recipient(this, dcChat);
|
||||
glideRequests = GlideApp.with(this);
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.views.ConversationAdaptiveActionsToolbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -74,6 +75,9 @@ import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import chat.delta.rpc.Rpc;
|
||||
import chat.delta.rpc.RpcException;
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class ConversationFragment extends MessageSelectorFragment
|
||||
{
|
||||
@@ -102,10 +106,12 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
|
||||
public boolean isPaused;
|
||||
private Debouncer markseenDebouncer;
|
||||
private Rpc rpc;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
rpc = DcHelper.getRpc(getContext());
|
||||
|
||||
DcEventCenter eventCenter = DcHelper.getEventCenter(getContext());
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this);
|
||||
@@ -206,8 +212,13 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Util.runOnBackground(() -> DcHelper.getContext(getContext()).marknoticedChat((int) chatId));
|
||||
Util.runOnBackground(() -> {
|
||||
try {
|
||||
rpc.marknoticedChat(rpc.getSelectedAccountId(), (int) chatId);
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "RPC error", e);
|
||||
}
|
||||
});
|
||||
if (list.getAdapter() != null) {
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
@@ -286,7 +297,12 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
dateDecoration = new StickyHeaderDecoration(adapter, false, false);
|
||||
list.addItemDecoration(dateDecoration);
|
||||
|
||||
int freshMsgs = DcHelper.getContext(getContext()).getFreshMsgCount((int) chatId);
|
||||
int freshMsgs = 0;
|
||||
try {
|
||||
freshMsgs = rpc.getFreshMsgCnt(rpc.getSelectedAccountId(), (int) chatId);
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "RPC error", e);
|
||||
}
|
||||
SetStartingPositionLinearLayoutManager layoutManager = (SetStartingPositionLinearLayoutManager) list.getLayoutManager();
|
||||
if (startingPosition > -1) {
|
||||
layoutManager.setStartingPosition(startingPosition);
|
||||
@@ -457,9 +473,13 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
private void handleForwardMessage(final Set<DcMsg> messageRecords) {
|
||||
Intent composeIntent = new Intent();
|
||||
int[] msgIds = DcMsg.msgSetToIds(messageRecords);
|
||||
setForwardingMessageIds(composeIntent, msgIds, DcHelper.getContext(getContext()).getAccountId());
|
||||
ConversationListRelayingActivity.start(this, composeIntent);
|
||||
getActivity().overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
||||
try {
|
||||
setForwardingMessageIds(composeIntent, msgIds, rpc.getSelectedAccountId());
|
||||
ConversationListRelayingActivity.start(this, composeIntent);
|
||||
getActivity().overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "RPC error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@@ -485,7 +505,7 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
private void handleReplyMessagePrivately(final DcMsg msg) {
|
||||
|
||||
if (getActivity() != null) {
|
||||
DcContext dcContext = DcHelper.getContext(getContext());
|
||||
DcContext dcContext = DcHelper.getContext(getActivity());
|
||||
int privateChatId = dcContext.createChatByContactId(msg.getFromId());
|
||||
DcMsg replyMsg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT);
|
||||
replyMsg.setQuote(msg);
|
||||
@@ -502,11 +522,14 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
|
||||
private void handleToggleSave(final Set<DcMsg> messageRecords) {
|
||||
DcMsg msg = getSelectedMessageRecord(messageRecords);
|
||||
DcContext dcContext = DcHelper.getContext(getContext());
|
||||
if (msg.getSavedMsgId() != 0) {
|
||||
dcContext.deleteMsgs(new int[]{msg.getSavedMsgId()});
|
||||
} else {
|
||||
dcContext.saveMsgs(new int[]{msg.getId()});
|
||||
try {
|
||||
if (msg.getSavedMsgId() != 0) {
|
||||
rpc.deleteMessages(rpc.getSelectedAccountId(), Collections.singletonList(msg.getSavedMsgId()));
|
||||
} else {
|
||||
rpc.saveMsgs(rpc.getSelectedAccountId(), Collections.singletonList(msg.getId()));
|
||||
}
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "RPC error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,16 +735,20 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
return;
|
||||
}
|
||||
|
||||
int[] ids = new int[lastPos - firstPos + 1];
|
||||
int index = 0;
|
||||
ArrayList<Integer> ids = new ArrayList<>(lastPos - firstPos + 1);
|
||||
for(int pos = firstPos; pos <= lastPos; pos++) {
|
||||
DcMsg message = ((ConversationAdapter) list.getAdapter()).getMsg(pos);
|
||||
if (message.getFromId() != DC_CONTACT_ID_SELF) {
|
||||
ids[index] = message.getId();
|
||||
index++;
|
||||
ids.add(message.getId());
|
||||
}
|
||||
}
|
||||
Util.runOnAnyBackgroundThread(() -> DcHelper.getContext(getContext()).markseenMsgs(ids));
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
try {
|
||||
rpc.markseenMsgs(rpc.getSelectedAccountId(), ids);
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "RPC error", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class ConversationFragmentItemClickListener implements ItemClickListener {
|
||||
|
||||
@@ -266,12 +266,12 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
DcContext dcContext = DcHelper.getContext(this);
|
||||
int accountId = getIntent().getIntExtra(ACCOUNT_ID_EXTRA, dcContext.getAccountId());
|
||||
int selectedAccId = DcHelper.getContext(this).getAccountId();
|
||||
int accountId = getIntent().getIntExtra(ACCOUNT_ID_EXTRA, selectedAccId);
|
||||
if (getIntent().getBooleanExtra(CLEAR_NOTIFICATIONS, false)) {
|
||||
DcHelper.getNotificationCenter(this).removeAllNotifications(accountId);
|
||||
}
|
||||
if (accountId != dcContext.getAccountId()) {
|
||||
if (accountId != selectedAccId) {
|
||||
AccountManager.getInstance().switchAccount(this, accountId);
|
||||
onProfileSwitched(accountId);
|
||||
} else {
|
||||
|
||||
@@ -103,8 +103,7 @@ public class AccountSelectionListFragment extends DialogFragment implements DcEv
|
||||
DcAccounts accounts = DcHelper.getAccounts(getActivity());
|
||||
int[] accountIds = accounts.getAll();
|
||||
|
||||
int count = (selectOnly? 0 : 1) + accountIds.length;
|
||||
int[] ids = new int[count];
|
||||
int[] ids = new int[(selectOnly? 0 : 1) + accountIds.length];
|
||||
int j = 0;
|
||||
for (int accountId : accountIds) {
|
||||
ids[j++] = accountId;
|
||||
|
||||
Reference in New Issue
Block a user