Skip to content

Commit

Permalink
fix: Latest message timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 12, 2020
1 parent dcf46d6 commit 048974b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class Message extends BaseEntity {
@Column()
type: string

@Column()
raw: string
@Column({ nullable: true })
raw?: string

@Column('simple-json', { nullable: true })
data?: any
Expand Down
23 changes: 19 additions & 4 deletions packages/daf-data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,25 @@ export class DataStore {
}

async latestMessageTimestamps() {
let query = `SELECT * FROM ( SELECT m."timestamp", m.receiver AS did, md. "type" , md.id FROM messages AS m
LEFT JOIN messages_meta_data AS md ON m.id = md.message_id order by m.timestamp desc) GROUP BY did, "type", id`

return [] //FIXME
const innerQb = await Message.createQueryBuilder('message')
.leftJoinAndSelect('message.metaData', 'meta')
.orderBy('message.createdAt', 'DESC')

const res = await Message.createQueryBuilder()
.select('message_toDid as did, meta_type as type, meta_value as value, message_createdAt as createdAt')
.from('(' + innerQb.getQuery() + ')', 'inner')
.setParameters(innerQb.getParameters())
.groupBy('message_toDid')
.addGroupBy('meta_type')
.addGroupBy('meta_value')
.getRawMany()

return res.map(item => ({
did: item.did,
type: item.type,
id: item.value,
timestamp: Math.round(new Date(item.createdAt).getTime() / 1000),
}))
}

async shortId(did: string) {
Expand Down

0 comments on commit 048974b

Please sign in to comment.