Handle message and channel deleting in frontend when syncing
This commit is contained in:
@@ -18,4 +18,3 @@ export const PORT = parseInt(process.env["PORT"]!) || 3000;
|
|||||||
export const USE_SSL = process.env["USE_SSL"] === "1" ? true : false;
|
export const USE_SSL = process.env["USE_SSL"] === "1" ? true : false;
|
||||||
export const SSL_KEY = process.env["SSL_KEY"] || "";
|
export const SSL_KEY = process.env["SSL_KEY"] || "";
|
||||||
export const SSL_CERT = process.env["SSL_CERT"] || "";
|
export const SSL_CERT = process.env["SSL_CERT"] || "";
|
||||||
console.log(process.env);
|
|
@@ -138,6 +138,11 @@ export class MainView extends View {
|
|||||||
|
|
||||||
private async syncChannels() {
|
private async syncChannels() {
|
||||||
const channels = await API.getChannels();
|
const channels = await API.getChannels();
|
||||||
|
state.channelList.channels.forEach((chan) => {
|
||||||
|
if (!channels.find((c) => c.id === chan.id)) {
|
||||||
|
state.removeChannel(chan);
|
||||||
|
}
|
||||||
|
});
|
||||||
channels.forEach((chan) => state.addChannel(new Channel(chan)));
|
channels.forEach((chan) => state.addChannel(new Channel(chan)));
|
||||||
this.updateChannelList();
|
this.updateChannelList();
|
||||||
if (!state.currentChannel) {
|
if (!state.currentChannel) {
|
||||||
@@ -180,8 +185,21 @@ export class MainView extends View {
|
|||||||
const channelId = state.currentChannel.id;
|
const channelId = state.currentChannel.id;
|
||||||
if (channelId) {
|
if (channelId) {
|
||||||
const messages = await API.getMessages(channelId.toString());
|
const messages = await API.getMessages(channelId.toString());
|
||||||
// only render new list items, or list items that have changed.
|
// first, delete all local messages that are no longer on the remote using the chunk processor
|
||||||
const proc = new ChunkProcessor<IMessage>(100);
|
const proc = new ChunkProcessor<IMessage>(100);
|
||||||
|
proc.processArray(state.currentChannel.messages, (chunk: IMessage[]) => {
|
||||||
|
chunk.forEach((message: IMessage) => {
|
||||||
|
if (!messages.find((m) => m.id === message.id)) {
|
||||||
|
state.currentChannel!.removeMessage(message.id);
|
||||||
|
const elem = this.messageElementMap.get(message.id);
|
||||||
|
if (elem) {
|
||||||
|
this.messageList.remove(elem);
|
||||||
|
this.messageElementMap.delete(message.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// only render new list items, or list items that have changed.
|
||||||
proc.processArray(messages, (chunk: IMessage[]) => {
|
proc.processArray(messages, (chunk: IMessage[]) => {
|
||||||
chunk.forEach((message: IMessage) => {
|
chunk.forEach((message: IMessage) => {
|
||||||
// TODO: this could do with a lot of perf improvements. I'll get to it once this is an issue.
|
// TODO: this could do with a lot of perf improvements. I'll get to it once this is an issue.
|
||||||
|
Reference in New Issue
Block a user