forked from Ivasoft/mattermost-mobile
[Gekidou CRT] thread mention counts (#6126)
* Sets values on my_channel according to CRT * Team counts with regard to CRT * Fixes myChannel.is_unread with regard to CRT * Include DM/GMs for thread counts on demand * Incorporate thread mention counts in server/channel * Channel updates in regard to CRT
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
transformMyChannelSettingsRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/channel';
|
||||
import {getUniqueRawsBy} from '@database/operator/utils/general';
|
||||
import {getIsCRTEnabled} from '@queries/servers/thread';
|
||||
|
||||
import type {HandleChannelArgs, HandleChannelInfoArgs, HandleChannelMembershipArgs, HandleMyChannelArgs, HandleMyChannelSettingsArgs} from '@typings/database/database';
|
||||
import type ChannelModel from '@typings/database/models/servers/channel';
|
||||
@@ -156,14 +157,19 @@ const ChannelHandler = (superclass: any) => class extends superclass {
|
||||
return [];
|
||||
}
|
||||
|
||||
const isCRTEnabled = await getIsCRTEnabled(this.database);
|
||||
|
||||
const channelMap = channels.reduce((result: Record<string, Channel>, channel) => {
|
||||
result[channel.id] = channel;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
for (const my of myChannels) {
|
||||
const channel = channelMap[my.channel_id];
|
||||
if (channel) {
|
||||
const msgCount = Math.max(0, channel.total_msg_count - my.msg_count);
|
||||
const total = isCRTEnabled ? channel.total_msg_count_root! : channel.total_msg_count;
|
||||
const myMsgCount = isCRTEnabled ? my.msg_count_root! : my.msg_count;
|
||||
const msgCount = Math.max(0, total - myMsgCount);
|
||||
my.msg_count = msgCount;
|
||||
my.is_unread = msgCount > 0;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import {prepareBaseRecord} from '@database/operator/server_data_operator/transformers/index';
|
||||
import {extractChannelDisplayName} from '@helpers/database';
|
||||
import {getIsCRTEnabled} from '@queries/servers/thread';
|
||||
import {OperationType} from '@typings/database/enums';
|
||||
|
||||
import type {TransformerArgs} from '@typings/database/database';
|
||||
@@ -120,18 +121,20 @@ export const transformChannelInfoRecord = ({action, database, value}: Transforme
|
||||
* @param {RecordPair} operator.value
|
||||
* @returns {Promise<MyChannelModel>}
|
||||
*/
|
||||
export const transformMyChannelRecord = ({action, database, value}: TransformerArgs): Promise<MyChannelModel> => {
|
||||
export const transformMyChannelRecord = async ({action, database, value}: TransformerArgs): Promise<MyChannelModel> => {
|
||||
const raw = value.raw as ChannelMembership;
|
||||
const record = value.record as MyChannelModel;
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
const isCRTEnabled = await getIsCRTEnabled(database);
|
||||
|
||||
const fieldsMapper = (myChannel: MyChannelModel) => {
|
||||
myChannel._raw.id = isCreateAction ? (raw.channel_id || myChannel.id) : record.id;
|
||||
myChannel.roles = raw.roles;
|
||||
myChannel.messageCount = raw.msg_count;
|
||||
myChannel.messageCount = isCRTEnabled ? raw.msg_count_root! : raw.msg_count;
|
||||
myChannel.isUnread = Boolean(raw.is_unread);
|
||||
myChannel.mentionsCount = raw.mention_count;
|
||||
myChannel.lastPostAt = raw.last_post_at || 0;
|
||||
myChannel.mentionsCount = isCRTEnabled ? raw.mention_count_root! : raw.mention_count;
|
||||
myChannel.lastPostAt = (isCRTEnabled ? (raw.last_root_post_at || raw.last_post_at) : raw.last_post_at) || 0;
|
||||
myChannel.lastViewedAt = raw.last_viewed_at;
|
||||
myChannel.viewedAt = record?.viewedAt || 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user