Skip to content

Commit

Permalink
fix some issues in VoiceMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
mantikafasi committed Jun 26, 2023
1 parent 1049579 commit 9717efc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
5 changes: 4 additions & 1 deletion VoiceMessages/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version = "1.1.0"
version = "1.1.1"
description = "Send Voice Messages"

aliucord.changelog.set("""
# 1.1.1
* Fix some issues
# 1.1.0
* Make voice messages sendable in servers
Expand Down
71 changes: 42 additions & 29 deletions VoiceMessages/src/main/java/com/aliucord/plugins/VoiceMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class VoiceMessages extends Plugin {
long voicePermissionMask = ((long) 1 << 46);
long adminMask = ((long) 1 << 3);
long meID = StoreStream.getUsers().getMe().getId();
StoreStageInstances stageInstances;
StoreThreadsJoined storeThreadsJoined;

@SuppressLint("ClickableViewAccessibility")
@Override
Expand All @@ -80,6 +82,9 @@ public void start(Context context) throws NoSuchMethodException, NoSuchFieldExce
return;
}

stageInstances = (StoreStageInstances) ReflectUtils.getField(StoreStream.getPermissions(), "storeStageInstances");
storeThreadsJoined = (StoreThreadsJoined) ReflectUtils.getField(StoreStream.getPermissions(), "storeThreadsJoined");

staticSettings = settings;

if (settings.getString("vendorId", null) == null) {
Expand Down Expand Up @@ -130,7 +135,6 @@ public void start(Context context) throws NoSuchMethodException, NoSuchFieldExce
patcher.patch(FlexInputFragment.class.getDeclaredMethod("onViewCreated", View.class, Bundle.class), cf -> {
var input = (FlexInputFragment) cf.thisObject;


editText = input.getView().findViewById(Utils.getResId("text_input", "id"));

var viewgroup = ((ViewGroup) input.getView().findViewById(Utils.getResId("main_input_container", "id")));
Expand All @@ -145,44 +149,22 @@ public void start(Context context) throws NoSuchMethodException, NoSuchFieldExce
});

patcher.patch(WidgetChatInputEditText$setOnTextChangedListener$1.class.getDeclaredMethod("afterTextChanged", Editable.class), cf -> {
if (editText.getText() == null || editText.getText().toString().equals("") && new ChannelWrapper(StoreStream.getChannelsSelected().getSelectedChannel()).isDM() ) {
recordButton.setVisibility(View.VISIBLE);
if (editText.getText() == null || editText.getText().toString().equals("")) {
ChannelWrapper channel = new ChannelWrapper(StoreStream.getChannelsSelected().getSelectedChannel());
logger.info(String.valueOf(channel.getId()));
showVoiceChannelIconIfCan(channel.getId());
} else {
recordButton.setVisibility(View.GONE);
}
});


var stageInstances = (StoreStageInstances) ReflectUtils.getField(StoreStream.getPermissions(), "storeStageInstances");
var storeThreadsJoined = (StoreThreadsJoined) ReflectUtils.getField(StoreStream.getPermissions(), "storeThreadsJoined");

patcher.patch(StoreStream.class.getDeclaredMethod("handleChannelSelected", long.class), cf -> {
var id = (long) cf.args[0];

if (id != 0L) {
var guild = StoreStream.getGuilds().getGuild(StoreStream.getGuildSelected().getSelectedGuildId());
try {
var channel = new ChannelWrapper(StoreStream.getChannels().getChannel(id));

var permissions = PermissionUtils.computePermissions(meID,
StoreStream.getChannels().getChannel(id),
StoreStream.getChannels().getGuildChannelInternal$app_productionGoogleRelease(guild.getId(), channel.getParentId()),
guild.getOwnerId(),
StoreStream.getGuilds().getMember(guild.getId(), meID),
StoreStream.getGuilds().getRoles().get(guild.getId()),
stageInstances.getStageInstancesForGuild(guild.getId()),
storeThreadsJoined.hasJoinedInternal(channel.getId())
);

var admin = PermissionUtils.can(adminMask, permissions);

Utils.mainThread.post(() -> {
if (admin || PermissionUtils.can(voicePermissionMask, permissions))
recordButton.setVisibility(View.VISIBLE);
else
recordButton.setVisibility(View.GONE);
});

showVoiceChannelIconIfCan(id);
} catch (NullPointerException e) {
logger.error(e);
}
Expand Down Expand Up @@ -254,7 +236,6 @@ public void onRecordStop(boolean send, long discordid) {
});
}


} catch (RuntimeException e) {
// if you instantly stop recording it causes crash
logger.error(e);
Expand All @@ -270,6 +251,38 @@ public void onRecordStop(boolean send, long discordid) {
}
}

public void showVoiceChannelIconIfCan(long channelId) {

var channel = new ChannelWrapper(StoreStream.getChannels().getChannel(channelId));
var guild = StoreStream.getGuilds().getGuild(channel.getGuildId());
if (channel.isDM()) {
// if channel is dm it causes guild to be null and causes issues
setRecordButtonVisibility(View.VISIBLE);
return;
}

var permissions = PermissionUtils.computePermissions(meID,
StoreStream.getChannels().getChannel(channelId),
StoreStream.getChannels().getGuildChannelInternal$app_productionGoogleRelease(guild.getId(), channel.getParentId()),
guild.getOwnerId(),
StoreStream.getGuilds().getMember(guild.getId(), meID),
StoreStream.getGuilds().getRoles().get(guild.getId()),
stageInstances.getStageInstancesForGuild(guild.getId()),
storeThreadsJoined.hasJoinedInternal(channel.getId())
);

var admin = PermissionUtils.can(adminMask, permissions);

if (admin || PermissionUtils.can(voicePermissionMask, permissions) || channel.isDM())
setRecordButtonVisibility(View.VISIBLE);
else
setRecordButtonVisibility(View.GONE);
}

public void setRecordButtonVisibility (int visibility){
Utils.mainThread.post(() -> recordButton.setVisibility(visibility));
}

@Override
public void stop(Context context) {
patcher.unpatchAll();
Expand Down

0 comments on commit 9717efc

Please sign in to comment.