NewMessageByID, Suppress Network Tests
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
edff87f77c
commit
92d2925622
53
lib.go
53
lib.go
|
@ -476,7 +476,6 @@ func BlockContact(profileOnion string, conversationID int) {
|
||||||
profile.BlockConversation(conversationID)
|
profile.BlockConversation(conversationID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//export c_GetMessage
|
//export c_GetMessage
|
||||||
// the pointer returned from this function **must** be Freed by c_Free
|
// the pointer returned from this function **must** be Freed by c_Free
|
||||||
func c_GetMessage(profile_ptr *C.char, profile_len C.int, conversation_id C.int, message_index C.int) *C.char {
|
func c_GetMessage(profile_ptr *C.char, profile_len C.int, conversation_id C.int, message_index C.int) *C.char {
|
||||||
|
@ -518,6 +517,40 @@ func GetMessage(profileOnion string, conversationID int, messageIndex int) strin
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export c_GetMessageByID
|
||||||
|
// the pointer returned from this function **must** be Freed by c_Free
|
||||||
|
func c_GetMessageByID(profile_ptr *C.char, profile_len C.int, conversation_id C.int, message_index C.int) *C.char {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
return C.CString(GetMessageByID(profile, int(conversation_id), int(message_index)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMessageByID(profileOnion string, conversationID int, messageIndex 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)
|
||||||
|
dbmessage, attr, err := profile.GetChannelMessage(conversationID, 0, messageIndex)
|
||||||
|
if err == nil {
|
||||||
|
time, _ := time.Parse(time.RFC3339Nano, attr[constants2.AttrSentTimestamp])
|
||||||
|
message.Message = model.Message{
|
||||||
|
Message: dbmessage,
|
||||||
|
Acknowledged: attr[constants2.AttrAck] == constants2.True,
|
||||||
|
Error: attr[constants2.AttrErr],
|
||||||
|
PeerID: attr[constants2.AttrAuthor],
|
||||||
|
Timestamp: time,
|
||||||
|
}
|
||||||
|
message.ID = messageIndex
|
||||||
|
message.ContactImage = utils.RandomProfileImage(message.PeerID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bytes, _ := json.Marshal(message)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
//export c_GetMessagesByContentHash
|
//export c_GetMessagesByContentHash
|
||||||
// the pointer returned from this function **must** be freed by calling c_Free
|
// the pointer returned from this function **must** be freed by calling c_Free
|
||||||
func c_GetMessagesByContentHash(profile_ptr *C.char, profile_len C.int, conversation_id C.int, contenthash_ptr *C.char, contenthash_len C.int) *C.char {
|
func c_GetMessagesByContentHash(profile_ptr *C.char, profile_len C.int, conversation_id C.int, contenthash_ptr *C.char, contenthash_len C.int) *C.char {
|
||||||
|
@ -534,15 +567,15 @@ func GetMessagesByContentHash(profileOnion string, handle int, contentHash strin
|
||||||
if err == nil {
|
if err == nil {
|
||||||
messages, err := profile.GetMostRecentMessages(handle, 0, offset, 1)
|
messages, err := profile.GetMostRecentMessages(handle, 0, offset, 1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
time, _ := time.Parse(time.RFC3339Nano, messages[0].Attr[constants2.AttrSentTimestamp])
|
time, _ := time.Parse(time.RFC3339Nano, messages[0].Attr[constants2.AttrSentTimestamp])
|
||||||
msg := model.Message{
|
msg := model.Message{
|
||||||
Message: messages[0].Body,
|
Message: messages[0].Body,
|
||||||
Acknowledged: messages[0].Attr[constants2.AttrAck] == constants2.True,
|
Acknowledged: messages[0].Attr[constants2.AttrAck] == constants2.True,
|
||||||
Error: messages[0].Attr[constants2.AttrErr],
|
Error: messages[0].Attr[constants2.AttrErr],
|
||||||
PeerID: messages[0].Attr[constants2.AttrAuthor],
|
PeerID: messages[0].Attr[constants2.AttrAuthor],
|
||||||
Timestamp: time,
|
Timestamp: time,
|
||||||
}
|
}
|
||||||
indexedMessages = append(indexedMessages, model.LocallyIndexedMessage{LocalIndex: offset, Message: msg})
|
indexedMessages = append(indexedMessages, model.LocallyIndexedMessage{LocalIndex: offset, Message: msg})
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("error fetching local index {} ", err)
|
log.Errorf("error fetching local index {} ", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,6 +300,10 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]]
|
cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]]
|
||||||
contact, _ := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer])
|
contact, _ := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer])
|
||||||
|
|
||||||
|
if ev.Event.Data[event.RemotePeer] == profile.GetOnion() {
|
||||||
|
return "" // suppress events from our own profile...
|
||||||
|
}
|
||||||
|
|
||||||
if cxnState == connections.AUTHENTICATED && contact == nil {
|
if cxnState == connections.AUTHENTICATED && contact == nil {
|
||||||
profile.NewContactConversation(ev.Event.Data[event.RemotePeer], model.AccessControl{Read: false, Append: false, Blocked: false}, false)
|
profile.NewContactConversation(ev.Event.Data[event.RemotePeer], model.AccessControl{Read: false, Append: false, Blocked: false}, false)
|
||||||
return ""
|
return ""
|
||||||
|
@ -345,7 +349,11 @@ func unwrap(original *EventProfileEnvelope) *event.Event {
|
||||||
func (eh *EventHandler) startHandlingPeer(onion string) {
|
func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||||
eventBus := eh.app.GetEventBus(onion)
|
eventBus := eh.app.GetEventBus(onion)
|
||||||
q := event.NewQueue()
|
q := event.NewQueue()
|
||||||
|
|
||||||
|
// eventBus.Subscribe(event.NetworkStatus, q)
|
||||||
|
|
||||||
eventBus.Subscribe(event.NewMessageFromPeer, q)
|
eventBus.Subscribe(event.NewMessageFromPeer, q)
|
||||||
|
eventBus.Subscribe(event.UpdatedProfileAttribute, q)
|
||||||
eventBus.Subscribe(event.PeerAcknowledgement, q)
|
eventBus.Subscribe(event.PeerAcknowledgement, q)
|
||||||
eventBus.Subscribe(event.DeleteContact, q)
|
eventBus.Subscribe(event.DeleteContact, q)
|
||||||
eventBus.Subscribe(event.AppError, q)
|
eventBus.Subscribe(event.AppError, q)
|
||||||
|
@ -364,7 +372,6 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||||
eventBus.Subscribe(event.SendMessageToPeerError, q)
|
eventBus.Subscribe(event.SendMessageToPeerError, q)
|
||||||
eventBus.Subscribe(event.ServerStateChange, q)
|
eventBus.Subscribe(event.ServerStateChange, q)
|
||||||
eventBus.Subscribe(event.PeerStateChange, q)
|
eventBus.Subscribe(event.PeerStateChange, q)
|
||||||
eventBus.Subscribe(event.NetworkStatus, q)
|
|
||||||
eventBus.Subscribe(event.ChangePasswordSuccess, q)
|
eventBus.Subscribe(event.ChangePasswordSuccess, q)
|
||||||
eventBus.Subscribe(event.ChangePasswordError, q)
|
eventBus.Subscribe(event.ChangePasswordError, q)
|
||||||
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)
|
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)
|
||||||
|
|
Reference in New Issue