use created_at for public group to order messages

pull/1321/head
Audric Ackermann 5 years ago
parent e9f1183178
commit 76664d9a11
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -810,6 +810,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion5, updateToLokiSchemaVersion5,
updateToLokiSchemaVersion6, updateToLokiSchemaVersion6,
updateToLokiSchemaVersion7, updateToLokiSchemaVersion7,
updateToLokiSchemaVersion8,
]; ];
async function updateToLokiSchemaVersion1(currentVersion, instance) { async function updateToLokiSchemaVersion1(currentVersion, instance) {
@ -823,7 +824,6 @@ async function updateToLokiSchemaVersion1(currentVersion, instance) {
`ALTER TABLE messages `ALTER TABLE messages
ADD COLUMN serverId INTEGER;` ADD COLUMN serverId INTEGER;`
); );
await instance.run( await instance.run(
`CREATE TABLE servers( `CREATE TABLE servers(
serverUrl STRING PRIMARY KEY ASC, serverUrl STRING PRIMARY KEY ASC,
@ -1051,6 +1051,29 @@ async function updateToLokiSchemaVersion7(currentVersion, instance) {
console.log('updateToLokiSchemaVersion7: success!'); console.log('updateToLokiSchemaVersion7: success!');
} }
async function updateToLokiSchemaVersion8(currentVersion, instance) {
if (currentVersion >= 8) {
return;
}
console.log('updateToLokiSchemaVersion8: starting...');
await instance.run('BEGIN TRANSACTION;');
await instance.run(
`ALTER TABLE messages
ADD COLUMN serverTimestamp INTEGER;`
);
await instance.run(
`INSERT INTO loki_schema (
version
) values (
8
);`
);
await instance.run('COMMIT TRANSACTION;');
console.log('updateToLokiSchemaVersion8: success!');
}
async function updateLokiSchema(instance) { async function updateLokiSchema(instance) {
const result = await instance.get( const result = await instance.get(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';" "SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';"
@ -2092,6 +2115,7 @@ async function saveMessage(data, { forceSave } = {}) {
hasVisualMediaAttachments, hasVisualMediaAttachments,
id, id,
serverId, serverId,
serverTimestamp,
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
received_at, received_at,
schemaVersion, schemaVersion,
@ -2111,6 +2135,7 @@ async function saveMessage(data, { forceSave } = {}) {
$json: objectToJSON(data), $json: objectToJSON(data),
$serverId: serverId, $serverId: serverId,
$serverTimestamp: serverTimestamp,
$body: body, $body: body,
$conversationId: conversationId, $conversationId: conversationId,
$expirationStartTimestamp: expirationStartTimestamp, $expirationStartTimestamp: expirationStartTimestamp,
@ -2134,6 +2159,7 @@ async function saveMessage(data, { forceSave } = {}) {
`UPDATE messages SET `UPDATE messages SET
json = $json, json = $json,
serverId = $serverId, serverId = $serverId,
serverTimestamp = $serverTimestamp,
body = $body, body = $body,
conversationId = $conversationId, conversationId = $conversationId,
expirationStartTimestamp = $expirationStartTimestamp, expirationStartTimestamp = $expirationStartTimestamp,
@ -2169,6 +2195,7 @@ async function saveMessage(data, { forceSave } = {}) {
json, json,
serverId, serverId,
serverTimestamp,
body, body,
conversationId, conversationId,
expirationStartTimestamp, expirationStartTimestamp,
@ -2190,6 +2217,7 @@ async function saveMessage(data, { forceSave } = {}) {
$json, $json,
$serverId, $serverId,
$serverTimestamp,
$body, $body,
$conversationId, $conversationId,
$expirationStartTimestamp, $expirationStartTimestamp,
@ -2419,7 +2447,7 @@ async function getMessagesByConversation(
conversationId = $conversationId AND conversationId = $conversationId AND
received_at < $received_at AND received_at < $received_at AND
type LIKE $type type LIKE $type
ORDER BY sent_at DESC ORDER BY serverTimestamp DESC, serverId DESC, sent_at DESC
LIMIT $limit; LIMIT $limit;
`, `,
{ {

@ -596,6 +596,7 @@
id: this.id, id: this.id,
direction: this.isIncoming() ? 'incoming' : 'outgoing', direction: this.isIncoming() ? 'incoming' : 'outgoing',
timestamp: this.get('sent_at'), timestamp: this.get('sent_at'),
serverTimestamp: this.get('serverTimestamp'),
status: this.getMessagePropStatus(), status: this.getMessagePropStatus(),
contact: this.getPropsForEmbeddedContact(), contact: this.getPropsForEmbeddedContact(),
authorColor, authorColor,
@ -1669,13 +1670,6 @@
Whisper.MessageCollection = Backbone.Collection.extend({ Whisper.MessageCollection = Backbone.Collection.extend({
model: Whisper.Message, model: Whisper.Message,
comparator(left, right) {
if (left.get('sent_at') === right.get('sent_at')) {
return (left.get('received_at') || 0) - (right.get('received_at') || 0);
}
return (left.get('sent_at') || 0) - (right.get('sent_at') || 0);
},
initialize(models, options) { initialize(models, options) {
if (options) { if (options) {
this.conversation = options.conversation; this.conversation = options.conversation;
@ -1726,7 +1720,7 @@
); );
} }
this.add(models); this.add(models.reverse());
if (unreadCount <= 0) { if (unreadCount <= 0) {
return; return;

@ -324,6 +324,7 @@ export function getMessagesByConversation(
type?: string; type?: string;
} }
): Promise<any>; ): Promise<any>;
export function getSeenMessagesByHashList(hashes: any): Promise<any>; export function getSeenMessagesByHashList(hashes: any): Promise<any>;
export function getLastHashBySnode(convoId: any, snode: any): Promise<any>; export function getLastHashBySnode(convoId: any, snode: any): Promise<any>;

@ -1799,7 +1799,9 @@ class LokiPublicChannelAPI {
} }
return { return {
timestamp: new Date(`${adnMessage.created_at}`).getTime() || timestamp, timestamp,
serverTimestamp:
new Date(`${adnMessage.created_at}`).getTime() || timestamp,
attachments, attachments,
preview, preview,
quote, quote,
@ -1919,6 +1921,7 @@ class LokiPublicChannelAPI {
adnMessage.body = messengerData.text; adnMessage.body = messengerData.text;
const { const {
timestamp, timestamp,
serverTimestamp,
quote, quote,
attachments, attachments,
preview, preview,
@ -1990,9 +1993,9 @@ class LokiPublicChannelAPI {
isSessionRequest: false, isSessionRequest: false,
source: pubKey, source: pubKey,
sourceDevice: 1, sourceDevice: 1,
timestamp, timestamp, // sender timestamp
serverTimestamp: timestamp, serverTimestamp, // server created_at, used to order messages
receivedAt, receivedAt,
isPublic: true, isPublic: true,
message: { message: {
@ -2008,7 +2011,7 @@ class LokiPublicChannelAPI {
profileKey, profileKey,
timestamp, timestamp,
received_at: receivedAt, received_at: receivedAt,
sent_at: timestamp, sent_at: timestamp, // sender timestamp inner
quote, quote,
contact: [], contact: [],
preview, preview,

@ -65,6 +65,7 @@ export interface Props {
collapseMetadata?: boolean; collapseMetadata?: boolean;
direction: 'incoming' | 'outgoing'; direction: 'incoming' | 'outgoing';
timestamp: number; timestamp: number;
serverTimestamp?: number;
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error'; status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
// What if changed this over to a single contact like quote, and put the events on it? // What if changed this over to a single contact like quote, and put the events on it?
contact?: Contact & { contact?: Contact & {
@ -257,6 +258,7 @@ export class Message extends React.PureComponent<Props, State> {
text, text,
textPending, textPending,
timestamp, timestamp,
serverTimestamp,
} = this.props; } = this.props;
if (collapseMetadata) { if (collapseMetadata) {
@ -299,7 +301,7 @@ export class Message extends React.PureComponent<Props, State> {
) : ( ) : (
<Timestamp <Timestamp
i18n={i18n} i18n={i18n}
timestamp={timestamp} timestamp={serverTimestamp || timestamp}
extended={true} extended={true}
direction={direction} direction={direction}
withImageNoCaption={withImageNoCaption} withImageNoCaption={withImageNoCaption}

@ -446,6 +446,7 @@ interface MessageCreationData {
source: boolean; source: boolean;
serverId: string; serverId: string;
message: any; message: any;
serverTimestamp: any;
// Needed for synced outgoing messages // Needed for synced outgoing messages
unidentifiedStatus: any; // ??? unidentifiedStatus: any; // ???
@ -464,6 +465,7 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
source, source,
serverId, serverId,
message, message,
serverTimestamp,
} = data; } = data;
const type = 'incoming'; const type = 'incoming';
@ -476,6 +478,7 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
sourceDevice, sourceDevice,
serverId, // + (not present below in `createSentMessage`) serverId, // + (not present below in `createSentMessage`)
sent_at: timestamp, sent_at: timestamp,
serverTimestamp,
received_at: receivedAt || Date.now(), received_at: receivedAt || Date.now(),
conversationId: groupId ?? source, conversationId: groupId ?? source,
unidentifiedDeliveryReceived, // + unidentifiedDeliveryReceived, // +

Loading…
Cancel
Save