Skip to content

Commit 4d32f42

Browse files
committedAug 3, 2019
FIX: Incorrect message sender if buildFromArchive().
This is an incorporated fix from pull-request #11.
1 parent 442157a commit 4d32f42

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎src/main/java/com/oasisfeng/nevo/decorators/wechat/MessagingBuilder.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.util.ArrayMap;
2222
import android.util.Log;
2323
import android.util.LongSparseArray;
24+
import android.util.Pair;
2425

2526
import com.oasisfeng.nevo.decorators.wechat.ConversationManager.Conversation;
2627
import com.oasisfeng.nevo.sdk.MutableNotification;
@@ -88,8 +89,7 @@ class MessagingBuilder {
8889
return null;
8990
}
9091

91-
final LongSparseArray<CharSequence> lines = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
92-
CharSequence text;
92+
final LongSparseArray<Pair<CharSequence/* text */, CharSequence/* ticker */>> lines = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
9393
int count = 0, num_lines_with_colon = 0;
9494
final String redundant_prefix = title.toString() + SENDER_MESSAGE_SEPARATOR;
9595
for (final StatusBarNotification each : archive) {
@@ -112,11 +112,11 @@ class MessagingBuilder {
112112
if (trimmed_text.toString().startsWith(redundant_prefix)) // Remove redundant prefix
113113
trimmed_text = trimmed_text.subSequence(redundant_prefix.length(), trimmed_text.length());
114114
else if (trimmed_text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
115-
lines.put(notification.when, trimmed_text);
115+
lines.put(notification.when, new Pair<>(trimmed_text, notification.tickerText));
116116
} else {
117117
count = 1;
118-
lines.put(notification.when, text = its_text);
119-
if (text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
118+
lines.put(notification.when, new Pair<>(its_text, n.tickerText));
119+
if (its_text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
120120
}
121121
}
122122
n.number = count;
@@ -127,8 +127,10 @@ class MessagingBuilder {
127127

128128
final MessagingStyle messaging = new MessagingStyle(mUserSelf);
129129
final boolean sender_inline = num_lines_with_colon == lines.size();
130-
for (int i = 0, size = lines.size(); i < size; i++) // All lines have colon in text
131-
messaging.addMessage(buildMessage(conversation, lines.keyAt(i), n.tickerText, lines.valueAt(i), sender_inline ? null : title.toString()));
130+
for (int i = 0, size = lines.size(); i < size; i ++) { // All lines have colon in text
131+
final Pair<CharSequence, CharSequence> line = lines.valueAt(i);
132+
messaging.addMessage(buildMessage(conversation, lines.keyAt(i), line.second, line.first, sender_inline ? null : title.toString()));
133+
}
132134
return messaging;
133135
}
134136

0 commit comments

Comments
 (0)