Skip to content

Commit

Permalink
Fix mergingWithPartialMsg: return new instance
Browse files Browse the repository at this point in the history
Self cannot be mutated since mutable functions don’t exist in classes, so return a new instance instead. This should fix this actions build failure.
  • Loading branch information
cryptoAlgorithm committed Aug 11, 2022
1 parent 0cdb7f6 commit 87bb3f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"location" : "https://github.com/SwiftcordApp/DiscordKit",
"state" : {
"branch" : "main",
"revision" : "2587b1df17fc2b18346b630e1a2f5635d209c94b"
"revision" : "5a1cf337615a73855ce20420a76b45c39dcaec63"
}
},
{
Expand Down
56 changes: 32 additions & 24 deletions Swiftcord/Utils/MergeStructs/MergePartialMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@ import Foundation
import DiscordKitCommon

extension Message {
func mergeWithPartialMsg(_ partial: PartialMessage) {
author = partial.author ?? author
member = partial.member ?? member
content = partial.content ?? content
edited_timestamp = partial.edited_timestamp ?? edited_timestamp
tts = partial.tts ?? tts
mention_everyone = partial.mention_everyone ?? mention_everyone
mentions = partial.mentions ?? mentions
mention_roles = partial.mention_roles ?? mention_roles
mention_channels = partial.mention_channels ?? mention_channels
attachments = partial.attachments ?? attachments
embeds = partial.embeds ?? embeds
reactions = partial.reactions ?? reactions
pinned = partial.pinned ?? pinned
webhook_id = partial.webhook_id ?? webhook_id
activity = partial.activity ?? activity
application = partial.application ?? application
application_id = partial.application_id ?? application_id
message_reference = partial.message_reference ?? message_reference
flags = partial.flags ?? flags
interaction = partial.interaction ?? interaction
thread = partial.thread ?? thread
components = partial.components ?? components
sticker_items = partial.sticker_items ?? sticker_items
func mergingWithPartialMsg(_ partial: PartialMessage) -> Message {
Message(
id: id,
channel_id: channel_id,
guild_id: guild_id,
author: partial.author ?? author,
member: partial.member ?? member,
content: partial.content ?? content,
timestamp: timestamp,
edited_timestamp: partial.edited_timestamp ?? edited_timestamp,
tts: partial.tts ?? tts,
mention_everyone: partial.mention_everyone ?? mention_everyone,
mentions: partial.mentions ?? mentions,
mention_roles: partial.mention_roles ?? mention_roles,
mention_channels: partial.mention_channels ?? mention_channels,
attachments: partial.attachments ?? attachments,
embeds: partial.embeds ?? embeds,
reactions: partial.reactions ?? reactions,
pinned: partial.pinned ?? pinned,
webhook_id: webhook_id,
type: type,
activity: partial.activity ?? activity,
application: partial.application ?? application,
application_id: partial.application_id ?? application_id,
message_reference: message_reference,
flags: partial.flags ?? flags,
referenced_message: partial.referenced_message ?? referenced_message,
interaction: partial.interaction ?? interaction,
thread: partial.thread ?? thread,
components: partial.components ?? components,
sticker_items: partial.sticker_items ?? sticker_items
)
}
}
4 changes: 1 addition & 3 deletions Swiftcord/Views/Message/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ struct MessagesView: View {
case .messageUpdate:
guard let newMsg = d as? PartialMessage else { break }
if let updatedIdx = messages.firstIndex(where: { $0.id == newMsg.id }) {
var updatedMsg = messages[updatedIdx]
updatedMsg.mergeWithPartialMsg(newMsg)
messages[updatedIdx] = updatedMsg
messages[updatedIdx] = messages[updatedIdx].mergingWithPartialMsg(newMsg)
}
case .messageDelete:
guard let deletedMsg = d as? MessageDelete else { break }
Expand Down

0 comments on commit 87bb3f2

Please sign in to comment.