Improve various aspects of mentions.

master
Cody Henthorne 2020-08-18 18:13:45 -04:00 committed by GitHub
parent 72b94127fb
commit 139317cf1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 5 deletions

View File

@ -1902,7 +1902,12 @@ public class ConversationActivity extends PassphraseRequiredActivity
private void initializeMentionsViewModel() {
MentionsPickerViewModel mentionsViewModel = ViewModelProviders.of(this, new MentionsPickerViewModel.Factory()).get(MentionsPickerViewModel.class);
recipient.observe(this, mentionsViewModel::onRecipientChange);
recipient.observe(this, r -> {
if (r.isPushV2Group() && !mentionsSuggestions.resolved()) {
mentionsSuggestions.get();
}
mentionsViewModel.onRecipientChange(r);
});
composeText.setMentionQueryChangedListener(query -> {
if (getRecipient().isPushV2Group()) {

View File

@ -15,6 +15,8 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.groups.GroupId;
import org.thoughtcrime.securesms.groups.LiveGroup;
import org.thoughtcrime.securesms.groups.ui.GroupMemberEntry.FullMember;
import org.thoughtcrime.securesms.megaphone.MegaphoneRepository;
import org.thoughtcrime.securesms.megaphone.Megaphones;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.MappingModel;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
@ -30,8 +32,11 @@ public class MentionsPickerViewModel extends ViewModel {
private final MutableLiveData<LiveGroup> group;
private final MutableLiveData<Query> liveQuery;
private final MutableLiveData<Boolean> isShowing;
private final MegaphoneRepository megaphoneRepository;
MentionsPickerViewModel(@NonNull MentionsPickerRepository mentionsPickerRepository, @NonNull MegaphoneRepository megaphoneRepository) {
this.megaphoneRepository = megaphoneRepository;
MentionsPickerViewModel(@NonNull MentionsPickerRepository mentionsPickerRepository) {
group = new MutableLiveData<>();
liveQuery = new MutableLiveData<>(Query.NONE);
selectedRecipient = new SingleLiveEvent<>();
@ -50,6 +55,7 @@ public class MentionsPickerViewModel extends ViewModel {
void onSelectionChange(@NonNull Recipient recipient) {
selectedRecipient.setValue(recipient);
megaphoneRepository.markFinished(Megaphones.Event.MENTIONS);
}
void setIsShowing(boolean isShowing) {
@ -116,7 +122,8 @@ public class MentionsPickerViewModel extends ViewModel {
@Override
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
//noinspection ConstantConditions
return modelClass.cast(new MentionsPickerViewModel(new MentionsPickerRepository(ApplicationDependencies.getApplication())));
return modelClass.cast(new MentionsPickerViewModel(new MentionsPickerRepository(ApplicationDependencies.getApplication()),
ApplicationDependencies.getMegaphoneRepository()));
}
}
}

View File

@ -101,6 +101,11 @@ public class MegaphoneRepository {
@AnyThread
public void markFinished(@NonNull Event event) {
executor.execute(() -> {
MegaphoneRecord record = databaseCache.get(event);
if (record != null && record.isFinished()) {
return;
}
database.markFinished(event);
resetDatabaseCache();
});

View File

@ -211,7 +211,7 @@ public final class Megaphones {
}
private static boolean shouldShowMentionsMegaphone() {
return FeatureFlags.mentions() && FeatureFlags.groupsV2();
return FeatureFlags.mentions();
}
private static boolean shouldShowLinkPreviewsMegaphone(@NonNull Context context) {

View File

@ -233,7 +233,7 @@ public final class FeatureFlags {
/** Whether or not we allow mentions send support in groups. */
public static boolean mentions() {
return getBoolean(MENTIONS, false);
return groupsV2() && getBoolean(MENTIONS, false);
}
/** Whether or not to use the UUID in verification codes. */