Skip to content

Commit

Permalink
Add User.lastMessage, GuildMember.lastMessage and TextBasedChannel.la…
Browse files Browse the repository at this point in the history
…stMessage (#1135)

* Add User.lastMessage

* User.lastMessage and GuildMember.lastMessage

* User, GuildMember and TextBasedChannel lastMessage

* Update MessageCreate.js
  • Loading branch information
PgBiel authored and amishshah committed Jan 26, 2017
1 parent 87b600f commit c7f5b44
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/client/actions/MessageCreate.js
Expand Up @@ -14,17 +14,32 @@ class MessageCreateAction extends Action {
for (let i = 0; i < data.length; i++) {
messages[i] = channel._cacheMessage(new Message(channel, data[i], client));
}
channel.lastMessageID = messages[messages.length - 1].id;
if (user) user.lastMessageID = messages[messages.length - 1].id;
if (member) member.lastMessageID = messages[messages.length - 1].id;
const lastMessage = messages[messages.length - 1];
channel.lastMessageID = lastMessage.id;
channel.lastMessage = lastMessage;
if (user) {
user.lastMessageID = lastMessage.id;
user.lastMessage = lastMessage;
}
if (member) {
member.lastMessageID = lastMessage.id;
member.lastMessage = lastMessage;
}
return {
messages,
};
} else {
const message = channel._cacheMessage(new Message(channel, data, client));
channel.lastMessageID = data.id;
if (user) user.lastMessageID = data.id;
if (member) member.lastMessageID = data.id;
channel.lastMessage = message;
if (user) {
user.lastMessageID = data.id;
user.lastMessage = message;
}
if (member) {
member.lastMessageID = data.id;
member.lastMessage = message;
}
return {
message,
};
Expand Down
6 changes: 6 additions & 0 deletions src/structures/GuildMember.js
Expand Up @@ -39,6 +39,12 @@ class GuildMember {
* @type {?Snowflake}
*/
this.lastMessageID = null;

/**
* The Message object of the last message sent by the member in their guild, if one was sent.
* @type {?Message}
*/
this.lastMessage = null;
}

setup(data) {
Expand Down
6 changes: 6 additions & 0 deletions src/structures/User.js
Expand Up @@ -55,6 +55,12 @@ class User {
* @type {?Snowflake}
*/
this.lastMessageID = null;

/**
* The Message object of the last message sent by the user, if one was sent.
* @type {?Message}
*/
this.lastMessage = null;
}

patch(data) {
Expand Down
6 changes: 6 additions & 0 deletions src/structures/interface/TextBasedChannel.js
Expand Up @@ -20,6 +20,12 @@ class TextBasedChannel {
* @type {?Snowflake}
*/
this.lastMessageID = null;

/**
* The Message object of the last message in the channel, if one was sent.
* @type {?Message}
*/
this.lastMessage = null;
}

/**
Expand Down

0 comments on commit c7f5b44

Please sign in to comment.