Merge pull request #231 from GetStream/add-merge-function
[Message, ChannelModel] Add merge helper functions for easier data manipulation
This commit is contained in:
@@ -1108,30 +1108,7 @@ class ChannelClientState {
|
|||||||
|
|
||||||
final oldIndex = newMessages.indexWhere((m) => m.id == message.id);
|
final oldIndex = newMessages.indexWhere((m) => m.id == message.id);
|
||||||
if (oldIndex != -1) {
|
if (oldIndex != -1) {
|
||||||
newMessages[oldIndex] = newMessages[oldIndex].copyWith(
|
newMessages[oldIndex] = newMessages[oldIndex].merge(message);
|
||||||
text: message.text,
|
|
||||||
type: message.type,
|
|
||||||
attachments: message.attachments,
|
|
||||||
mentionedUsers: message.mentionedUsers,
|
|
||||||
reactionCounts: message.reactionCounts,
|
|
||||||
reactionScores: message.reactionScores,
|
|
||||||
latestReactions: message.latestReactions,
|
|
||||||
ownReactions: message.ownReactions,
|
|
||||||
parentId: message.parentId,
|
|
||||||
quotedMessageId: message.quotedMessageId,
|
|
||||||
quotedMessage: message.quotedMessage,
|
|
||||||
replyCount: message.replyCount,
|
|
||||||
showInChannel: message.showInChannel,
|
|
||||||
command: message.command,
|
|
||||||
silent: message.silent,
|
|
||||||
createdAt: message.createdAt,
|
|
||||||
updatedAt: message.updatedAt,
|
|
||||||
deletedAt: message.deletedAt,
|
|
||||||
user: message.user,
|
|
||||||
status: message.status,
|
|
||||||
threadParticipants: message.threadParticipants,
|
|
||||||
extraData: message.extraData,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
newMessages.add(message);
|
newMessages.add(message);
|
||||||
}
|
}
|
||||||
@@ -1395,20 +1372,7 @@ class ChannelClientState {
|
|||||||
|
|
||||||
_channelState = _channelState.copyWith(
|
_channelState = _channelState.copyWith(
|
||||||
messages: newMessages,
|
messages: newMessages,
|
||||||
channel: _channelState.channel?.copyWith(
|
channel: _channelState.channel?.merge(updatedState.channel),
|
||||||
lastMessageAt: updatedState.channel?.lastMessageAt,
|
|
||||||
createdAt: updatedState.channel?.createdAt,
|
|
||||||
type: updatedState.channel?.type,
|
|
||||||
extraData: updatedState.channel?.extraData,
|
|
||||||
updatedAt: updatedState.channel?.updatedAt,
|
|
||||||
id: updatedState.channel?.id,
|
|
||||||
createdBy: updatedState.channel?.createdBy,
|
|
||||||
config: updatedState.channel?.config,
|
|
||||||
deletedAt: updatedState.channel?.deletedAt,
|
|
||||||
cid: updatedState.channel?.cid,
|
|
||||||
frozen: updatedState.channel?.frozen,
|
|
||||||
memberCount: updatedState.channel?.memberCount,
|
|
||||||
),
|
|
||||||
watchers: newWatchers,
|
watchers: newWatchers,
|
||||||
watcherCount: updatedState.watcherCount,
|
watcherCount: updatedState.watcherCount,
|
||||||
members: newMembers,
|
members: newMembers,
|
||||||
|
|||||||
@@ -142,4 +142,25 @@ class ChannelModel {
|
|||||||
extraData: extraData ?? this.extraData,
|
extraData: extraData ?? this.extraData,
|
||||||
team: team ?? this.team,
|
team: team ?? this.team,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Returns a new [ChannelModel] that is a combination of this channelModel and the given
|
||||||
|
/// [other] channelModel.
|
||||||
|
ChannelModel merge(ChannelModel other) {
|
||||||
|
if (other == null) return this;
|
||||||
|
return copyWith(
|
||||||
|
id: other.id,
|
||||||
|
type: other.type,
|
||||||
|
cid: other.cid,
|
||||||
|
config: other.config,
|
||||||
|
createdBy: other.createdBy,
|
||||||
|
frozen: other.frozen,
|
||||||
|
lastMessageAt: other.lastMessageAt,
|
||||||
|
createdAt: other.createdAt,
|
||||||
|
updatedAt: other.updatedAt,
|
||||||
|
deletedAt: other.deletedAt,
|
||||||
|
memberCount: other.memberCount,
|
||||||
|
extraData: other.extraData,
|
||||||
|
team: other.team,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,6 +250,38 @@ class Message {
|
|||||||
deletedAt: deletedAt ?? this.deletedAt,
|
deletedAt: deletedAt ?? this.deletedAt,
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Returns a new [Message] that is a combination of this message and the given
|
||||||
|
/// [other] message.
|
||||||
|
Message merge(Message other) {
|
||||||
|
if (other == null) return this;
|
||||||
|
return copyWith(
|
||||||
|
id: other.id,
|
||||||
|
text: other.text,
|
||||||
|
type: other.type,
|
||||||
|
attachments: other.attachments,
|
||||||
|
mentionedUsers: other.mentionedUsers,
|
||||||
|
reactionCounts: other.reactionCounts,
|
||||||
|
reactionScores: other.reactionScores,
|
||||||
|
latestReactions: other.latestReactions,
|
||||||
|
ownReactions: other.ownReactions,
|
||||||
|
parentId: other.parentId,
|
||||||
|
quotedMessage: other.quotedMessage,
|
||||||
|
quotedMessageId: other.quotedMessageId,
|
||||||
|
replyCount: other.replyCount,
|
||||||
|
threadParticipants: other.threadParticipants,
|
||||||
|
showInChannel: other.showInChannel,
|
||||||
|
command: other.command,
|
||||||
|
createdAt: other.createdAt,
|
||||||
|
silent: other.silent,
|
||||||
|
extraData: other.extraData,
|
||||||
|
user: other.user,
|
||||||
|
shadowed: other.shadowed,
|
||||||
|
updatedAt: other.updatedAt,
|
||||||
|
deletedAt: other.deletedAt,
|
||||||
|
status: other.status,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A translated message
|
/// A translated message
|
||||||
|
|||||||
Reference in New Issue
Block a user