Merge pull request 'Upgrade Cwtch - rely on Cwtch methods for fetching group timelines.' (#35) from new_group_api into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #35 Reviewed-by: erinn <erinn@openprivacy.ca>
This commit is contained in:
commit
4529984e45
|
@ -22,8 +22,11 @@ func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
||||||
|
|
||||||
// SendMessage handles sending messages to contacts
|
// SendMessage handles sending messages to contacts
|
||||||
func (pf *Functionality) SendMessage(peer peer.SendMessages, handle string, message string) features.Response {
|
func (pf *Functionality) SendMessage(peer peer.SendMessages, handle string, message string) features.Response {
|
||||||
eventID := peer.SendMessageToPeer(handle, message)
|
err := peer.SendMessage(handle, message)
|
||||||
return features.ConstructResponse(sendMessagePrefix, eventID)
|
if err == nil {
|
||||||
|
return features.ConstructResponse(sendMessagePrefix, "success")
|
||||||
|
}
|
||||||
|
return features.ConstructResponse(sendMessagePrefix, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleImportString handles contact import strings
|
// HandleImportString handles contact import strings
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (gf *GroupFunctionality) SendMessage(peer peer.CwtchPeer, handle string, me
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return peer.SendMessageToGroupTracked(handle, message)
|
return "", peer.SendMessage(handle, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidPrefix returns true if an import string contains a prefix that indicates it contains information about a
|
// ValidPrefix returns true if an import string contains a prefix that indicates it contains information about a
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -3,10 +3,10 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cwtch.im/cwtch v0.12.2
|
cwtch.im/cwtch v0.13.0
|
||||||
git.openprivacy.ca/openprivacy/connectivity v1.5.0
|
git.openprivacy.ca/openprivacy/connectivity v1.5.0
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||||
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
|
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
|
||||||
golang.org/x/mod v0.5.0 // indirect
|
golang.org/x/mod v0.5.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
|
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
|
||||||
)
|
)
|
||||||
|
|
31
lib.go
31
lib.go
|
@ -255,7 +255,7 @@ func ReconnectCwtchForeground() {
|
||||||
// fix peergroupcontact message counts
|
// fix peergroupcontact message counts
|
||||||
groupList := application.GetPeer(profileOnion).GetGroups()
|
groupList := application.GetPeer(profileOnion).GetGroups()
|
||||||
for _, groupID := range groupList {
|
for _, groupID := range groupList {
|
||||||
totalMessages := application.GetPeer(profileOnion).GetGroup(groupID).Timeline.Len() + len(application.GetPeer(profileOnion).GetGroup(groupID).UnacknowledgedMessages)
|
totalMessages := len(application.GetPeer(profileOnion).GetGroup(groupID).GetTimeline())
|
||||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
||||||
event.Identity: profileOnion,
|
event.Identity: profileOnion,
|
||||||
event.GroupID: groupID,
|
event.GroupID: groupID,
|
||||||
|
@ -537,7 +537,7 @@ type EnhancedMessage struct {
|
||||||
ContactImage string
|
ContactImage string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMessage(profileOnion, handle string, message_index int) string {
|
func GetMessage(profileOnion, handle string, messageIndex int) string {
|
||||||
var message EnhancedMessage
|
var message EnhancedMessage
|
||||||
// There is an edge case that can happen on Android when the app is shutdown while fetching messages...
|
// There is an edge case that can happen on Android when the app is shutdown while fetching messages...
|
||||||
// The worker threads that are spawned can become activated again when the app is opened attempt to finish their job...
|
// The worker threads that are spawned can become activated again when the app is opened attempt to finish their job...
|
||||||
|
@ -549,28 +549,25 @@ func GetMessage(profileOnion, handle string, message_index int) string {
|
||||||
ph := utils.NewPeerHelper(profile)
|
ph := utils.NewPeerHelper(profile)
|
||||||
if ph.IsGroup(handle) {
|
if ph.IsGroup(handle) {
|
||||||
if profile.GetGroup(handle) != nil {
|
if profile.GetGroup(handle) != nil {
|
||||||
// If we are safely within the limits of the timeline just grab the message at the index..
|
|
||||||
if len(profile.GetGroup(handle).Timeline.Messages) > message_index {
|
exists, timelineMessage, length := profile.GetGroup(handle).GetMessage(messageIndex)
|
||||||
message.Message = profile.GetGroup(handle).Timeline.Messages[message_index]
|
if exists {
|
||||||
|
message.Message = timelineMessage
|
||||||
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
|
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
|
||||||
} else {
|
} else {
|
||||||
// Message Index Request exceeded Timeline, most likely reason is this is a request for an
|
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
||||||
// unacknowledged sent message (it can take a many seconds for a message to be confirmed in the worst
|
event.Identity: profileOnion,
|
||||||
// case).
|
event.GroupID: handle,
|
||||||
offset := message_index - len(profile.GetGroup(handle).Timeline.Messages)
|
event.Data: strconv.Itoa(length),
|
||||||
if len(profile.GetGroup(handle).UnacknowledgedMessages) > offset {
|
}))
|
||||||
message.Message = profile.GetGroup(handle).UnacknowledgedMessages[offset]
|
log.Errorf("Couldn't find message in timeline %v / %v or unacked messages, probably transient threading issue, but logging for visibility..", messageIndex, length)
|
||||||
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
|
|
||||||
} else {
|
|
||||||
log.Errorf("Couldn't find message in timeline or unacked messages, probably transient threading issue, but logging for visibility..")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if profile.GetContact(handle) != nil {
|
if profile.GetContact(handle) != nil {
|
||||||
// If we are safely within the limits of the timeline just grab the message at the index..
|
// If we are safely within the limits of the timeline just grab the message at the index..
|
||||||
if len(profile.GetContact(handle).Timeline.Messages) > message_index {
|
if len(profile.GetContact(handle).Timeline.Messages) > messageIndex {
|
||||||
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
message.Message = profile.GetContact(handle).Timeline.Messages[messageIndex]
|
||||||
message.ContactImage = ph.GetProfilePic(handle)
|
message.ContactImage = ph.GetProfilePic(handle)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we
|
// Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we
|
||||||
|
|
Reference in New Issue