|
|
|
@ -27,11 +27,15 @@ export class MessageHistoryComponent implements OnInit { |
|
|
|
messages: MessageDTO[] = [] |
|
|
|
offset = 0; |
|
|
|
limit = 10; |
|
|
|
lastMsgTs = 0; |
|
|
|
|
|
|
|
knownNodes:KeyValueMap<NodeDTO> = {} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.getMessages(); |
|
|
|
setInterval(() => { |
|
|
|
//this.newMessagePooler()
|
|
|
|
}, 1000) |
|
|
|
} |
|
|
|
|
|
|
|
tryKnownNodes(nums: number[]) { |
|
|
|
@ -49,13 +53,19 @@ export class MessageHistoryComponent implements OnInit { |
|
|
|
|
|
|
|
getMessages() { |
|
|
|
this.loading = true; |
|
|
|
this.http.get(`api/messages?offset=${this.offset}&limit=${this.limit}`) |
|
|
|
this.http.get(`api/messages?offset=${this.offset}&limit=${this.limit}&after=${this.lastMsgTs}`) |
|
|
|
.subscribe((res) => { |
|
|
|
let new_msgs = res as MessageDTO[] |
|
|
|
this.tryKnownNodes(new_msgs.map(msg => msg.from)).add( |
|
|
|
() => { |
|
|
|
this.messages = this.messages.concat(new_msgs) |
|
|
|
.sort((m1, m2) => m1.ts - m2.ts); |
|
|
|
|
|
|
|
if (this.messages.length>0) { |
|
|
|
if (this.messages[this.messages.length-1].ts > this.lastMsgTs) |
|
|
|
this.lastMsgTs = this.messages[this.messages.length-1].ts; |
|
|
|
} |
|
|
|
|
|
|
|
let msgSizes = (res as MessageDTO[]).length |
|
|
|
if (msgSizes == 0) this.canLoadMoreMessage = false; |
|
|
|
this.offset += msgSizes; |
|
|
|
@ -64,4 +74,22 @@ export class MessageHistoryComponent implements OnInit { |
|
|
|
this.loading = false; |
|
|
|
}, (err) => {this.loading = false;}) |
|
|
|
} |
|
|
|
|
|
|
|
//ЭХ ВОТ БЫ ВЕБСОКЕТ НО МНЕ ЛЕНЬ
|
|
|
|
newMessagePooler() { |
|
|
|
this.http.get(`api/messages?offset=0&limit=10&after=${this.lastMsgTs}`) |
|
|
|
.subscribe((res) => { |
|
|
|
let new_msgs = res as MessageDTO[] |
|
|
|
this.tryKnownNodes(new_msgs.map(msg => msg.from)).add( |
|
|
|
() => { |
|
|
|
this.messages.push(...new_msgs) |
|
|
|
|
|
|
|
if (this.messages.length>0) { |
|
|
|
if (this.messages[this.messages.length-1].ts > this.lastMsgTs) |
|
|
|
this.lastMsgTs = this.messages[this.messages.length-1].ts; |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|