Skip to content

Discord API#191

Merged
zerebos merged 165 commits into
JsSucks:masterfrom
samuelthomas2774:discord-api
Aug 5, 2018
Merged

Discord API#191
zerebos merged 165 commits into
JsSucks:masterfrom
samuelthomas2774:discord-api

Conversation

@samuelthomas2774
Copy link
Copy Markdown

@samuelthomas2774 samuelthomas2774 commented Apr 14, 2018

Additional changes not related to the Discord API:

  • Wrap Discord's preload script instead of enabling Node integration
  • Add multi option radio settings
  • Add getting all components used to render a single element to Reflection
  • Add the ability to pass a filter to ReactComponents to select the correct component from Reflection
  • Add data attributes to the user profile modal
  • Patch the user profile modal component instead of waiting for it to be opened
  • Add data attributes to the user popout
  • Patch all components at once instead of waiting for the previous component to be found and patched
  • Make some Vue components available to plugins
  • Move Filters to common and and it to the plugin API
  • Add ReactHelpers to the plugin API
  • Add DOM, DOMObserver and VueInjector to the plugin API
  • Add a function to wrap a Vue component in a React component
  • Add getting known modules as properties of WebpackModules
  • Use top and left to position tooltips and popovers
  • Use Date instead of Moment.js in Logger
  • Show proxies instead of the target in logs
  • Allow patching arrays
  • Get class names from WebpackModules
  • Add highlight.js to WebpackModules
  • Rename HTMLUtils to SimpleMarkdown
  • Use Node.js v8 for Travis CI builds
  • Use ES6 imports/exports
  • Fix favourite emotes array being undefined when loading settings
  • Fix colour picker/dropdrop options being hidden when in a drawer
  • Fix EventsWrapper not unsubscribing to events
  • Fix badges not being rendered when jumping to a message
  • Fix settings panel not displaying on Linux
  • Fix for webpack 4

@zerebos
Copy link
Copy Markdown
Member

zerebos commented Apr 14, 2018

