Skip to content

Commit

Permalink
fix: store message_text_updated_at field in the offline DB (#2548)
Browse files Browse the repository at this point in the history
* feat: store message_text_updates_at field in the offline DB

* fix: update tests
  • Loading branch information
khushal87 authored Jun 14, 2024
1 parent 95abb46 commit ff86bca
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ exports[`Thread should match thread snapshot 1`] = `
],
"html": "<p>regular</p>",
"id": "38ef6f7c-3090-5759-a37f-ab0053aadb96",
"message_text_updated_at": "2020-05-05T14:50:00.000Z",
"parent_id": "b4612a73-fa2b-5787-bf71-1adc8f291a04",
"pinned_at": null,
"readBy": false,
Expand Down Expand Up @@ -86,6 +87,7 @@ exports[`Thread should match thread snapshot 1`] = `
],
"html": "<p>regular</p>",
"id": "516efa25-5d29-5c9a-ad2d-4cc183e785bd",
"message_text_updated_at": "2020-05-05T14:50:00.000Z",
"parent_id": "b4612a73-fa2b-5787-bf71-1adc8f291a04",
"pinned_at": null,
"readBy": false,
Expand Down Expand Up @@ -114,6 +116,7 @@ exports[`Thread should match thread snapshot 1`] = `
],
"html": "<p>regular</p>",
"id": "82a83b16-b611-527c-b3ac-765ef6220490",
"message_text_updated_at": "2020-05-05T14:50:00.000Z",
"parent_id": "b4612a73-fa2b-5787-bf71-1adc8f291a04",
"pinned_at": null,
"readBy": false,
Expand Down Expand Up @@ -490,6 +493,40 @@ exports[`Thread should match thread snapshot 1`] = `
>
2:50 PM
</Text>
<Text
style={
[
{
"paddingHorizontal": 4,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{
"fontSize": 12,
},
]
}
>
</Text>
<Text
style={
[
{
"fontSize": 12,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{},
]
}
>
Edited
</Text>
</View>
</View>
</View>
Expand Down Expand Up @@ -770,6 +807,40 @@ exports[`Thread should match thread snapshot 1`] = `
>
2:50 PM
</Text>
<Text
style={
[
{
"paddingHorizontal": 4,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{
"fontSize": 12,
},
]
}
>
</Text>
<Text
style={
[
{
"fontSize": 12,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{},
]
}
>
Edited
</Text>
</View>
</View>
</View>
Expand Down Expand Up @@ -1050,6 +1121,40 @@ exports[`Thread should match thread snapshot 1`] = `
>
2:50 PM
</Text>
<Text
style={
[
{
"paddingHorizontal": 4,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{
"fontSize": 12,
},
]
}
>
</Text>
<Text
style={
[
{
"fontSize": 12,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{},
]
}
>
Edited
</Text>
</View>
</View>
</View>
Expand Down Expand Up @@ -1370,6 +1475,40 @@ exports[`Thread should match thread snapshot 1`] = `
>
2:50 PM
</Text>
<Text
style={
[
{
"paddingHorizontal": 4,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{
"fontSize": 12,
},
]
}
>
</Text>
<Text
style={
[
{
"fontSize": 12,
},
{
"color": "#7A7A7A",
"textAlign": "left",
},
{},
]
}
>
Edited
</Text>
</View>
</View>
</View>
Expand Down
2 changes: 2 additions & 0 deletions package/src/mock-builders/generator/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const generateMessage = (options = {}) => {
created_at: timestamp,
html: '<p>regular</p>',
id: uuidv4(),
message_text_updated_at: timestamp,
text: uuidv4(),
type: 'regular',
updated_at: timestamp.toString(),
Expand All @@ -24,6 +25,7 @@ export const generateStaticMessage = (seed, options, date) =>
generateMessage({
created_at: date || '2020-04-27T13:39:49.331742Z',
id: uuidv5(seed, StreamReactNativeNamespace),
message_text_updated_at: date || '2020-04-27T13:39:49.331742Z',
text: seed,
updated_at: date || '2020-04-27T13:39:49.331742Z',
...options,
Expand Down
2 changes: 1 addition & 1 deletion package/src/store/QuickSqliteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type { PreparedQueries, Table } from './types';
*
*/
export class QuickSqliteClient {
static dbVersion = 4;
static dbVersion = 5;

static dbName = DB_NAME;
static dbLocation = DB_LOCATION;
Expand Down
2 changes: 2 additions & 0 deletions package/src/store/mappers/mapMessageToStorable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const mapMessageToStorable = (
id,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
latest_reactions,
message_text_updated_at,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
own_reactions,
reaction_groups,
Expand All @@ -32,6 +33,7 @@ export const mapMessageToStorable = (
deletedAt: mapDateTimeToStorable(deleted_at),
extraData: JSON.stringify(extraData),
id,
messageTextUpdatedAt: mapDateTimeToStorable(message_text_updated_at),
reactionGroups: JSON.stringify(reaction_groups),
text,
type,
Expand Down
12 changes: 11 additions & 1 deletion package/src/store/mappers/mapStorableToMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ export const mapStorableToMessage = <
messageRow: TableRowJoinedUser<'messages'>;
reactionRows: TableRowJoinedUser<'reactions'>[];
}): MessageResponse<StreamChatGenerics> => {
const { createdAt, deletedAt, extraData, reactionGroups, updatedAt, user, ...rest } = messageRow;
const {
createdAt,
deletedAt,
extraData,
messageTextUpdatedAt,
reactionGroups,
updatedAt,
user,
...rest
} = messageRow;
const latestReactions =
reactionRows?.map((reaction) => mapStorableToReaction<StreamChatGenerics>(reaction)) || [];

Expand All @@ -31,6 +40,7 @@ export const mapStorableToMessage = <
created_at: createdAt,
deleted_at: deletedAt,
latest_reactions: latestReactions,
message_text_updated_at: messageTextUpdatedAt,
own_reactions: ownReactions,
reaction_groups: reactionGroups ? JSON.parse(reactionGroups) : {},
updated_at: updatedAt,
Expand Down
2 changes: 2 additions & 0 deletions package/src/store/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const tables: Tables = {
deletedAt: 'TEXT',
extraData: 'TEXT',
id: 'TEXT',
messageTextUpdatedAt: 'TEXT',
reactionGroups: 'TEXT',
text: "TEXT DEFAULT ''",
type: 'TEXT',
Expand Down Expand Up @@ -262,6 +263,7 @@ export type Schema = {
deletedAt: string;
extraData: string;
id: string;
messageTextUpdatedAt: string;
reactionGroups: string;
type: MessageLabel;
updatedAt: string;
Expand Down
1 change: 1 addition & 0 deletions package/src/utils/removeReservedFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const removeReservedFields = <
'reaction_groups',
'last_message_at',
'member_count',
'message_text_updated_at',
'type',
'updated_at',
'reply_count',
Expand Down

0 comments on commit ff86bca

Please sign in to comment.