SecondParticipant now has extended user object

Этот коммит содержится в:
Shivashis Padhi
2022-07-27 18:41:18 +05:30
родитель 849aea452c
Коммит e94532c862
6 изменённых файлов: 42 добавлений и 23 удалений

Просмотреть файл

@@ -912,6 +912,7 @@ func TestGetTopDMsForUserSince(t *testing.T) {
require.Len(t, topDMs.Items, 2) require.Len(t, topDMs.Items, 2)
require.Equal(t, topDMs.Items[1].MessageCount, int64(2)) require.Equal(t, topDMs.Items[1].MessageCount, int64(2))
require.Equal(t, topDMs.Items[0].MessageCount, int64(3)) require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, basicUser1.Id)
}) })
// get top dms for bu1 // get top dms for bu1

Просмотреть файл

@@ -3145,11 +3145,11 @@ func TestGetTopDMsForUserSince(t *testing.T) {
require.Len(t, topDMs.Items, 3) require.Len(t, topDMs.Items, 3)
// check order, magnitude of items // check order, magnitude of items
// fmt.Println(topDMs.Items[0].MessageCount, topDMs.Items[1].MessageCount, topDMs.Items[2].MessageCount) // fmt.Println(topDMs.Items[0].MessageCount, topDMs.Items[1].MessageCount, topDMs.Items[2].MessageCount)
require.Equal(t, topDMs.Items[0].SecondParticipant, 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[1].SecondParticipant, 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[2].SecondParticipant, 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))
// 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.
}) })
@@ -3160,7 +3160,7 @@ func TestGetTopDMsForUserSince(t *testing.T) {
// len of topDMs.Items should be 3 // len of topDMs.Items should be 3
require.Len(t, topDMs.Items, 1) require.Len(t, topDMs.Items, 1)
// check order, magnitude of items // check order, magnitude of items
require.Equal(t, topDMs.Items[0].SecondParticipant, u3.Id) require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
require.Equal(t, topDMs.Items[0].MessageCount, int64(4)) require.Equal(t, topDMs.Items[0].MessageCount, int64(4))
}) })
} }

Просмотреть файл

