Forums: Various fixes 4 (#2254)
This commit is contained in:
parent
b4f283d207
commit
941d5c8919
@ -1359,6 +1359,8 @@ export function buildLocalForwardedMessage({
|
|||||||
isInAlbum,
|
isInAlbum,
|
||||||
isForwardingAllowed: true,
|
isForwardingAllowed: true,
|
||||||
replyToTopMessageId: toThreadId,
|
replyToTopMessageId: toThreadId,
|
||||||
|
...(toThreadId && toChat?.isForum && { isTopicReply: true }),
|
||||||
|
|
||||||
...(emojiOnlyCount && { emojiOnlyCount }),
|
...(emojiOnlyCount && { emojiOnlyCount }),
|
||||||
// Forward info doesn't get added when users forwards his own messages, also when forwarding audio
|
// Forward info doesn't get added when users forwards his own messages, also when forwarding audio
|
||||||
...(message.chatId !== currentUserId && !isAudio && !noAuthors && {
|
...(message.chatId !== currentUserId && !isAudio && !noAuthors && {
|
||||||
|
|||||||
@ -41,6 +41,7 @@ export interface ApiChat {
|
|||||||
fakeType?: ApiFakeType;
|
fakeType?: ApiFakeType;
|
||||||
isForum?: boolean;
|
isForum?: boolean;
|
||||||
topics?: Record<number, ApiTopic>;
|
topics?: Record<number, ApiTopic>;
|
||||||
|
listedTopicIds?: number[];
|
||||||
topicsCount?: number;
|
topicsCount?: number;
|
||||||
orderedPinnedTopicIds?: number[];
|
orderedPinnedTopicIds?: number[];
|
||||||
|
|
||||||
|
|||||||
@ -198,7 +198,7 @@ const Chat: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
// Load the forum topics to display unread count badge
|
// Load the forum topics to display unread count badge
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isIntersecting && lastSyncTime && isForum && chat && chat.topics === undefined) {
|
if (isIntersecting && lastSyncTime && isForum && chat && chat.listedTopicIds === undefined) {
|
||||||
loadTopics({ chatId });
|
loadTopics({ chatId });
|
||||||
}
|
}
|
||||||
}, [chat, chatId, isForum, isIntersecting, lastSyncTime, loadTopics]);
|
}, [chat, chatId, isForum, isIntersecting, lastSyncTime, loadTopics]);
|
||||||
|
|||||||
@ -41,7 +41,7 @@ import {
|
|||||||
updateTopics,
|
updateTopics,
|
||||||
deleteTopic,
|
deleteTopic,
|
||||||
updateTopic,
|
updateTopic,
|
||||||
updateThreadInfo,
|
updateThreadInfo, updateListedTopicIds,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectChat, selectUser, selectChatListType, selectIsChatPinned,
|
selectChat, selectUser, selectChatListType, selectIsChatPinned,
|
||||||
@ -1338,18 +1338,22 @@ addActionHandler('loadTopics', async (global, actions, payload) => {
|
|||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
if (!chat) return;
|
if (!chat) return;
|
||||||
|
|
||||||
if (!force && chat.topics && Object.values(chat.topics).length === chat.topicsCount) {
|
if (!force && chat.listedTopicIds && chat.listedTopicIds.length === chat.topicsCount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const offsetTopic = !force && chat.topics ? Object.values(chat.topics).reduce((acc, el) => {
|
const offsetTopic = !force && chat.listedTopicIds ? chat.listedTopicIds.reduce((acc, el) => {
|
||||||
if (!acc || el.lastMessageId < acc.lastMessageId) {
|
const topic = chat.topics?.[el];
|
||||||
|
const accTopic = chat.topics?.[acc];
|
||||||
|
if (!topic) return acc;
|
||||||
|
if (!accTopic || topic.lastMessageId < accTopic.lastMessageId) {
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}) : undefined;
|
}) : undefined;
|
||||||
|
|
||||||
const { id: offsetTopicId, date: offsetDate, lastMessageId: offsetId } = offsetTopic || {};
|
const { id: offsetTopicId, date: offsetDate, lastMessageId: offsetId } = (offsetTopic
|
||||||
|
&& chat.topics?.[offsetTopic]) || {};
|
||||||
const result = await callApi('fetchTopics', {
|
const result = await callApi('fetchTopics', {
|
||||||
chat, offsetTopicId, offsetId, offsetDate, limit: offsetTopicId ? TOPICS_SLICE : TOPICS_SLICE_SECOND_LOAD,
|
chat, offsetTopicId, offsetId, offsetDate, limit: offsetTopicId ? TOPICS_SLICE : TOPICS_SLICE_SECOND_LOAD,
|
||||||
});
|
});
|
||||||
@ -1361,6 +1365,7 @@ addActionHandler('loadTopics', async (global, actions, payload) => {
|
|||||||
global = addChats(global, buildCollectionByKey(result.chats, 'id'));
|
global = addChats(global, buildCollectionByKey(result.chats, 'id'));
|
||||||
global = addMessages(global, result.messages);
|
global = addMessages(global, result.messages);
|
||||||
global = updateTopics(global, chatId, result.count, result.topics);
|
global = updateTopics(global, chatId, result.count, result.topics);
|
||||||
|
global = updateListedTopicIds(global, chatId, result.topics.map((topic) => topic.id));
|
||||||
Object.entries(result.draftsById || {}).forEach(([threadId, draft]) => {
|
Object.entries(result.draftsById || {}).forEach(([threadId, draft]) => {
|
||||||
global = replaceThreadParam(global, chatId, Number(threadId), 'draft', draft?.formattedText);
|
global = replaceThreadParam(global, chatId, Number(threadId), 'draft', draft?.formattedText);
|
||||||
global = replaceThreadParam(global, chatId, Number(threadId), 'replyingToId', draft?.replyingToId);
|
global = replaceThreadParam(global, chatId, Number(threadId), 'replyingToId', draft?.replyingToId);
|
||||||
|
|||||||
@ -769,6 +769,13 @@ function updateChatLastMessage(
|
|||||||
const chat = chats.byId[chatId];
|
const chat = chats.byId[chatId];
|
||||||
const currentLastMessage = chat?.lastMessage;
|
const currentLastMessage = chat?.lastMessage;
|
||||||
|
|
||||||
|
const topic = chat?.isForum ? selectTopicFromMessage(global, message) : undefined;
|
||||||
|
if (topic) {
|
||||||
|
global = updateTopic(global, chatId, topic.id, {
|
||||||
|
lastMessageId: message.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (currentLastMessage && !force) {
|
if (currentLastMessage && !force) {
|
||||||
const isSameOrNewer = (
|
const isSameOrNewer = (
|
||||||
currentLastMessage.id === message.id || currentLastMessage.id === message.previousLocalId
|
currentLastMessage.id === message.id || currentLastMessage.id === message.previousLocalId
|
||||||
@ -780,12 +787,6 @@ function updateChatLastMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
global = updateChat(global, chatId, { lastMessage: message });
|
global = updateChat(global, chatId, { lastMessage: message });
|
||||||
const topic = chat?.isForum ? selectTopicFromMessage(global, message) : undefined;
|
|
||||||
if (topic) {
|
|
||||||
global = updateTopic(global, chatId, topic.id, {
|
|
||||||
lastMessageId: message.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return global;
|
return global;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import type {
|
|||||||
|
|
||||||
import { ARCHIVED_FOLDER_ID } from '../../config';
|
import { ARCHIVED_FOLDER_ID } from '../../config';
|
||||||
import {
|
import {
|
||||||
areSortedArraysEqual, buildCollectionByKey, omit,
|
areSortedArraysEqual, buildCollectionByKey, omit, unique,
|
||||||
} from '../../util/iteratees';
|
} from '../../util/iteratees';
|
||||||
import { selectChat, selectChatListType } from '../selectors';
|
import { selectChat, selectChatListType } from '../selectors';
|
||||||
import { updateThread, updateThreadInfo } from './messages';
|
import { updateThread, updateThreadInfo } from './messages';
|
||||||
@ -252,6 +252,17 @@ export function addChatMembers(global: GlobalState, chat: ApiChat, membersToAdd:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateListedTopicIds(
|
||||||
|
global: GlobalState, chatId: string, topicIds: number[],
|
||||||
|
): GlobalState {
|
||||||
|
return updateChat(global, chatId, {
|
||||||
|
listedTopicIds: unique([
|
||||||
|
...(global.chats.byId[chatId]?.listedTopicIds || []),
|
||||||
|
...topicIds,
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function updateTopics(
|
export function updateTopics(
|
||||||
global: GlobalState, chatId: string, topicsCount: number, topics: ApiTopic[],
|
global: GlobalState, chatId: string, topicsCount: number, topics: ApiTopic[],
|
||||||
): GlobalState {
|
): GlobalState {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user