update fork #128

Manually merged
tristan merged 181 commits from mirror/monocles_chat_clean:master into master 2026-01-23 14:02:38 +01:00
3 changed files with 65 additions and 49 deletions
Showing only changes of commit f72e57cabd - Show all commits

Allow viewing all stories from a single contact

Arne 2025-12-30 13:09:57 +01:00

View file

@ -466,11 +466,14 @@ public class MessageParser extends AbstractParser
final Element item = items.findChild("item");
mXmppConnectionService.processMdsItem(account, item);
} else if (Namespace.PUBSUB_STORIES.equals(node)) {
final Element item = items.findChild("item");
if (item != null) {
final Story story = Story.fromElement(item, from);
if (story != null) {
mXmppConnectionService.onStoryReceived(story);
if (items != null) {
for (Element item : items.getChildren()) {
if ("item".equals(item.getName())) {
final Story story = Story.fromElement(item, from);
if (story != null) {
mXmppConnectionService.onStoryReceived(story);
}
}
}
}
} else if (Namespace.USER_TUNE.equals(node)) {

View file

@ -17,6 +17,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@ -27,22 +28,26 @@ import okhttp3.HttpUrl;
public class StoryViewActivity extends XmppActivity {
public static final String EXTRA_URL = "url";
public static final String EXTRA_URLS = "urls";
public static final String EXTRA_TITLES = "titles";
public static final String EXTRA_STORY_IDS = "story_ids";
public static final String EXTRA_ACCOUNT = "account";
public static final String EXTRA_TITLE = "title";
public static final String EXTRA_STORY_ID = "story_id";
public static final String EXTRA_CONTACT = "contact";
private ImageView imageView;
private TextView titleView;
private String storyId;
private ArrayList<String> urls;
private ArrayList<String> titles;
private ArrayList<String> storyIds;
private int currentIndex = 0;
private Jid contact;
private Account mAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Conversations3);
setContentView(R.layout.activity_story_view);
Toolbar toolbar = findViewById(R.id.toolbar);
@ -54,19 +59,19 @@ public class StoryViewActivity extends XmppActivity {
imageView = findViewById(R.id.story_image_view);
titleView = findViewById(R.id.story_title_view);
final String title = getIntent().getStringExtra(EXTRA_TITLE);
if (title != null) {
titleView.setText(title);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(title);
}
} else {
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(R.string.story);
}
}
urls = getIntent().getStringArrayListExtra(EXTRA_URLS);
titles = getIntent().getStringArrayListExtra(EXTRA_TITLES);
storyIds = getIntent().getStringArrayListExtra(EXTRA_STORY_IDS);
imageView.setOnClickListener(v -> {
currentIndex++;
if (currentIndex < urls.size()) {
loadStory();
} else {
finish();
}
});
storyId = getIntent().getStringExtra(EXTRA_STORY_ID);
try {
contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT));
} catch (final Exception e) {
@ -74,7 +79,8 @@ public class StoryViewActivity extends XmppActivity {
}
}
@Override
@Override
protected void refreshUiReal() {
}
@ -91,16 +97,12 @@ public class StoryViewActivity extends XmppActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
if (item.getItemId() == R.id.action_delete_story) {
new MaterialAlertDialogBuilder(this)
.setTitle(R.string.delete_story_dialog_title)
.setMessage(R.string.delete_story_dialog_message)
.setPositiveButton(R.string.delete, (dialog, which) -> {
xmppConnectionService.retractStory(mAccount, storyId, new UiCallback<Void>() {
xmppConnectionService.retractStory(mAccount, storyIds.get(currentIndex), new UiCallback<Void>() {
@Override
public void success(Void aVoid) {
runOnUiThread(() -> {
@ -131,23 +133,23 @@ public class StoryViewActivity extends XmppActivity {
@Override
public void onBackendConnected() {
String url = getIntent().getStringExtra(EXTRA_URL);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
if (url == null || accountUuid == null) {
finish();
return;
if (accountUuid != null) {
mAccount = xmppConnectionService.findAccountByUuid(accountUuid);
}
mAccount = xmppConnectionService.findAccountByUuid(accountUuid);
if (mAccount == null) {
Toast.makeText(this, R.string.no_active_account, Toast.LENGTH_SHORT).show();
finish();
return;
}
invalidateOptionsMenu();
loadStory();
}
private void loadStory() {
if (urls == null || currentIndex >= urls.size()) {
finish();return;
}
titleView.setText(titles.get(currentIndex));
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(titles.get(currentIndex));
}
final String url = urls.get(currentIndex);
final HttpUrl httpUrl;
try {
httpUrl = HttpUrl.get(url);
@ -157,8 +159,8 @@ public class StoryViewActivity extends XmppActivity {
return;
}
final boolean useTor = xmppConnectionService.useTorToConnect() || mAccount.isOnion();
final boolean useI2p = xmppConnectionService.useI2PToConnect() || mAccount.isI2P();
final boolean useTor = mAccount != null && (xmppConnectionService.useTorToConnect() || mAccount.isOnion());
final boolean useI2p = mAccount != null && (xmppConnectionService.useI2PToConnect() || mAccount.isI2P());
new Thread(() -> {
File tempFile = null;

View file

@ -8,6 +8,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
@ -38,8 +39,8 @@ public class StoryAdapter extends RecyclerView.Adapter<StoryAdapter.StoryViewHol
public void onBindViewHolder(@NonNull StoryViewHolder holder, int position) {
final Story story = stories.get(position);
final Jid jid = story.getContact();
Contact contact;
Account storyAccount;
Contact contact = null;
Account storyAccount = null;
// Check if the story author is one of our own accounts
storyAccount = activity.xmppConnectionService.findAccountByJid(jid);
@ -49,8 +50,6 @@ public class StoryAdapter extends RecyclerView.Adapter<StoryAdapter.StoryViewHol
contact = storyAccount.getSelfContact();
} else {
// It's from someone else. Find which of our accounts knows them.
contact = null;
storyAccount = null;
for (Account account : activity.xmppConnectionService.getAccounts()) {
contact = account.getRoster().getContact(jid);
if (contact != null) {
@ -70,13 +69,25 @@ public class StoryAdapter extends RecyclerView.Adapter<StoryAdapter.StoryViewHol
final Account finalStoryAccount = storyAccount;
holder.itemView.setOnClickListener(v -> {
Intent intent = new Intent(activity, StoryViewActivity.class);
intent.putExtra(StoryViewActivity.EXTRA_URL, story.getUrl());
ArrayList<String> urls = new ArrayList<>();
ArrayList<String> titles = new ArrayList<>();
ArrayList<String> storyIds = new ArrayList<>();
// This is the corrected logic: Get the FULL list from the service
for (Story s : activity.xmppConnectionService.getStories()) {
if (s.getContact().asBareJid().equals(story.getContact().asBareJid())) {
urls.add(s.getUrl());
titles.add(s.getTitle());
storyIds.add(s.getUuid());
}
}
intent.putStringArrayListExtra(StoryViewActivity.EXTRA_URLS, urls);
intent.putStringArrayListExtra(StoryViewActivity.EXTRA_TITLES, titles);
intent.putStringArrayListExtra(StoryViewActivity.EXTRA_STORY_IDS, storyIds);
intent.putExtra(StoryViewActivity.EXTRA_CONTACT, story.getContact().asBareJid().toString());
if (finalStoryAccount != null) {
intent.putExtra(StoryViewActivity.EXTRA_ACCOUNT, finalStoryAccount.getUuid());
}
intent.putExtra(StoryViewActivity.EXTRA_TITLE, story.getTitle());
intent.putExtra(StoryViewActivity.EXTRA_STORY_ID, story.getUuid());
intent.putExtra(StoryViewActivity.EXTRA_CONTACT, story.getContact().asBareJid().toString());
activity.startActivity(intent);
});
}