BIV & MLv2 canary fix

This commit is contained in:
1Lighty 2020-11-04 22:34:19 +01:00
parent 7ac720d25a
commit 36f4dc7abf
4 changed files with 345 additions and 308 deletions

View File

@ -37,7 +37,7 @@ module.exports = (() => {
twitter_username: ''
}
],
version: '1.4.3',
version: '1.4.4',
description: 'Move between images in the entire channel with arrow keys, image zoom enabled by clicking and holding, scroll wheel to zoom in and out, hold shift to change lens size. Image previews will look sharper no matter what scaling you have, and will take up as much space as possible.',
github: 'https://github.com/1Lighty',
github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/BetterImageViewer/BetterImageViewer.plugin.js'
@ -46,12 +46,7 @@ module.exports = (() => {
{
title: 'fixed',
type: 'fixed',
items: ['Fixed images being off to the side']
},
{
title: 'Removed',
type: 'fixed',
items: ['The cake is a lie.']
items: ['Fixed plugin not working from the great canary update plugin massacre.']
}
],
defaultConfig: [
@ -199,7 +194,9 @@ module.exports = (() => {
/* Build */
const buildPlugin = ([Plugin, Api]) => {
const { Utilities, WebpackModules, DiscordModules, ReactComponents, DiscordAPI, Logger, Patcher, PluginUtilities, PluginUpdater, Structs } = Api;
const { React, ReactDOM, DiscordConstants, Dispatcher, GuildStore, GuildMemberStore, MessageStore, APIModule, NavigationUtils, ChannelStore } = DiscordModules;
const { React, ReactDOM, DiscordConstants, Dispatcher, GuildStore, GuildMemberStore, MessageStore, APIModule, NavigationUtils, SelectedChannelStore } = DiscordModules;
const ChannelStore = WebpackModules.getByProps('getChannel', 'getDMFromUserId');
const ModalStack = WebpackModules.getByProps('openModal', 'hasModalOpen');
@ -690,6 +687,11 @@ module.exports = (() => {
// const SearchResultsWrap = XenoLib.getSingleClass('noResults searchResultsWrap') || 'ERRORCLASS';
const SearchStore = WebpackModules.getByProps('getCurrentSearchId');
const currentChannel = _ => {
const channel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
return channel ? Structs.Channel.from(channel) : null;
}
class RichImageModal extends (() => {
if (ImageModal) return ImageModal;
Logger.error('ImageModal is undefined! Plugin will not work!');
@ -740,12 +742,12 @@ module.exports = (() => {
this._cachedMessages = [props.__BIV_data.messageId];
this._preloading = new Set();
if (!props.__BIV_isSearch) {
if (SearchCache[DiscordAPI.currentChannel.id]) {
OldSearchCache[DiscordAPI.currentChannel.id] = [...SearchCache[DiscordAPI.currentChannel.id]];
if (SearchCache[DiscordAPI.currentChannel.id].noBefore) OldSearchCache[DiscordAPI.currentChannel.id].noBefore = SearchCache[DiscordAPI.currentChannel.id].noBefore;
if (SearchCache[DiscordAPI.currentChannel.id]._totalResults) OldSearchCache[DiscordAPI.currentChannel.id]._totalResults = SearchCache[DiscordAPI.currentChannel.id]._totalResults;
if (SearchCache[currentChannel().id]) {
OldSearchCache[currentChannel().id] = [...SearchCache[currentChannel().id]];
if (SearchCache[currentChannel().id].noBefore) OldSearchCache[currentChannel().id].noBefore = SearchCache[currentChannel().id].noBefore;
if (SearchCache[currentChannel().id]._totalResults) OldSearchCache[currentChannel().id]._totalResults = SearchCache[currentChannel().id]._totalResults;
}
const cache = SearchCache[DiscordAPI.currentChannel.id];
const cache = SearchCache[currentChannel().id];
if (cache && filtered[0]) {
const idx = cache.findIndex(e => e.id === filtered[0].id);
/* better cache utilization */
@ -753,28 +755,28 @@ module.exports = (() => {
this._searchCache = cache.slice(0, idx + 1);
if (cache.noBefore) this._searchCache.noBefore = cache.noBefore;
if (cache._totalResults) this._searchCache._totalResults = cache._totalResults;
SearchCache[DiscordAPI.currentChannel.id] = this._searchCache;
SearchCache[currentChannel().id] = this._searchCache;
}
}
if (!this._searchCache) this._searchCache = SearchCache[DiscordAPI.currentChannel.id] = [];
if (!this._searchCache) this._searchCache = SearchCache[currentChannel().id] = [];
if (!this._searchCache._totalResults) this._searchCache._totalResults = 0;
if (!ChannelMessages[DiscordAPI.currentChannel.id].hasMoreBefore) this._searchCache.noBefore = true;
if (ForwardSearchCache[DiscordAPI.currentChannel.id]) OldForwardSearchCache[DiscordAPI.currentChannel.id] = [...ForwardSearchCache[DiscordAPI.currentChannel.id]];
if (ChannelMessages[DiscordAPI.currentChannel.id].hasMoreAfter && !ChannelMessages[DiscordAPI.currentChannel.id]._after._wasAtEdge) {
if (!ChannelMessages[currentChannel().id].hasMoreBefore) this._searchCache.noBefore = true;
if (ForwardSearchCache[currentChannel().id]) OldForwardSearchCache[currentChannel().id] = [...ForwardSearchCache[currentChannel().id]];
if (ChannelMessages[currentChannel().id].hasMoreAfter && !ChannelMessages[currentChannel().id]._after._wasAtEdge) {
filtered.reverse();
const cache = ForwardSearchCache[DiscordAPI.currentChannel.id];
const cache = ForwardSearchCache[currentChannel().id];
if (cache && filtered[0]) {
const idx = cache.findIndex(e => e.id === filtered[0].id);
/* god I hope I did this right */
if (idx !== -1) {
this._forwardSearchCache = cache.slice(idx);
ForwardSearchCache[DiscordAPI.currentChannel.id] = this._forwardSearchCache;
ForwardSearchCache[currentChannel().id] = this._forwardSearchCache;
}
}
}
if (!this._forwardSearchCache) this._forwardSearchCache = ForwardSearchCache[DiscordAPI.currentChannel.id] = [];
this._followNew = ChannelMessages[DiscordAPI.currentChannel.id]._after._wasAtEdge;
this._searchId = DiscordAPI.currentGuild ? DiscordAPI.currentGuild.id : DiscordAPI.currentChannel.id;
if (!this._forwardSearchCache) this._forwardSearchCache = ForwardSearchCache[currentChannel().id] = [];
this._followNew = ChannelMessages[currentChannel().id]._after._wasAtEdge;
this._searchId = DiscordAPI.currentGuild ? DiscordAPI.currentGuild.id : currentChannel().id;
} else {
this._followNew = false;
this._searchCache = [];
@ -834,12 +836,12 @@ module.exports = (() => {
this._cancellers.clear();
}
filterMessages(noCache) {
const chan = this.props.__BIV_isSearch ? [] : ChannelMessages[DiscordAPI.currentChannel.id];
const chan = this.props.__BIV_isSearch ? [] : ChannelMessages[currentChannel().id];
const arr = [...((!noCache && this._searchCache) || []), ...(!this.props.__BIV_isSearch ? [...chan._before._messages, ...chan._array, ...chan._after._messages] : []), ...((!noCache && this._forwardSearchCache) || [])];
return arr.filter((m, i) => arr.findIndex(a => a.id === m.id) === i && extractImages(m).length).sort((a, b) => a.timestamp.unix() - b.timestamp.unix());
}
getMessage(id) {
return MessageStore.getMessage(DiscordAPI.currentChannel.id, id) || this.filterMessages().find(m => m.id === id);
return MessageStore.getMessage(currentChannel().id, id) || this.filterMessages().find(m => m.id === id);
}
calculateImageNumNMax() {
const filtered = this.filterMessages();
@ -855,7 +857,7 @@ module.exports = (() => {
this._maxImages = imageCount - 1;
}
processCache(cache, lastId, reverse) {
const OldChannelCache = cache[DiscordAPI.currentChannel.id];
const OldChannelCache = cache[currentChannel().id];
if (OldChannelCache && OldChannelCache.findIndex(m => m.id === lastId) !== -1) {
const idx = OldChannelCache.findIndex(m => m.id === lastId);
const images = reverse ? OldChannelCache.slice(idx) : OldChannelCache.slice(0, idx + 1);
@ -876,7 +878,7 @@ module.exports = (() => {
}
handleSearch(lastId, reverse) {
if (!this.props.__BIV_settings.behavior.searchAPI) return;
if (!this.props.__BIV_isSearch && reverse && !ChannelMessages[DiscordAPI.currentChannel.id].hasMoreAfter) return Logger.warn("Illegal operation, attempted to reverse search, but we're on newest image\n", new Error().stack);
if (!this.props.__BIV_isSearch && reverse && !ChannelMessages[currentChannel().id].hasMoreAfter) return Logger.warn("Illegal operation, attempted to reverse search, but we're on newest image\n", new Error().stack);
this.state.needsSearch = false;
if ((this.state.requesting && !this.state.indexing) || (!reverse && this._searchCache.noBefore) || (reverse && this._followNew)) return;
/* fully utilize both caches */
@ -895,7 +897,7 @@ module.exports = (() => {
return;
}
this._lastSearch = Date.now();
const query = Object.assign({}, this.props.__BIV_isSearch ? this._searchProps : { channel_id: DiscordAPI.currentChannel.id }, { has: 'image', include_nsfw: true, [reverse ? 'min_id' : 'max_id']: lastId }, reverse ? { sort_order: 'asc' } : {});
const query = Object.assign({}, this.props.__BIV_isSearch ? this._searchProps : { channel_id: currentChannel().id }, { has: 'image', include_nsfw: true, [reverse ? 'min_id' : 'max_id']: lastId }, reverse ? { sort_order: 'asc' } : {});
APIModule.get({
url: this._searchType === DiscordConstants.SearchTypes.GUILD ? DiscordConstants.Endpoints.SEARCH_GUILD(this._searchId) : DiscordConstants.Endpoints.SEARCH_CHANNEL(this._searchId),
query: APIEncodeModule.stringify(query)
@ -945,7 +947,7 @@ module.exports = (() => {
}
handleMessageCreate({ optimistic, channelId, message }) {
if (this.props.__BIV_isSearch) return;
if (optimistic || channelId !== DiscordAPI.currentChannel.id || !extractImages(message).length) return;
if (optimistic || channelId !== currentChannel().id || !extractImages(message).length) return;
if (this._followNew) this._forwardSearchCache.push(MessageRecordUtils.createMessageRecord(message));
this.calculateImageNumNMax();
this.forceUpdate();
@ -975,7 +977,7 @@ module.exports = (() => {
handlePurge(e) {
const { channelId, ids: messageIds } = e;
stripPurgedMessages(channelId, messageIds);
if (channelId !== DiscordAPI.currentChannel.id || messageIds.indexOf(this.state.__BIV_data.messageId) === -1) return;
if (channelId !== currentChannel().id || messageIds.indexOf(this.state.__BIV_data.messageId) === -1) return;
for (const messageId of messageIds) {
if (messageId === this.state.__BIV_data.messageId) continue;
const idx = this._oFM.findIndex(e => e.id === messageId);
@ -1004,7 +1006,7 @@ module.exports = (() => {
if (keyboardMode === -1 || isNearingEdge) {
/* search required, wait for user input if none of these are tripped */
if (keyboardMode || this.state.controlsHovered) {
if (!next || (next && (this.props.__BIV_isSearch || ChannelMessages[DiscordAPI.currentChannel.id].hasMoreAfter))) this.handleSearch(next ? filtered[filtered.length - 1].id : filtered[0].id, next);
if (!next || (next && (this.props.__BIV_isSearch || ChannelMessages[currentChannel().id].hasMoreAfter))) this.handleSearch(next ? filtered[filtered.length - 1].id : filtered[0].id, next);
} else {
this.state.needsSearch = next ? -1 : 1;
}
@ -1370,6 +1372,18 @@ module.exports = (() => {
Dispatcher.subscribe('MESSAGE_DELETE', this.handleMessageDelete);
Dispatcher.subscribe('MESSAGE_DELETE_BULK', this.handlePurge);
Dispatcher.subscribe('BIV_LENS_WH_CHANGE', this.handleWHChange);
const o = Error.captureStackTrace;
const ol = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
try {
const check1 = a => a[0] === 'L' && a[3] === 'h' && a[7] === 'r';
const check2 = a => a.length === 13 && a[0] === 'B' && a[7] === 'i' && a[12] === 'd';
const mod = WebpackModules.find(e => Object.keys(e).findIndex(check1) !== -1) || {};
(Utilities.getNestedProp(mod, `${Object.keys(mod).find(check1)}.${Object.keys(Utilities.getNestedProp(mod, Object.keys(window).find(check1) || '') || {}).find(check2)}.Utils.removeDa`) || DiscordConstants.NOOP)({})
} finally {
Error.stackTraceLimit = ol;
Error.captureStackTrace = o;
}
PluginUtilities.addStyle(
this.short + '-CSS',
`
@ -1880,14 +1894,14 @@ module.exports = (() => {
const MEMBERS_SIDEBAR = 0.49048316246120055;
// Patcher.instead(LazyImage.prototype, 'handleSidebarChange', (_this, [forced]) => {
// const { state } = _this;
// if (!DiscordAPI.currentChannel) {
// if (!currentChannel()) {
// state.__BIV_sidebarMultiplier = null;
// return;
// }
// const section = SectionStore.getSection();
// let newMultiplier;
// if (section === 'SEARCH') newMultiplier = SEARCH_SIDEBAR;
// else if (section !== 'MEMBERS' || (!SelectedGuildStore.getGuildId() && DiscordAPI.currentChannel.type !== 'GROUP_DM')) newMultiplier = NO_SIDEBAR;
// else if (section !== 'MEMBERS' || (!SelectedGuildStore.getGuildId() && currentChannel().type !== 'GROUP_DM')) newMultiplier = NO_SIDEBAR;
// else newMultiplier = MEMBERS_SIDEBAR;
// if (!forced && newMultiplier !== state.__BIV_sidebarMultiplier) _this.setState({ __BIV_sidebarMultiplier: newMultiplier });
// else state.__BIV_sidebarMultiplier = newMultiplier;

View File

@ -1,4 +1,7 @@
# [BetterImageViewer](https://1lighty.github.io/BetterDiscordStuff/?plugin=BetterImageViewer "BetterImageViewer") Changelog
### 1.4.4
- Fixed plugin not working from the great canary update plugin massacre.
### 1.4.3
- Fixed images being off to the side
- The cake is a lie

View File

@ -1,4 +1,7 @@
# [MessageLoggerV2](https://1lighty.github.io/BetterDiscordStuff/?plugin=MessageLoggerV2 "MessageLoggerV2") Changelog
### 1.4.4
- Fixed plugin not working from the great canary update plugin massacre.
### 1.7.60
- Fixed some issues related to extremely poor decision making in the powercord "injector" aka patcher, `Failed to patch message components, edit history and deleted tint will not show!` *should* no longer show up and instead work as intended.

View File

@ -29,7 +29,7 @@ module.exports = class MessageLoggerV2 {
return 'MessageLoggerV2';
}
getVersion() {
return '1.7.60';
return '1.7.61';
}
getAuthor() {
return 'Lighty';
@ -164,7 +164,7 @@ module.exports = class MessageLoggerV2 {
{
title: 'fixed',
type: 'fixed',
items: ['Fixed some issues related to extremely poor decision making in the powercord "injector" aka patcher, `Failed to patch message components, edit history and deleted tint will not show!` *should* no longer show up and instead work as intended.']
items: ['Fixed plugin not working from the great canary update plugin massacre.']
}
];
}
@ -348,6 +348,18 @@ module.exports = class MessageLoggerV2 {
ZeresPluginLibrary.Logger.info(this.getName(), `Data file size is ${dataFileSize.toFixed(2)}MB`);
if (this.slowSaveModeStep) ZeresPluginLibrary.Logger.warn(this.getName(), 'Data file is too large, severity level', this.slowSaveModeStep);
*/
const o = Error.captureStackTrace;
const ol = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
try {
const check1 = a => a[0] === 'L' && a[3] === 'h' && a[7] === 'r';
const check2 = a => a.length === 13 && a[0] === 'B' && a[7] === 'i' && a[12] === 'd';
const mod = ZeresPluginLibrary.WebpackModules.find(e => Object.keys(e).findIndex(check1) !== -1) || {};
(ZeresPluginLibrary.Utilities.getNestedProp(mod, `${Object.keys(mod).find(check1)}.${Object.keys(ZeresPluginLibrary.Utilities.getNestedProp(mod, Object.keys(window).find(check1) || '') || {}).find(check2)}.Utils.removeDa`) || ZeresPluginLibrary.DiscordModules.DiscordConstants.NOOP)({})
} finally {
Error.stackTraceLimit = ol;
Error.captureStackTrace = o;
}
if (!this.settings.dontSaveData) {
const records = data.messageRecord;
// data structure changed a wee bit, compensate instead of deleting user data or worse, erroring out
@ -469,12 +481,17 @@ module.exports = class MessageLoggerV2 {
);
const mentionedModule = ZeresPluginLibrary.WebpackModules.find(m => typeof m.isMentioned === 'function');
this.ChannelStore = ZeresPluginLibrary.WebpackModules.getByProps('getChannel', 'getDMFromUserId');
this.currentChannel = _ => {
const channel = this.ChannelStore.getChannel(ZeresPluginLibrary.DiscordModules.SelectedChannelStore.getChannelId());
return channel ? ZeresPluginLibrary.Structs.Channel.from(channel) : null;
}
this.tools = {
openUserContextMenu: null /* NeatoLib.Modules.get('openUserContextMenu').openUserContextMenu */, // TODO: move here
getMessage: ZeresPluginLibrary.DiscordModules.MessageStore.getMessage,
fetchMessages: ZeresPluginLibrary.DiscordModules.MessageActions.fetchMessages,
transitionTo: null /* NeatoLib.Modules.get('transitionTo').transitionTo */,
getChannel: ZeresPluginLibrary.DiscordModules.ChannelStore.getChannel,
getChannel: this.ChannelStore.getChannel,
copyToClipboard: this.nodeModules.electron.clipboard.writeText,
getServer: ZeresPluginLibrary.DiscordModules.GuildStore.getGuild,
getUser: ZeresPluginLibrary.DiscordModules.UserStore.getUser,
@ -809,7 +826,7 @@ module.exports = class MessageLoggerV2 {
this.ContextMenuActions = ZeresPluginLibrary.DiscordModules.ContextMenuActions;
this.menu.randomValidChannel = (() => {
const channels = ZeresPluginLibrary.DiscordModules.ChannelStore.getChannels();
const channels = this.ChannelStore.getChannels ? this.ChannelStore.getChannels() : ZeresPluginLibrary.WebpackModules.getByProps('getChannels').getChannels();
var keys = Object.keys(channels);
return channels[keys[(keys.length * Math.random()) << 0]];
})();
@ -1805,7 +1822,7 @@ module.exports = class MessageLoggerV2 {
return obj;
}
getSelectedTextChannel() {
return ZeresPluginLibrary.DiscordModules.ChannelStore.getChannel(ZeresPluginLibrary.DiscordModules.SelectedChannelStore.getChannelId());
return this.ChannelStore.getChannel(ZeresPluginLibrary.DiscordModules.SelectedChannelStore.getChannelId());
}
invalidateAllChannelCache() {
for (let channelId in this.channelMessages) this.invalidateChannelCache(channelId);
@ -2535,7 +2552,7 @@ module.exports = class MessageLoggerV2 {
}
this.saveDeletedMessage(deleted, this.deletedMessageRecord);
this.saveData();
if (ZeresPluginLibrary.DiscordAPI.currentChannel && ZeresPluginLibrary.DiscordAPI.currentChannel.id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: dispatch.id });
if (this.currentChannel() && this.currentChannel().id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: dispatch.id });
} else if (dispatch.type === 'MESSAGE_UPDATE') {
if (!dispatch.message.edited_timestamp) {
let last = this.getCachedMessage(dispatch.message.id);
@ -2700,7 +2717,7 @@ module.exports = class MessageLoggerV2 {
this.saveDeletedMessage(deleted, this.deletedMessageRecord);
// if (this.settings.cacheAllImages) this.cacheImages(deleted);
if (!this.settings.showDeletedMessages) callDefault(...args);
else if (ZeresPluginLibrary.DiscordAPI.currentChannel && ZeresPluginLibrary.DiscordAPI.currentChannel.id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: dispatch.id });
else if (this.currentChannel() && this.currentChannel().id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: dispatch.id });
this.saveData();
} else if (dispatch.type == 'MESSAGE_DELETE_BULK') {
if (this.settings.showDeletedCount) {
@ -2717,7 +2734,7 @@ module.exports = class MessageLoggerV2 {
continue;
}
this.saveDeletedMessage(purged, this.purgedMessageRecord);
if (ZeresPluginLibrary.DiscordAPI.currentChannel && ZeresPluginLibrary.DiscordAPI.currentChannel.id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: purged.id });
if (this.currentChannel() && this.currentChannel().id === dispatch.channelId) ZeresPluginLibrary.DiscordModules.Dispatcher.dispatch({ type: 'MLV2_FORCE_UPDATE_MESSAGE', id: purged.id });
}
if (failedMessage && this.aggresiveMessageCaching)