Merge pull request 'Document Android edge case and clarify design of GetMessage' (#8) from fix-sync into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #8 Reviewed-by: erinn <erinn@openprivacy.ca>
This commit is contained in:
commit
58460ca0ca
15
lib.go
15
lib.go
|
@ -493,10 +493,17 @@ type EnhancedMessage struct {
|
|||
}
|
||||
|
||||
func GetMessage(profileOnion, handle string, message_index int) string {
|
||||
var message EnhancedMessage
|
||||
// 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...
|
||||
// In that case we skip processing and just return the empty message...
|
||||
// Note: This is far less likely to happen now that the UI only requests messages *after* syncing has happened and
|
||||
// these requests complete almost immediately v.s. being stalled for seconds to minutes on large groups.
|
||||
if application != nil {
|
||||
profile := application.GetPeer(profileOnion)
|
||||
ph := utils.NewPeerHelper(profile)
|
||||
var message EnhancedMessage
|
||||
if ph.IsGroup(handle) {
|
||||
// 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 {
|
||||
message.Message = profile.GetGroup(handle).Timeline.Messages[message_index]
|
||||
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
|
||||
|
@ -513,10 +520,13 @@ func GetMessage(profileOnion, handle string, message_index int) string {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if message_index < len(profile.GetContact(handle).Timeline.Messages) {
|
||||
// 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 {
|
||||
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
||||
message.ContactImage = ph.GetProfilePic(handle)
|
||||
} else {
|
||||
// Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we
|
||||
// throw an error.
|
||||
log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case")
|
||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
||||
event.Identity: profileOnion,
|
||||
|
@ -525,6 +535,7 @@ func GetMessage(profileOnion, handle string, message_index int) string {
|
|||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes, _ := json.Marshal(message)
|
||||
return string(bytes)
|
||||
}
|
||||
|
|
Reference in New Issue