forked from Ivasoft/mattermost-mobile
[Gekidou] Allow multiple posts in thread and posts in channel for a specific root or channel (#5594)
* Allow multiple posts in thread and posts in channel for a specific root or channel * Apply suggestions from code review Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com> Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
@@ -75,7 +75,7 @@ const PostsInChannelHandler = (superclass: any) => class extends superclass {
|
||||
|
||||
// Find the records in the PostsInChannel table that have a matching channel_id
|
||||
const chunks = (await this.database.get(POSTS_IN_CHANNEL).query(
|
||||
Q.where('id', channelId),
|
||||
Q.where('channel_id', channelId),
|
||||
Q.experimentalSortBy('latest', Q.desc),
|
||||
).fetch()) as PostsInChannelModel[];
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ const PostsInThreadHandler = (superclass: any) => class extends superclass {
|
||||
const chunks = (await retrieveRecords({
|
||||
database: this.database,
|
||||
tableName: POSTS_IN_THREAD,
|
||||
condition: Q.where('id', rootId),
|
||||
condition: Q.where('root_id', rootId),
|
||||
})) as PostsInThreadModel[];
|
||||
|
||||
if (chunks.length) {
|
||||
const chunk = chunks[0];
|
||||
const newValue = {
|
||||
id: rootId,
|
||||
root_id: rootId,
|
||||
earliest: Math.min(chunk.earliest, firstPost.create_at),
|
||||
latest: Math.max(chunk.latest, lastPost.create_at),
|
||||
};
|
||||
@@ -50,7 +50,7 @@ const PostsInThreadHandler = (superclass: any) => class extends superclass {
|
||||
} else {
|
||||
// create chunk
|
||||
create.push({
|
||||
id: rootId,
|
||||
root_id: rootId,
|
||||
earliest: firstPost.create_at,
|
||||
latest: lastPost.create_at,
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('*** POST Prepare Records Test ***', () => {
|
||||
record: undefined,
|
||||
raw: {
|
||||
id: 'ps81iqbddesfby8jayz7owg4yypoo',
|
||||
post_id: '8swgtrrdiff89jnsiwiip3y1eoe',
|
||||
root_id: '8swgtrrdiff89jnsiwiip3y1eoe',
|
||||
earliest: 1596032651748,
|
||||
latest: 1597032651748,
|
||||
},
|
||||
|
||||
@@ -76,7 +76,8 @@ export const transformPostInThreadRecord = ({action, database, value}: Transform
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
const fieldsMapper = (postsInThread: PostsInThreadModel) => {
|
||||
postsInThread._raw.id = isCreateAction ? raw.id : record.id;
|
||||
postsInThread._raw.id = isCreateAction ? (raw.id || postsInThread.id) : record.id;
|
||||
postsInThread.rootId = raw.root_id;
|
||||
postsInThread.earliest = raw.earliest;
|
||||
postsInThread.latest = raw.latest!;
|
||||
};
|
||||
@@ -193,7 +194,8 @@ export const transformPostsInChannelRecord = ({action, database, value}: Transfo
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
const fieldsMapper = (postsInChannel: PostsInChannelModel) => {
|
||||
postsInChannel._raw.id = isCreateAction ? (raw.channel_id || postsInChannel.id) : record.id;
|
||||
postsInChannel._raw.id = isCreateAction ? (raw.id || postsInChannel.id) : record.id;
|
||||
postsInChannel.channelId = raw.channel_id;
|
||||
postsInChannel.earliest = raw.earliest;
|
||||
postsInChannel.latest = raw.latest;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user