@@ -90,6 +90,11 @@ type InsightUserInformation struct {
Username string `json:"username"` Username string `json:"username"`
} }
type TopDMInsightUserInformation struct {
InsightUserInformation
Position string `json:"position"`
}
type DurationPostCount struct { type DurationPostCount struct {
ChannelID string `db:"channelid"` ChannelID string `db:"channelid"`
// Duration is an ISO8601 date string representing either a day or a day and hour (ex. "2022-05-26" or "2022-05-26T14"). // Duration is an ISO8601 date string representing either a day or a day and hour (ex. "2022-05-26" or "2022-05-26T14").
@@ -99,9 +104,9 @@ type DurationPostCount struct {
// Top DMs // Top DMs
type TopDM struct { type TopDM struct {
MessageCount int64 `json:"post_count"` MessageCount int64 `json:"post_count"`
Participants string `json:"-"` Participants string `json:"-"`
SecondParticipant string `json:"second_participant"` SecondParticipant *TopDMInsightUserInformation `json:"second_participant"`
} }
type TopDMList struct { type TopDMList struct {

Просмотреть файл

@@ -123,13 +123,13 @@ func TestGetTopThreadListWithPagination(t *testing.T) {
func TestGetTopDMsListWithPagination(t *testing.T) { func TestGetTopDMsListWithPagination(t *testing.T) {
dms := []*TopDM{ dms := []*TopDM{
{SecondParticipant: NewId(), MessageCount: 100}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 100},
{SecondParticipant: NewId(), MessageCount: 80}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 80},
{SecondParticipant: NewId(), MessageCount: 90}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 90},
{SecondParticipant: NewId(), MessageCount: 76}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 76},
{SecondParticipant: NewId(), MessageCount: 43}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 43},
{SecondParticipant: NewId(), MessageCount: 2}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 2},
{SecondParticipant: NewId(), MessageCount: 1}, {SecondParticipant: &TopDMInsightUserInformation{InsightUserInformation: InsightUserInformation{Id: NewId()}}, MessageCount: 1},
} }
hasNextTT := []struct { hasNextTT := []struct {
Description string Description string

Просмотреть файл

@@ -3014,27 +3014,40 @@ func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM) ([
var topDMsFiltered = []*model.TopDM{} var topDMsFiltered = []*model.TopDM{}
for _, topDM := range topDMs { for _, topDM := range topDMs {
participants := strings.Split(topDM.Participants, ",") participants := strings.Split(topDM.Participants, ",")
var secondParticipantId string
if len(participants) == 1 { if len(participants) == 1 {
// chatting to self // chatting to self
topDM.SecondParticipant = userID secondParticipantId = userID
} else { } else {
// divide message count by 2, because it's counted twice due to channel memberships being 2 for dms. // divide message count by 2, because it's counted twice due to channel memberships being 2 for dms.
topDM.MessageCount = topDM.MessageCount / 2 topDM.MessageCount = topDM.MessageCount / 2
if participants[0] == userID { if participants[0] == userID {
topDM.SecondParticipant = participants[1] secondParticipantId = participants[1]
} else { } else {
topDM.SecondParticipant = participants[0] secondParticipantId = participants[0]
} }
// filter topDM out if second user is bot // filter topDM out if second user is bot
users, err := s.User().GetProfileByIds(context.Background(), []string{topDM.SecondParticipant}, &store.UserGetByIdsOpts{}, true) users, err := s.User().GetProfileByIds(context.Background(), []string{secondParticipantId}, &store.UserGetByIdsOpts{}, true)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get second participant information for user-id: %s", topDM.SecondParticipant) return nil, errors.Wrapf(err, "failed to get second participant information for user-id: %s", topDM.SecondParticipant)
} }
if users[0].IsBot { if users[0].IsBot {
continue continue
} }
user := users[0]
topDM.SecondParticipant = &model.TopDMInsightUserInformation{
InsightUserInformation: model.InsightUserInformation{
Id: user.Id,
LastPictureUpdate: user.LastPictureUpdate,
FirstName: user.FirstName,
LastName: user.LastName,
Username: user.Username,
NickName: user.Nickname,
},
Position: user.Position,
}
} }
topDMsFiltered = append(topDMsFiltered, topDM) topDMsFiltered = append(topDMsFiltered, topDM)

Просмотреть файл

@@ -4073,11 +4073,11 @@ func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
// len of topDMs.Items should be 3 // len of topDMs.Items should be 3
require.Len(t, topDMs.Items, 3) require.Len(t, topDMs.Items, 3)
// check order, magnitude of items // check order, magnitude of items
require.Equal(t, topDMs.Items[0].SecondParticipant, 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[1].SecondParticipant, 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[2].SecondParticipant, 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))
// 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.
}) })
@@ -4088,7 +4088,7 @@ func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
// len of topDMs.Items should be 3 // len of topDMs.Items should be 3
require.Len(t, topDMs.Items, 1) require.Len(t, topDMs.Items, 1)
// check order, magnitude of items // check order, magnitude of items
require.Equal(t, topDMs.Items[0].SecondParticipant, u3.Id) require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
require.Equal(t, topDMs.Items[0].MessageCount, int64(4)) require.Equal(t, topDMs.Items[0].MessageCount, int64(4))
}) })
t.Run("topDMs will consider self dms", func(t *testing.T) { t.Run("topDMs will consider self dms", func(t *testing.T) {
@@ -4107,7 +4107,7 @@ func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
// len of topDMs.Items should be 3 // len of topDMs.Items should be 3
require.Len(t, topDMs.Items, 3) require.Len(t, topDMs.Items, 3)
// check order, magnitude of items // check order, magnitude of items
require.Equal(t, topDMs.Items[2].SecondParticipant, user.Id) require.Equal(t, topDMs.Items[2].SecondParticipant.Id, user.Id)
require.Equal(t, topDMs.Items[2].MessageCount, int64(1)) require.Equal(t, topDMs.Items[2].MessageCount, int64(1))
}) })
} }