mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 04:59:16 +00:00
sorting conversations by latest
This commit is contained in:
parent
8e14f51d58
commit
39372d8e0a
@ -67,7 +67,7 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
|
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
|
||||||
return store.DB.Order("topics.id DESC").Limit(1)
|
return store.DB.Order("topics.id DESC")
|
||||||
}).Preload("Channel.Cards.CardSlot").Preload("Channel.Groups.GroupSlot").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
|
}).Preload("Channel.Cards.CardSlot").Preload("Channel.Groups.GroupSlot").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
|
||||||
ErrResponse(w, http.StatusInternalServerError, err)
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
@ -110,7 +110,7 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
|
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
|
||||||
return store.DB.Order("topics.id DESC").Limit(1)
|
return store.DB.Order("topics.id DESC")
|
||||||
}).Preload("Channel.Cards").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
|
}).Preload("Channel.Cards").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
|
||||||
ErrResponse(w, http.StatusInternalServerError, err)
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
@ -58,12 +58,30 @@ export function useChannels() {
|
|||||||
card.state.cards.forEach((value, key, map) => {
|
card.state.cards.forEach((value, key, map) => {
|
||||||
cardChannels.current.push(...Array.from(value.channels.values()));
|
cardChannels.current.push(...Array.from(value.channels.values()));
|
||||||
});
|
});
|
||||||
updateState({ channels: [ ...channels.current, ...cardChannels.current ]});
|
let merged = [ ...channels.current, ...cardChannels.current ];
|
||||||
|
merged.sort((a, b) => {
|
||||||
|
if (a?.data?.channelSummary?.lastTopic?.created > b?.data?.channelSummary?.lastTopic?.created) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
updateState({ channels: merged });
|
||||||
}, [card])
|
}, [card])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
channels.current = Array.from(channel.state.channels.values());
|
channels.current = Array.from(channel.state.channels.values());
|
||||||
updateState({ channels: [ ...channels.current, ...cardChannels.current ]});
|
let merged = [ ...channels.current, ...cardChannels.current ];
|
||||||
|
merged.sort((a, b) => {
|
||||||
|
if (a?.data?.channelSummary?.lastTopic?.created > b?.data?.channelSummary?.lastTopic?.created) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
for (let i = 0; i < merged.length; i++) {
|
||||||
|
console.log(merged[i]);
|
||||||
|
console.log(merged[i]?.data?.channelSummary?.lastTopic?.created);
|
||||||
|
}
|
||||||
|
updateState({ channels: merged });
|
||||||
}, [channel])
|
}, [channel])
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
@ -124,7 +124,7 @@ export function useCardContext() {
|
|||||||
}
|
}
|
||||||
cur.data.detailRevision = channel.data.detailRevision;
|
cur.data.detailRevision = channel.data.detailRevision;
|
||||||
}
|
}
|
||||||
if (cur.data.detailRevision != channel.data.detailRevision) {
|
if (cur.data.topicRevision != channel.data.topicRevision) {
|
||||||
if (channel.data.channelSummary != null) {
|
if (channel.data.channelSummary != null) {
|
||||||
cur.data.channelSummary = channel.data.channelSummary;
|
cur.data.channelSummary = channel.data.channelSummary;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ export function useChannelContext() {
|
|||||||
cur.data.detailRevision = channel.data.detailRevision;
|
cur.data.detailRevision = channel.data.detailRevision;
|
||||||
}
|
}
|
||||||
if (cur.data.topicRevision != channel.data.topicRevision) {
|
if (cur.data.topicRevision != channel.data.topicRevision) {
|
||||||
if (channel.data.channelDetail != null) {
|
if (channel.data.channelSummary != null) {
|
||||||
cur.data.channelDetail = channel.data.channelDetail;
|
cur.data.channelSummary = channel.data.channelSummary;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let summary = await getChannelSummary(access.current, channel.id);
|
let summary = await getChannelSummary(access.current, channel.id);
|
||||||
|
Loading…
Reference in New Issue
Block a user