Aside from the snake_case being there (especially since it's being intermixed with camelCase), I would approve this. It's pretty close to the restructure I had planned for the next version of the API anyways and takes quite a few things to add off my list.

@Jiiks Jiiks requested a review from zerebos April 21, 2018 17:38
Copy link
Copy Markdown
Member

@zerebos zerebos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this restructure is nice, as it gives more explicit types to objects. There were a couple errors, and some naming convention issues that should be addressed however.

Comment thread client/src/structs/discord/user.js Outdated
async ensurePrivateChannel() {
if (DiscordApi.currentUser === this)
throw new Error('Cannot create a direct message channel to the current user.');
return Channel.from(await Modules.PrivateChannelActions.ensurePrivateChannel(DiscordApi.currentUser.id, this.id));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use Channel.fromId since ensurePrivateChannel returns the ID of the channel

Comment thread client/src/structs/discord/channel.js Outdated
/**
* Whether this channel is the guild's default channel.
*/
get default_channel() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean return should have affirmative or "is" prefix. default_channel should be isDefaultChannel

let response = {};
if (parse) response = await Modules.MessageActions._sendMessage(this.id, Modules.MessageParser.parse(this.discordObject, content));
else response = await Modules.MessageActions._sendMessage(this.id, {content});
return Message.from(Modules.MessageStore.getMessage(this.id, response.body.id));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it returns Message but you have it labelled as returning Promise

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an async function so the actual return value is a promise. I'll add that it resolves to a message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, actual return is the Promise, but I think it's best we say what it resolves to especially since it should always resolve to Message type

Comment thread client/src/structs/discord/channel.js Outdated
static get GroupChannel() { return GroupChannel }

get id() { return this.discordObject.id }
get application_id() { return this.discordObject.application_id }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make this comment once, but it applies throughout all these changes. You have a mix of snake_case and camelCase here and the codebase we have already has been going with camelCase although of course we have consistencies in the codebase itself but I think it's better to make sure we consistently use camelCase. For reference look at the similar structs done here: https://github.com/JsSucks/BetterDiscordApp/tree/master/client/src/structs/socketstructs

I can tell you were trying to use snake_case for attributes but it wasn't done consistently and it feels weird to have two quite different naming schemes happening at the same time.

Copy link
Copy Markdown
Author

@samuelthomas2774 samuelthomas2774 Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about the socket structs. I tried to normalise attribute names to snake case as Discord was using them inconsistently. I'll change these to camel case then.

Comment thread client/src/structs/discord/channel.js Outdated
/**
* Whether this channel is currently selected.
*/
get selected() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably change this to isSelected

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread client/src/structs/discord/guild.js Outdated
/**
* Whether this channel is currently selected.
*/
get selected() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the other one we should probably rename to isSelected

Comment thread client/src/structs/discord/message.js Outdated

/**
* Deletes the message.
* TODO: how do we know if the message was deleted successfully?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do a temporary subscribe to the message delete event

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would tell us if the message was deleted successfully, but won't help if it isn't. We would only be able to tell if it failed if a timeout passes and we wouldn't be able to tell if an error had been returned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally it does attempt to retry for awhile if there are errors and then fire the event when it completes. Otherwise we could copy the internals of the deleteMessage function but add in passing the error callback to the delete() request

* Deletes the message.
* TODO: how do we know if the message was deleted successfully?
*/
delete() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a permission check similar to edit message here

Comment thread client/src/structs/discord/user.js Outdated
return Modules.UserStatusStore.getActivity(this.id);
}

get direct_messages() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name here is unclear, makes it seem like it would return a list of all the DMs

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed this to privateChannel.

Modules.MessageActions.startEditMessage(this.channel_id, this.id, this.content);
}
static get modules() { return Modules }
static get User() { return User }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is the point of having all the types as static members a way for plugins to check types of objects?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally added it so you could use static functions like Channel.fromId where you had a channel's ID instead of getting all channels. I didn't actually think about that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright, that works as well, I didn't think about it that way either. Personally I have been doing api.channels.find(c => c.id == "XXXXXXXXXX") 😀

…icates when multiple modals are opened at the same time
# Conflicts:
#	client/src/modules/pluginapi.js
#	client/src/ui/bdui.js
#	client/src/ui/dom.js
#	client/src/ui/ui.js
#	package-lock.json
#	package.json
@samuelthomas2774
Copy link
Copy Markdown
Author

  • Add toasts (JsSucks/toasts)
    • Added an option to add additional classes to the toast element
  • Add class normaliser
    • Classes like guildsWrapper-5TJh6A are normalised to da-guilds-wrapper
  • Add support for (transpiled) ES6 modules as a plugin's main file
  • Emit events when loading (Discord) modules
    • module-loading with the module object before the module is evaluated
    • module-loaded with the module object after the module is evaluated
    • modules-loaded with an array of module objects after they've loaded
  • Add functions to wait for modules to be loaded
  • Add getting all stateNodes to Reflection
  • Add a function to force update all instances of a component
  • Delete old logs on startup
  • Add custom window preferences
  • Add settings section to edit window preferences
  • Add settings proxy
    • Values can be retrieved from sets/categories as normal properties: set.proxy.category.setting
  • Use request to check for updates
  • Disable loading of emotes when emotes are disabled
  • Use an observer to detect new React components instead of a timer
  • Fix escape key closing all modals
  • Fix keybind settings not activated when in a text input
  • Fix components not being selected properly due to Discord updates
  • Fix leaks in keybind settings
    • Plugins must unbind the keybind-activated event from all keybind settings they bind to when stopping or when removing the last reference to them
  • Add development webpack plugins

@zerebos
Copy link
Copy Markdown
Member

zerebos commented Aug 5, 2018

Re: The weakmaps/sets it goes against the point of them because the references are supposed to be weak and allow garbage collection, what you were doing introduces non-determinism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants