Fix Posts query while populating top DMs, add OutgoingMessageCount check to tests
Этот коммит содержится в:
@@ -3003,14 +3003,14 @@ func (s *SqlPostStore) GetTopDMsForUserSince(userID string, since int64, offset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fill SecondParticipant column
|
// fill SecondParticipant column
|
||||||
topDMs, err = postProcessTopDMs(s, userID, topDMs)
|
topDMs, err = postProcessTopDMs(s, userID, topDMs, since)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return model.GetTopDMListWithPagination(topDMs, limit), nil
|
return model.GetTopDMListWithPagination(topDMs, limit), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM) ([]*model.TopDM, error) {
|
func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM, since int64) ([]*model.TopDM, error) {
|
||||||
var topDMsFiltered = []*model.TopDM{}
|
var topDMsFiltered = []*model.TopDM{}
|
||||||
var secondParticipantIds []string
|
var secondParticipantIds []string
|
||||||
var channelIds []string
|
var channelIds []string
|
||||||
@@ -3041,10 +3041,21 @@ func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM) ([
|
|||||||
|
|
||||||
// get outgoing message count for userId
|
// get outgoing message count for userId
|
||||||
outgoingMessagesQuery := s.getQueryBuilder().Select("ch.Id as ChannelId, count(p.Id) as MessageCount").From("Channels as ch").
|
outgoingMessagesQuery := s.getQueryBuilder().Select("ch.Id as ChannelId, count(p.Id) as MessageCount").From("Channels as ch").
|
||||||
Join("Posts as p on p.ChannelId=ch.Id").Where(sq.Eq{
|
Join("Posts as p on p.ChannelId=ch.Id").Where(
|
||||||
"ch.Id": channelIds,
|
sq.And{
|
||||||
"p.UserId": userID,
|
sq.Gt{
|
||||||
}).GroupBy("ch.Id")
|
"p.UpdateAt": since,
|
||||||
|
},
|
||||||
|
sq.Eq{
|
||||||
|
"p.DeleteAt": 0,
|
||||||
|
},
|
||||||
|
sq.Eq{
|
||||||
|
"ch.Id": channelIds,
|
||||||
|
},
|
||||||
|
sq.Eq{
|
||||||
|
"p.UserId": userID,
|
||||||
|
},
|
||||||
|
}).GroupBy("ch.Id")
|
||||||
|
|
||||||
outgoingMessages := make([]*model.OutgoingMessageQueryResult, 0)
|
outgoingMessages := make([]*model.OutgoingMessageQueryResult, 0)
|
||||||
sql, args, err := outgoingMessagesQuery.ToSql()
|
sql, args, err := outgoingMessagesQuery.ToSql()
|
||||||
|
|||||||
@@ -4075,10 +4075,13 @@ func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
|
|||||||
// check order, magnitude of items
|
// check order, magnitude of items
|
||||||
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
|
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
|
||||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
||||||
|
require.Equal(t, topDMs.Items[0].OutgoingMessageCount, int64(3))
|
||||||
require.Equal(t, topDMs.Items[1].SecondParticipant.Id, u1.Id)
|
require.Equal(t, topDMs.Items[1].SecondParticipant.Id, u1.Id)
|
||||||
require.Equal(t, topDMs.Items[1].MessageCount, int64(2))
|
require.Equal(t, topDMs.Items[1].MessageCount, int64(2))
|
||||||
|
require.Equal(t, topDMs.Items[1].OutgoingMessageCount, int64(1))
|
||||||
require.Equal(t, topDMs.Items[2].SecondParticipant.Id, u2.Id)
|
require.Equal(t, topDMs.Items[2].SecondParticipant.Id, u2.Id)
|
||||||
require.Equal(t, topDMs.Items[2].MessageCount, int64(1))
|
require.Equal(t, topDMs.Items[2].MessageCount, int64(1))
|
||||||
|
require.Equal(t, topDMs.Items[2].OutgoingMessageCount, int64(0))
|
||||||
// this also ensures that u3-u4 conversation doesn't show up in others' top DMs.
|
// this also ensures that u3-u4 conversation doesn't show up in others' top DMs.
|
||||||
})
|
})
|
||||||
t.Run("topDMs should only consider user's DM channels ", func(t *testing.T) {
|
t.Run("topDMs should only consider user's DM channels ", func(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user