pull/1387/head
Audric Ackermann 4 years ago
parent 5617d9e7aa
commit 96263b4d25
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -365,6 +365,7 @@ export class SessionConversation extends React.Component<Props, State> {
// Set first member of series here.
const messageModels = messageSet.models;
console.warn('messageSet', messageSet);
const messages = [];
let previousSender;

@ -1,84 +1,3 @@
import { Constants } from '../../../session';
export interface MessageFetchType {
messages: Array<any>;
messageFetchTimestamp: number;
newTopMessage: any;
previousTopMessage: any;
}
export async function getMessages(
conversationKey: string,
currentMessages: Array<any>,
messageFetchTimestamp: number,
unreadCount: number,
onGotMessages?: any,
numMessages?: number,
fetchInterval = Constants.CONVERSATION.MESSAGE_FETCH_INTERVAL
) {
const timestamp = getTimestamp();
// If we have pulled messages in the last interval, don't bother rescanning
// This avoids getting messages on every re-render.
const timeBuffer = timestamp - messageFetchTimestamp;
if (timeBuffer < fetchInterval) {
// Loopback gets messages after time has elapsed,
// rather than completely cancelling the fetch.
// if (loopback) {
// setTimeout(() => {
// this.getMessages(numMessages, fetchInterval, false);
// }, timeBuffer * 1000);
// }
return { newTopMessage: undefined, previousTopMessage: undefined };
}
let msgCount =
numMessages ||
Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT + unreadCount;
msgCount =
msgCount > Constants.CONVERSATION.MAX_MESSAGE_FETCH_COUNT
? Constants.CONVERSATION.MAX_MESSAGE_FETCH_COUNT
: msgCount;
const messageSet = await window.Signal.Data.getMessagesByConversation(
conversationKey,
{ limit: msgCount, MessageCollection: window.Whisper.MessageCollection }
);
// Set first member of series here.
const messageModels = messageSet.models;
const messages = [];
let previousSender;
for (let i = 0; i < messageModels.length; i++) {
// Handle firstMessageOfSeries for conditional avatar rendering
let firstMessageOfSeries = true;
if (i > 0 && previousSender === messageModels[i].authorPhoneNumber) {
firstMessageOfSeries = false;
}
messages.push({ ...messageModels[i], firstMessageOfSeries });
previousSender = messageModels[i].authorPhoneNumber;
}
const previousTopMessage = currentMessages[0]?.id;
const newTopMessage = messages[0]?.id;
const newMessageFetchTimestamp = getTimestamp();
// Callback to onGotMessages
if (onGotMessages) {
onGotMessages(
messages,
newMessageFetchTimestamp,
previousTopMessage,
newTopMessage
);
}
return { newTopMessage, previousTopMessage };
}
export function getTimestamp(asInt = false) {
const timestamp = Date.now() / 1000;
return asInt ? Math.floor(timestamp) : timestamp;

@ -106,6 +106,13 @@ export type SelectedConversationChangedActionType = {
messageId?: string;
};
};
export type LoadMoreMessagesActionType = {
type: 'LOAD_MORE_MESSAGES_ACTION_TYPE';
payload: {
id: string;
currentMessageCount: number;
};
};
export type ConversationActionType =
| ConversationAddedActionType
@ -115,7 +122,8 @@ export type ConversationActionType =
| MessageExpiredActionType
| SelectedConversationChangedActionType
| MessageExpiredActionType
| SelectedConversationChangedActionType;
| SelectedConversationChangedActionType
| LoadMoreMessagesActionType;
// Action Creators
@ -127,6 +135,7 @@ export const actions = {
messageExpired,
openConversationInternal,
openConversationExternal,
loadMoreMessages,
};
function conversationAdded(
@ -168,6 +177,16 @@ function removeAllConversations(): RemoveAllConversationsActionType {
};
}
function loadMoreMessages(id: string, currentMessageCount: number): LoadMoreMessagesActionType {
return {
type: 'LOAD_MORE_MESSAGES_ACTION_TYPE',
payload: {
id,
currentMessageCount,
},
};
}
function messageExpired(
id: string,
conversationId: string

@ -16,7 +16,6 @@ import {
SelectedConversationChangedActionType,
} from './conversations';
import { MultiDeviceProtocol } from '../../session/protocols';
import { PubKey } from '../../session/types';
// State

@ -8,11 +8,10 @@ import {
import { reducer as user, UserStateType } from './ducks/user';
import { reducer as theme, ThemeStateType } from './ducks/theme';
import { reducer as section, SectionStateType } from './ducks/section';
// import { reducer as messages } from './ducks/messages';
export type StateType = {
search: SearchStateType;
messages: any;
// messages: any;
user: UserStateType;
conversations: ConversationsStateType;
theme: ThemeStateType;

Loading…
Cancel
Save